Skip to content

Commit bb70805

Browse files
author
Bertrand Dunogier
committed
Added first generator test
1 parent 61d8adf commit bb70805

File tree

6 files changed

+173
-5
lines changed

6 files changed

+173
-5
lines changed

behat_suites.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# This file is meant to be imported from ezplatform's behat.yml.dist.
22
# All path are relative to the root ezplatform directory.
3-
default: {}
3+
default:
4+
autoload:
5+
- '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/bootstrap/'
46

57
graphql:
68
suites:
79
graphql:
10+
autoload:
11+
- '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/bootstrap/'
812
paths:
9-
- '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/Generator.feature'
13+
- '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/Generator.feature'
1014
contexts:
1115
- GraphQLContext
1216
- GeneratorContext
17+
- ConfigurationContext
18+
- CacheContext

features/Generator.Feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Feature: Schema generation
44
I need to generate the schema
55

66
Scenario: An application maintainer generates the schema
7+
Given the schema has not been generated
78
When I run the command "ezplatform:graphql:generate-schema"
9+
When I clear the cache
810
Then the schema files are generated in "app/config/graphql/ezplatform"
911
And the GraphQL extension is configured to use that schema

features/bootstrap/CacheContext.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
use PHPUnit\Framework\Assert;
4+
use Symfony\Component\Console\Input\ArrayInput;
5+
use Symfony\Component\Console\Output\BufferedOutput;
6+
use Symfony\Component\Finder\Finder;
7+
use Symfony\Component\Filesystem\Filesystem;
8+
use Symfony\Component\HttpKernel\KernelInterface;
9+
use Symfony\Component\Process\PhpExecutableFinder;
10+
use Symfony\Component\Process\Process;
11+
12+
/**
13+
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
14+
* @license For full copyright and license information view LICENSE file distributed with this source code.
15+
*/
16+
17+
class CacheContext implements \Behat\Symfony2Extension\Context\KernelAwareContext
18+
{
19+
/**
20+
* @var \Symfony\Component\HttpKernel\KernelInterface
21+
*/
22+
private $kernel;
23+
24+
/**
25+
* Sets Kernel instance.
26+
*
27+
* @param \Symfony\Component\HttpKernel\KernelInterface $kernel
28+
*/
29+
public function setKernel(KernelInterface $kernel)
30+
{
31+
$this->kernel = $kernel;
32+
}
33+
34+
/**
35+
* @Given /^I clear the cache$/
36+
*/
37+
public function iClearTheCache()
38+
{
39+
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->kernel);
40+
$application->setAutoExit(false);
41+
42+
$input = new ArrayInput(['command' => 'cache:clear', '--env' => 'behat']);
43+
44+
// You can use NullOutput() if you don't need the output
45+
$output = new BufferedOutput();
46+
Assert::assertEquals(0, $application->run($input, $output));
47+
$content = $output->fetch();
48+
$this->kernel->shutdown();
49+
$this->kernel->boot();
50+
}
51+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
use PHPUnit\Framework\Assert;
4+
use Symfony\Component\Console\Input\ArrayInput;
5+
use Symfony\Component\Console\Output\BufferedOutput;
6+
use Symfony\Component\Finder\Finder;
7+
use Symfony\Component\Filesystem\Filesystem;
8+
use Symfony\Component\HttpKernel\KernelInterface;
9+
use Symfony\Component\Process\PhpExecutableFinder;
10+
use Symfony\Component\Process\Process;
11+
12+
/**
13+
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
14+
* @license For full copyright and license information view LICENSE file distributed with this source code.
15+
*/
16+
17+
class ConfigurationContext implements \Behat\Symfony2Extension\Context\KernelAwareContext
18+
{
19+
/**
20+
* @var \Symfony\Component\HttpKernel\KernelInterface
21+
*/
22+
private $kernel;
23+
24+
/**
25+
* Sets Kernel instance.
26+
*
27+
* @param \Symfony\Component\HttpKernel\KernelInterface $kernel
28+
*/
29+
public function setKernel(KernelInterface $kernel)
30+
{
31+
$this->kernel = $kernel;
32+
}
33+
34+
/**
35+
* @Given /^the GraphQL extension is configured to use that schema$/
36+
*/
37+
public function theGraphQLExtensionIsConfiguredToUseThatSchema()
38+
{
39+
$container = $this->kernel->getContainer();
40+
$executor = $container->get('overblog_graphql.request_executor');
41+
$schema = $executor->getSchema('default');
42+
Assert::assertEquals('Domain', (string)$schema->getQueryType());
43+
}
44+
45+
}
Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,75 @@
11
<?php
2+
3+
use PHPUnit\Framework\Assert;
4+
use Symfony\Bundle\FrameworkBundle\Console\Application;
5+
use Symfony\Component\Console\Input\ArrayInput;
6+
use Symfony\Component\Console\Output\BufferedOutput;
7+
use Symfony\Component\Finder\Finder;
8+
use Symfony\Component\Filesystem\Filesystem;
9+
use Symfony\Component\HttpKernel\KernelInterface;
10+
use Symfony\Component\Process\PhpExecutableFinder;
11+
use Symfony\Component\Process\Process;
12+
213
/**
314
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
415
* @license For full copyright and license information view LICENSE file distributed with this source code.
516
*/
617

7-
class GeneratorContext
18+
class GeneratorContext implements \Behat\Symfony2Extension\Context\KernelAwareContext
819
{
20+
/**
21+
* @var string
22+
*/
23+
private $scriptOutput;
24+
25+
/**
26+
* @var \Symfony\Component\HttpKernel\KernelInterface
27+
*/
28+
private $kernel;
29+
30+
/**
31+
* @When /^I run the command "([^"]+)"$/
32+
*/
33+
public function iRunTheCommand($command)
34+
{
35+
$application = new Application($this->kernel);
36+
$application->setAutoExit(false);
37+
38+
$input = new ArrayInput(['command' => $command, '--env' => 'behat']);
39+
40+
$output = new BufferedOutput();
41+
$application->run($input, $output);
42+
43+
$content = $output->fetch();
44+
}
45+
46+
/**
47+
* @Then /^the schema files are generated in "([^"]*)"$/
48+
*/
49+
public function theSchemaFilesAreGeneratedIn($directory)
50+
{
51+
$finder = new Finder();
52+
Assert::assertFileExists('app/config/graphql/ezplatform/Domain.types.yml');
53+
Assert::assertFileExists('app/config/graphql/ezplatform/DomainContentMutation.types.yml');
54+
}
55+
56+
/**
57+
* @Given /^the schema has not been generated$/
58+
*/
59+
public function theSchemaHasNotBeenGenerated()
60+
{
61+
$finder = new Finder();
62+
$fs = new Filesystem();
63+
$fs->remove($finder->in('app/config/graphql/ezplatform')->files());
64+
}
965

66+
/**
67+
* Sets Kernel instance.
68+
*
69+
* @param \Symfony\Component\HttpKernel\KernelInterface $kernel
70+
*/
71+
public function setKernel(KernelInterface $kernel)
72+
{
73+
$this->kernel = $kernel;
74+
}
1075
}

features/bootstrap/GraphQLContext.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* @license For full copyright and license information view LICENSE file distributed with this source code.
55
*/
66

7-
8-
class GraphQLContext
7+
class GraphQLContext implements \Behat\Behat\Context\Context
98
{
109

1110
}

0 commit comments

Comments
 (0)