diff --git a/behat_suites.yml b/behat_suites.yml index cff2ef7f..ed647f48 100644 --- a/behat_suites.yml +++ b/behat_suites.yml @@ -1,12 +1,18 @@ # This file is meant to be imported from ezplatform's behat.yml.dist. # All path are relative to the root ezplatform directory. -default: {} +default: + autoload: + - '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/bootstrap/' graphql: suites: graphql: + autoload: + - '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/bootstrap/' paths: - - '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/Generator.feature' + - '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/Generator.feature' contexts: - GraphQLContext - GeneratorContext + - ConfigurationContext + - CacheContext diff --git a/features/Generator.Feature b/features/Generator.Feature index 87f2f962..6133ca9a 100644 --- a/features/Generator.Feature +++ b/features/Generator.Feature @@ -4,6 +4,8 @@ Feature: Schema generation I need to generate the schema Scenario: An application maintainer generates the schema + Given the schema has not been generated When I run the command "ezplatform:graphql:generate-schema" + When I clear the cache Then the schema files are generated in "app/config/graphql/ezplatform" And the GraphQL extension is configured to use that schema diff --git a/features/bootstrap/CacheContext.php b/features/bootstrap/CacheContext.php new file mode 100644 index 00000000..0117636c --- /dev/null +++ b/features/bootstrap/CacheContext.php @@ -0,0 +1,51 @@ +kernel = $kernel; + } + + /** + * @Given /^I clear the cache$/ + */ + public function iClearTheCache() + { + $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->kernel); + $application->setAutoExit(false); + + $input = new ArrayInput(['command' => 'cache:clear', '--env' => 'behat']); + + // You can use NullOutput() if you don't need the output + $output = new BufferedOutput(); + Assert::assertEquals(0, $application->run($input, $output)); + $content = $output->fetch(); + $this->kernel->shutdown(); + $this->kernel->boot(); + } +} \ No newline at end of file diff --git a/features/bootstrap/ConfigurationContext.php b/features/bootstrap/ConfigurationContext.php new file mode 100644 index 00000000..6f644133 --- /dev/null +++ b/features/bootstrap/ConfigurationContext.php @@ -0,0 +1,45 @@ +kernel = $kernel; + } + + /** + * @Given /^the GraphQL extension is configured to use that schema$/ + */ + public function theGraphQLExtensionIsConfiguredToUseThatSchema() + { + $container = $this->kernel->getContainer(); + $executor = $container->get('overblog_graphql.request_executor'); + $schema = $executor->getSchema('default'); + Assert::assertEquals('Domain', (string)$schema->getQueryType()); + } + +} \ No newline at end of file diff --git a/features/bootstrap/GeneratorContext.php b/features/bootstrap/GeneratorContext.php index db6f4258..238201d2 100644 --- a/features/bootstrap/GeneratorContext.php +++ b/features/bootstrap/GeneratorContext.php @@ -1,10 +1,75 @@ kernel); + $application->setAutoExit(false); + + $input = new ArrayInput(['command' => $command, '--env' => 'behat']); + + $output = new BufferedOutput(); + $application->run($input, $output); + + $content = $output->fetch(); + } + + /** + * @Then /^the schema files are generated in "([^"]*)"$/ + */ + public function theSchemaFilesAreGeneratedIn($directory) + { + $finder = new Finder(); + Assert::assertFileExists('app/config/graphql/ezplatform/Domain.types.yml'); + Assert::assertFileExists('app/config/graphql/ezplatform/DomainContentMutation.types.yml'); + } + + /** + * @Given /^the schema has not been generated$/ + */ + public function theSchemaHasNotBeenGenerated() + { + $finder = new Finder(); + $fs = new Filesystem(); + $fs->remove($finder->in('app/config/graphql/ezplatform')->files()); + } + /** + * Sets Kernel instance. + * + * @param \Symfony\Component\HttpKernel\KernelInterface $kernel + */ + public function setKernel(KernelInterface $kernel) + { + $this->kernel = $kernel; + } } \ No newline at end of file diff --git a/features/bootstrap/GraphQLContext.php b/features/bootstrap/GraphQLContext.php index 44d44042..4048419f 100644 --- a/features/bootstrap/GraphQLContext.php +++ b/features/bootstrap/GraphQLContext.php @@ -4,8 +4,7 @@ * @license For full copyright and license information view LICENSE file distributed with this source code. */ - -class GraphQLContext +class GraphQLContext implements \Behat\Behat\Context\Context { } \ No newline at end of file