Skip to content

Commit

Permalink
Merge 6cd6540 into 93bab59
Browse files Browse the repository at this point in the history
  • Loading branch information
fbourigault committed Jan 30, 2017
2 parents 93bab59 + 6cd6540 commit cfdd8ac
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
24 changes: 24 additions & 0 deletions features/main/object_primary_key.feature
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"
}
"""
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;
}
}
45 changes: 45 additions & 0 deletions tests/Fixtures/TestBundle/Entity/ObjectPrimaryKey.php
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;
}
}
4 changes: 4 additions & 0 deletions tests/Fixtures/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ nelmio_api_doc:
json: 'application/json'

services:
object_primary_key.item_data_provider:
class: 'ApiPlatform\Core\Tests\Fixtures\TestBundle\DataProvider\ObjectPrimaryKeyItemDataProvider'
tags:
- { name: 'api_platform.item_data_provider' }
app.user_manager:
class: 'ApiPlatform\Core\Tests\Fixtures\TestBundle\Manager\UserManager'
arguments:
Expand Down

0 comments on commit cfdd8ac

Please sign in to comment.