Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test 0-index bug with ManyToMany relations
- Loading branch information
abluchet
committed
Dec 1, 2017
1 parent
a30ac33
commit 2d1288d
Showing
4 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
Feature: Add/remove on a ManytoMany relation | ||
In order to use a hypermedia API | ||
As a client software developer | ||
I need to be able to update ManytoMany relations between resources | ||
|
||
@createSchema | ||
Scenario: Add a DummyCar to the Brand | ||
Given there is a brand and 5 DummyCar | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "PUT" request to "/brands/1" with body: | ||
""" | ||
{"car": ["/dummy_cars/1"]} | ||
""" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" | ||
And the JSON should be equal to: | ||
""" | ||
{ | ||
"@context": "/contexts/Brand", | ||
"@id": "/brands/1", | ||
"@type": "Brand", | ||
"car": [ | ||
"/dummy_cars/1" | ||
], | ||
"id": 1 | ||
} | ||
""" | ||
|
||
Scenario: Add another DummyCar to the Brand | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "PUT" request to "/brands/1" with body: | ||
""" | ||
{"car": ["/dummy_cars/1", "/dummy_cars/2"]} | ||
""" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" | ||
And the JSON should be equal to: | ||
""" | ||
{ | ||
"@context": "/contexts/Brand", | ||
"@id": "/brands/1", | ||
"@type": "Brand", | ||
"car": [ | ||
"/dummy_cars/1", | ||
"/dummy_cars/2" | ||
], | ||
"id": 1 | ||
} | ||
""" | ||
|
||
@dropSchema | ||
Scenario: Remove the first car of the relation | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "PUT" request to "/brands/1" with body: | ||
""" | ||
{"car": ["/dummy_cars/2"]} | ||
""" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" | ||
And the JSON should be equal to: | ||
""" | ||
{ | ||
"@context": "/contexts/Brand", | ||
"@id": "/brands/1", | ||
"@type": "Brand", | ||
"car": [ | ||
"/dummy_cars/2" | ||
], | ||
"id": 1 | ||
} | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ApiResource | ||
* @ORM\Entity | ||
*/ | ||
class Brand | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\ManyToMany(targetEntity="ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCar", inversedBy="brand") | ||
* @ORM\JoinTable( | ||
* name="CarToBrand", | ||
* joinColumns={@ORM\JoinColumn(name="brand_id", referencedColumnName="id", nullable=false)}, | ||
* inverseJoinColumns={@ORM\JoinColumn(name="car_id", referencedColumnName="id", nullable=false)} | ||
* ) | ||
*/ | ||
private $car; | ||
|
||
public function __construct() | ||
{ | ||
$this->car = new ArrayCollection(); | ||
} | ||
|
||
public function addCar(DummyCar $car) | ||
{ | ||
$this->car[] = $car; | ||
} | ||
|
||
public function removeCar(DummyCar $car) | ||
{ | ||
$this->car->removeElement($car); | ||
} | ||
|
||
public function getCar() | ||
{ | ||
return $this->car->getValues(); | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters