Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6623f2
commit 1496702
Showing
6 changed files
with
305 additions
and
40 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
Feature: Uri Variables | ||
|
||
@createSchema | ||
@php8 | ||
Scenario: Create a resource Company | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/companies" with body: | ||
""" | ||
{ | ||
"name": "Api Platform" | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
And the response should be in JSON | ||
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" | ||
And the header "Content-Location" should be equal to "/companies/1" | ||
And the header "Location" should be equal to "/companies/1" | ||
And the JSON should be equal to: | ||
""" | ||
{ | ||
"@context": "/contexts/Company", | ||
"@id": "/companies/1", | ||
"@type": "Company", | ||
"id": 1, | ||
"name": "Api Platform" | ||
} | ||
""" | ||
|
||
@php8 | ||
Scenario: Create a second resource Company | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/companies" with body: | ||
""" | ||
{ | ||
"name": "Les Tilleuls.coop" | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
|
||
@php8 | ||
Scenario: Create first Employee | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/employees" with body: | ||
""" | ||
{ | ||
"name": "foo", | ||
"company": "/companies/1" | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
And the response should be in JSON | ||
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" | ||
And the header "Content-Location" should be equal to "/companies/1/employees/1" | ||
And the header "Location" should be equal to "/companies/1/employees/1" | ||
And the JSON should be equal to: | ||
""" | ||
{ | ||
"@context": "/contexts/Employee", | ||
"@id": "/companies/1/employees/1", | ||
"@type": "Employee", | ||
"id": 1, | ||
"name": "foo", | ||
"company": "/companies/1" | ||
} | ||
""" | ||
|
||
@php8 | ||
Scenario: Create second Employee | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/employees" with body: | ||
""" | ||
{ | ||
"name": "foo2", | ||
"company": "/companies/2" | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
|
||
@php8 | ||
Scenario: Create thirf Employee | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/employees" with body: | ||
""" | ||
{ | ||
"name": "foo3", | ||
"company": "/companies/2" | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
@php8 | ||
Scenario: Create a resource Company | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/companies" with body: | ||
""" | ||
{ | ||
"name": "bar", | ||
"company": "/companies/1" | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
|
||
@php8 | ||
Scenario: Create a second resource Company | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/companies" with body: | ||
""" | ||
{ | ||
"name": "toto", | ||
"company": "/companies/2" | ||
} | ||
""" | ||
Then the response status code should be 201 |
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
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,70 @@ | ||
<?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\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\Post; | ||
use ApiPlatform\Metadata\UriVariable; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Serializer\Annotation\Ignore; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
#[ApiResource] | ||
#[Get] | ||
#[Post] | ||
#[ApiResource('/employee/{employeeId}/company')] | ||
#[Get] | ||
class Company | ||
{ | ||
/** | ||
* @var int The id | ||
* | ||
* @ORM\Column(type="integer", nullable=true) | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string The dummy name | ||
* | ||
* @ORM\Column | ||
*/ | ||
public string $name; | ||
|
||
// TODO 3.0: Set the uri variable directly in the api resource and remove this property | ||
#[UriVariable(parameterName: 'employeeId', inverseProperty: 'company', property: null, targetClass: Employee::class)] | ||
/** | ||
* @Ignore | ||
*/ | ||
public $employees; // only used to set metadata | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): void | ||
{ | ||
$this->name = $name; | ||
} | ||
} |
Oops, something went wrong.