Skip to content

Commit 1a4ac8d

Browse files
author
Bertrand Dunogier
committed
Added behat structure + generator feature
1 parent 46fa215 commit 1a4ac8d

File tree

8 files changed

+243
-7
lines changed

8 files changed

+243
-7
lines changed

.travis.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,35 @@ cache:
1414
- $HOME/.composer/cache/files
1515

1616
env:
17-
matrix:
18-
- TARGET="phpspec"
19-
- TARGET="codestyle"
17+
global:
18+
- EZPLATFORM_REPO="https://github.com/ezsystems/ezplatform.git"
19+
- SYMFONY_ENV=behat
20+
- SYMFONY_DEBUG=1
21+
22+
matrix:
23+
include:
24+
- name: "Unit tests with PhpSpec"
25+
env:
26+
- TARGET="phpspec"
27+
- name: "Code style"
28+
env:
29+
- TARGET="codestyle"
30+
- name: "Behat"
31+
env:
32+
- TARGET="behat"
33+
- COMPOSE_FILE="doc/docker/base-dev.yml"
34+
- BEHAT_OPTS="--mode=behat --profile=graphql --suite=graphql"
35+
36+
install:
37+
- if [ $TARGET == "behat" ]; then ./.travis/prepare_ezplatform.sh ${INSTALL_EZ_INSTALL_TYPE}; fi
2038

2139
before_script:
22-
- COMPOSER_MEMORY_LIMIT=-1 composer install
40+
- if [ "$TARGET" != "behat" ]; then COMPOSER_MEMORY_LIMIT=-1 composer install; fi
2341

2442
script:
2543
- if [ "$TARGET" == "phpspec" ] ; then ./vendor/bin/phpspec run --format=pretty; fi
2644
- if [ "$TARGET" == "codestyle" ] ; then ./vendor/bin/php-cs-fixer fix --dry-run -v --show-progress=estimating; fi
45+
- if [ "$TARGET" == "behat" ]; then cd "$HOME/build/ezplatform"; docker-compose exec --user www-data app sh -c "bin/ezbehat ${BEHAT_OPTS}" ; fi
2746

2847
notification:
2948
email: false

.travis/prepare_ezplatform.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
EZPLATFORM_BRANCH=`php -r 'echo json_decode(file_get_contents("./composer.json"))->extra->_ezplatform_branch_for_behat_tests;'`
4+
EZPLATFORM_BRANCH="${EZPLATFORM_BRANCH:-master}"
5+
PACKAGE_BUILD_DIR=$PWD
6+
EZPLATFORM_BUILD_DIR=${HOME}/build/ezplatform
7+
8+
echo "> Cloning ezsystems/ezplatform:${EZPLATFORM_BRANCH}"
9+
git clone --depth 1 --single-branch --branch "${EZPLATFORM_BRANCH}" ${EZPLATFORM_REPO} ${EZPLATFORM_BUILD_DIR}
10+
cd ${EZPLATFORM_BUILD_DIR}
11+
12+
/bin/bash ./bin/.travis/trusty/setup_ezplatform.sh "${COMPOSE_FILE}" '' "${PACKAGE_BUILD_DIR}"

behat_suites.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is meant to be imported from ezplatform's behat.yml.dist.
2+
# All path are relative to the root ezplatform directory.
3+
default:
4+
autoload:
5+
- '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/bootstrap/'
6+
7+
graphql:
8+
suites:
9+
graphql:
10+
autoload:
11+
- '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/bootstrap/'
12+
paths:
13+
- '%paths.base%/vendor/ezsystems/ezplatform-graphql/features/Generator.feature'
14+
contexts:
15+
- GeneratorContext
16+
- ConfigurationContext
17+
- CacheContext

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"overblog/graphiql-bundle": "^0.1",
2323
"phpspec/phpspec": "^5.1",
2424
"friendsofphp/php-cs-fixer": "~2.15.1",
25-
"mikey179/vfsstream": "^1.6"
25+
"mikey179/vfsstream": "^1.6",
26+
"behat/behat": "^3.0"
2627
},
2728
"autoload": {
2829
"psr-4": {
@@ -37,8 +38,10 @@
3738
},
3839
"extra": {
3940
"branch-alias": {
40-
"dev-master": "1.0.x-dev"
41-
}
41+
"dev-master": "1.0.x-dev",
42+
"dev-tmp_ci_branch": "1.0.x-dev"
43+
},
44+
"_ezplatform_branch_for_behat_tests": "2.5"
4245
},
4346
"scripts": {
4447
"fix-cs": "@php ./vendor/bin/php-cs-fixer fix -v --show-progress=estimating"

features/Generator.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: Schema generation
2+
In order to use GraphQL
3+
As an application maintainer
4+
I need to generate the schema
5+
6+
Scenario: An application maintainer generates the schema
7+
Given the schema has not been generated
8+
When I run the command "ezplatform:graphql:generate-schema"
9+
When I clear the cache
10+
Then the schema files are generated in "app/config/graphql/ezplatform"
11+
And the GraphQL extension is configured to use that schema
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
Assert::assertEquals('DomainContentMutation', (string)$schema->getMutationType());
44+
}
45+
46+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?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+
13+
/**
14+
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
15+
* @license For full copyright and license information view LICENSE file distributed with this source code.
16+
*/
17+
18+
class GeneratorContext implements \Behat\Symfony2Extension\Context\KernelAwareContext
19+
{
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+
if (file_exists('app/config/graphql/ezplatform')) {
62+
$finder = new Finder();
63+
$fs = new Filesystem();
64+
$fs->remove($finder->in('app/config/graphql/ezplatform')->files());
65+
}
66+
}
67+
68+
/**
69+
* Sets Kernel instance.
70+
*
71+
* @param \Symfony\Component\HttpKernel\KernelInterface $kernel
72+
*/
73+
public function setKernel(KernelInterface $kernel)
74+
{
75+
$this->kernel = $kernel;
76+
}
77+
}

0 commit comments

Comments
 (0)