Skip to content

Commit

Permalink
Merge branch '2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Feb 22, 2018
2 parents da84be3 + f8206c4 commit c49f3a2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
18 changes: 1 addition & 17 deletions features/main/configurable.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Feature: Configurable resource CRUD
}
"""

@dropSchema
Scenario: Retrieve the ConfigDummy resource
When I send a "GET" request to "/fileconfigdummies/1"
Then the response status code should be 200
Expand All @@ -60,20 +61,3 @@ Feature: Configurable resource CRUD
"foo": "Foo"
}
"""

@dropSchema
Scenario: Entities can be configured using a Flex-like directory structure
When I send a "GET" request to "/flex_configs"
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/FlexConfig",
"@id": "/flex_configs",
"@type": "hydra:Collection",
"hydra:member": [],
"hydra:totalItems": 0
}
"""
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/Orm/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function filterProperty(string $property, $values, QueryBuilder $query
protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, string $operator, string $value, string $nullManagement = null, $type = null)
{
try {
$value = false !== strpos('_immutable', $type) ? new \DateTime($value) : new \DateTimeImmutable($value);
$value = false === strpos($type, '_immutable') ? new \DateTime($value) : new \DateTimeImmutable($value);
} catch (\Exception $e) {
// Silently ignore this filter if it can not be transformed to a \DateTime
$this->logger->notice('Invalid filter ignored', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,14 @@ private function getBundlesResourcesPaths(ContainerBuilder $container): array

private function getResourcesToWatch(ContainerBuilder $container, array $resourcesPaths): array
{
// Flex structure
$paths = array_unique(array_merge($resourcesPaths, $this->getBundlesResourcesPaths($container)));

// Flex structure (only if nothing specified)
$projectDir = $container->getParameter('kernel.project_dir');
if (is_dir($dir = "$projectDir/config/api_platform")) {
$resourcesPaths[] = $dir;
if (!$paths && is_dir($dir = "$projectDir/config/api_platform")) {
$paths = [$dir];
}

$paths = array_unique(array_merge($resourcesPaths, $this->getBundlesResourcesPaths($container)));
$resources = ['yml' => [], 'xml' => [], 'dir' => []];

foreach ($paths as $path) {
Expand Down
30 changes: 30 additions & 0 deletions tests/Bridge/Doctrine/Orm/Filter/DateFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDate;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyImmutableDate;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

Expand Down Expand Up @@ -57,6 +62,31 @@ private function doTestApplyDate(bool $request)
$filter->apply($queryBuilder, new QueryNameGenerator(), DummyDate::class, null, $request ? [] : ['filters' => $filters]);

$this->assertEquals(new \DateTime('2015-04-05'), $queryBuilder->getParameters()[0]->getValue());
$this->assertInstanceOf(\DateTime::class, $queryBuilder->getParameters()[0]->getValue());
}

public function testApplyDateImmutable()
{
$request = Request::create('/api/dummy_immutable_dates', 'GET', [
'dummyDate' => [
'after' => '2015-04-05',
],
]);
$requestStack = new RequestStack();
$requestStack->push($request);

$queryBuilder = $this->repository->createQueryBuilder('o');

$filter = new DateFilter(
$this->managerRegistry,
$requestStack,
null,
['dummyDate' => null]
);

$filter->apply($queryBuilder, new QueryNameGenerator(), DummyImmutableDate::class);
$this->assertEquals(new \DateTimeImmutable('2015-04-05'), $queryBuilder->getParameters()[0]->getValue());
$this->assertInstanceOf(\DateTimeImmutable::class, $queryBuilder->getParameters()[0]->getValue());
}

public function testGetDescription()
Expand Down
16 changes: 13 additions & 3 deletions tests/GraphQl/Action/EntrypointActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@
*/
class EntrypointActionTest extends TestCase
{
/**
* Hack to avoid transient failing test because of Date header.
*/
private function assertEqualsWithoutDateHeader(JsonResponse $expected, JsonResponse $actual)
{
$expected->headers->remove('Date');
$actual->headers->remove('Date');
$this->assertEquals($expected, $actual);
}

public function testGetAction()
{
$request = new Request(['query' => 'graphqlQuery', 'variables' => '["graphqlVariable"]', 'operation' => 'graphqlOperationName']);
$request->setRequestFormat('json');
$mockedEntrypoint = $this->getEntrypointAction($request);

$this->assertEquals(new JsonResponse(['GraphQL']), $mockedEntrypoint($request));
$this->assertEqualsWithoutDateHeader(new JsonResponse(['GraphQL']), $mockedEntrypoint($request));
}

public function testPostRawAction()
Expand All @@ -44,7 +54,7 @@ public function testPostRawAction()
$request->headers->set('Content-Type', 'application/graphql');
$mockedEntrypoint = $this->getEntrypointAction($request);

$this->assertEquals(new JsonResponse(['GraphQL']), $mockedEntrypoint($request));
$this->assertEqualsWithoutDateHeader(new JsonResponse(['GraphQL']), $mockedEntrypoint($request));
}

public function testPostJsonAction()
Expand All @@ -54,7 +64,7 @@ public function testPostJsonAction()
$request->headers->set('Content-Type', 'application/json');
$mockedEntrypoint = $this->getEntrypointAction($request);

$this->assertEquals(new JsonResponse(['GraphQL']), $mockedEntrypoint($request));
$this->assertEqualsWithoutDateHeader(new JsonResponse(['GraphQL']), $mockedEntrypoint($request));
}

public function testBadContentTypePostAction()
Expand Down

0 comments on commit c49f3a2

Please sign in to comment.