-
-
Notifications
You must be signed in to change notification settings - Fork 848
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
Showing
4 changed files
with
111 additions
and
0 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,24 @@ | ||
Feature: Planning handling | ||
In order to use an object as primary key | ||
As a developer | ||
I should be able serialize types with object primary key. | ||
|
||
@createSchema | ||
@dropSchema | ||
Scenario: Get a resource containing a raw object | ||
When I send a "GET" request to "/object_primary_keys/2017-01-30" | ||
Then print last JSON response | ||
Scenario: Get a resource | ||
When I send a "GET" request to "/object_primary_keys/2017-01-30" | ||
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/ObjectPrimaryKey", | ||
"@id": "/object_primary_keys/2017-01-30", | ||
"@type": "ObjectPrimaryKey", | ||
"date": "2017-01-30" | ||
} | ||
""" |
38 changes: 38 additions & 0 deletions
38
tests/Fixtures/TestBundle/DataProvider/ObjectPrimaryKeyItemDataProvider.php
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,38 @@ | ||
<?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. | ||
*/ | ||
|
||
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\DataProvider; | ||
|
||
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; | ||
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; | ||
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ObjectPrimaryKey; | ||
use DateTime; | ||
|
||
/** | ||
* @author Kévin Dunglas <dunglas@gmail.com> | ||
*/ | ||
class ObjectPrimaryKeyItemDataProvider implements ItemDataProviderInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []) | ||
{ | ||
if (ObjectPrimaryKey::class !== $resourceClass) { | ||
throw new ResourceClassNotSupportedException(); | ||
} | ||
|
||
$planning = new ObjectPrimaryKey(); | ||
$planning->setDate(new DateTime($id)); | ||
|
||
return $planning; | ||
} | ||
} |
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,45 @@ | ||
<?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. | ||
*/ | ||
|
||
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use DateTime; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* Planning. | ||
* | ||
* @author Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* @ApiResource | ||
* @ORM\Entity | ||
*/ | ||
class ObjectPrimaryKey | ||
{ | ||
/** | ||
* @var DateTime | ||
* | ||
* @ORM\Column(type="date") | ||
* @ORM\Id | ||
*/ | ||
private $date; | ||
|
||
public function getDate(): DateTime | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function setDate(DateTime $date) | ||
{ | ||
$this->date = $date; | ||
} | ||
} |
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