From 9ae9c6c4eb2102d3ffe8508ef0bae92a1853d27b Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Wed, 23 Mar 2016 16:28:34 +0100 Subject: [PATCH] Add enum values short notation --- DependencyInjection/TypesConfiguration.php | 4 ++++ Tests/Functional/Command/GraphDumpSchemaCommandTest.php | 4 ++-- Tests/Functional/Command/{schema.yml => schema.json} | 0 Tests/Functional/Relay/Node/GlobalTest.php | 2 ++ Tests/Functional/app/Resolver/GlobalResolver.php | 2 ++ .../app/config/global/mapping/global.types.yml | 9 +++++++++ 6 files changed, 19 insertions(+), 2 deletions(-) rename Tests/Functional/Command/{schema.yml => schema.json} (100%) diff --git a/DependencyInjection/TypesConfiguration.php b/DependencyInjection/TypesConfiguration.php index e65c4d6e9..678539d83 100644 --- a/DependencyInjection/TypesConfiguration.php +++ b/DependencyInjection/TypesConfiguration.php @@ -69,6 +69,10 @@ private function addConfigSelection() ->arrayNode('values') ->useAttributeAsKey('name') ->prototype('array') + ->beforeNormalization() + ->ifTrue(function ($v) { return !is_null($v) && !is_array($v); }) + ->then(function ($v) { return ['value' => $v]; }) + ->end() ->isRequired() ->children() ->scalarNode('value')->end() diff --git a/Tests/Functional/Command/GraphDumpSchemaCommandTest.php b/Tests/Functional/Command/GraphDumpSchemaCommandTest.php index 995821e44..3c0cf81a3 100644 --- a/Tests/Functional/Command/GraphDumpSchemaCommandTest.php +++ b/Tests/Functional/Command/GraphDumpSchemaCommandTest.php @@ -27,7 +27,7 @@ public function testExecute() $application->add(new GraphDumpSchemaCommand()); $command = $application->find('graph:dump-schema'); - $file = $kernel->getCacheDir().'/schema.yml'; + $file = $kernel->getCacheDir().'/schema.json'; $commandTester = new CommandTester($command); $commandTester->execute( @@ -38,6 +38,6 @@ public function testExecute() ); $this->assertEquals(0, $commandTester->getStatusCode()); - $this->assertEquals(file_get_contents(__DIR__.'/schema.yml'), file_get_contents($file)); + $this->assertEquals(file_get_contents(__DIR__.'/schema.json'), file_get_contents($file)); } } diff --git a/Tests/Functional/Command/schema.yml b/Tests/Functional/Command/schema.json similarity index 100% rename from Tests/Functional/Command/schema.yml rename to Tests/Functional/Command/schema.json diff --git a/Tests/Functional/Relay/Node/GlobalTest.php b/Tests/Functional/Relay/Node/GlobalTest.php index 4b76f1edb..5d47f6bd6 100644 --- a/Tests/Functional/Relay/Node/GlobalTest.php +++ b/Tests/Functional/Relay/Node/GlobalTest.php @@ -84,6 +84,7 @@ public function testReFetchesTheIds() id ... on Post { text + status } } } @@ -100,6 +101,7 @@ public function testReFetchesTheIds() 'post' => [ 'id' => 'UG9zdDox', 'text' => 'lorem', + 'status' => 'DRAFT', ], ]; diff --git a/Tests/Functional/app/Resolver/GlobalResolver.php b/Tests/Functional/app/Resolver/GlobalResolver.php index 7d67142a3..517ccb076 100644 --- a/Tests/Functional/app/Resolver/GlobalResolver.php +++ b/Tests/Functional/app/Resolver/GlobalResolver.php @@ -45,10 +45,12 @@ class GlobalResolver 1 => [ 'id' => 1, 'text' => 'lorem', + 'status' => 2, ], 2 => [ 'id' => 2, 'text' => 'ipsum', + 'status' => 1, ], ]; diff --git a/Tests/Functional/app/config/global/mapping/global.types.yml b/Tests/Functional/app/config/global/mapping/global.types.yml index b1f0586d3..b0669258a 100644 --- a/Tests/Functional/app/config/global/mapping/global.types.yml +++ b/Tests/Functional/app/config/global/mapping/global.types.yml @@ -51,4 +51,13 @@ Post: typeName: Post text: type: String + status: + type: Status interfaces: [NodeInterface] + +Status: + type: enum + config: + values: + PUBLISHED: 1 + DRAFT: 2