diff --git a/.gitignore b/.gitignore index af180a9..1e6c6d5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ composer.lock composer.phar .php_cs.cache .php_cs +php-cs-fixer.phar diff --git a/.travis.yml b/.travis.yml index 6a0da1b..1a710c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,13 +19,7 @@ matrix: env: COMPOSER_UPDATE_FLAGS=--prefer-lowest - php: 7.1 - php: 7.2 - env: SYMFONY_VERSION=3.2.* - - php: 7.2 - env: SYMFONY_VERSION=3.3.* TEST_COVERAGE=true - - php: 7.2 - env: SYMFONY_VERSION=3.3.* GRAPHQLBUNDLE_VERSION=0.9.* - - php: 7.2 - env: SYMFONY_VERSION=3.4.* GRAPHQLBUNDLE_VERSION=0.10.* DEPENDENCIES=dev + env: SYMFONY_VERSION=3.4.* GRAPHQLBUNDLE_VERSION=0.10.* - php: 7.2 env: SYMFONY_VERSION=3.4.* - php: 7.2 @@ -33,7 +27,11 @@ matrix: - php: 7.3 env: SYMFONY_VERSION=4.1.* - php: 7.3 - env: SYMFONY_VERSION=4.2.* + env: SYMFONY_VERSION=4.3.* TEST_COVERAGE=true + - php: 7.3 + env: SYMFONY_VERSION=4.4.* + - php: 7.3 + env: SYMFONY_VERSION=5.0.* - php: nightly env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs allow_failures: @@ -55,7 +53,7 @@ install: composer update --prefer-source --no-interaction --optimize-autoloader script: - ./bin/phpunit --debug $( if [ "$TEST_COVERAGE" = "true" ]; then echo "-d xdebug.max_nesting_level=1000 --coverage-clover=build/logs/clover.xml"; fi; ) - - if [ "${TEST_COVERAGE}" = "true" ]; then wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer && php ./php-cs-fixer fix --diff --dry-run -v; fi; + - if [ "${TEST_COVERAGE}" = "true" ]; then composer check-cs; fi; after_script: - if [ "${TEST_COVERAGE}" = "true" ]; then wget https://scrutinizer-ci.com/ocular.phar && travis_retry php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi; diff --git a/Tests/DependencyInjection/OverblogGraphiQLExtensionTest.php b/Tests/DependencyInjection/OverblogGraphiQLExtensionTest.php deleted file mode 100644 index 37d61ae..0000000 --- a/Tests/DependencyInjection/OverblogGraphiQLExtensionTest.php +++ /dev/null @@ -1,68 +0,0 @@ -createContainer(); - $container->addCompilerPass($this); - $container->registerExtension(new OverblogGraphiQLExtension()); - $container->loadFromExtension('overblog_graphiql'); - $this->compileContainer($container); - - $jsLibraries = $container->get('overblog_graphiql.view.config.javascript_libraries'); - - $this->assertInstanceOf(GraphiQLViewJavaScriptLibraries::class, $jsLibraries); - $this->assertSame('2.0', $jsLibraries->getFetchVersion()); - $this->assertSame('15.6', $jsLibraries->getReactVersion()); - $this->assertSame('0.11', $jsLibraries->getGraphiQLVersion()); - - $viewConfig = $container->get('overblog_graphiql.view.config'); - - $this->assertInstanceOf(GraphiQLViewConfig::class, $viewConfig); - $this->assertSame('@OverblogGraphiQL/GraphiQL/index.html.twig', $viewConfig->getTemplate()); - $this->assertSame($jsLibraries, $viewConfig->getJavaScriptLibraries()); - - $controllerDefinition = $container->getDefinition('overblog_graphiql.controller'); - $viewConfigArgument = $controllerDefinition->getArgument(1); - $this->assertInstanceOf(Reference::class, $viewConfigArgument); - $this->assertSame('overblog_graphiql.view.config', (string) $viewConfigArgument); - } - - private function createContainer() - { - $container = new ContainerBuilder(new ParameterBag([ - 'kernel.cache_dir' => __DIR__, - 'kernel.root_dir' => __DIR__.'/Fixtures', - 'kernel.charset' => 'UTF-8', - 'kernel.debug' => true, - 'kernel.bundles' => ['GraphiQLBundle' => 'Symfony\\Bundle\\DebugBundle\\GraphiQLBundle'], - ])); - - return $container; - } - - private function compileContainer(ContainerBuilder $container) - { - $container->getCompilerPassConfig()->setOptimizationPasses([]); - $container->getCompilerPassConfig()->setRemovingPasses([]); - $container->compile(); - } - - public function process(ContainerBuilder $container) - { - $container->findDefinition('overblog_graphiql.view.config.javascript_libraries')->setPublic(true); - $container->findDefinition('overblog_graphiql.view.config')->setPublic(true); - } -} diff --git a/Tests/Fixtures/TestKernel.php b/Tests/Fixtures/TestKernel.php index 1d309f7..fa9c900 100644 --- a/Tests/Fixtures/TestKernel.php +++ b/Tests/Fixtures/TestKernel.php @@ -29,9 +29,9 @@ public function registerContainerConfiguration(LoaderInterface $loader) $container->loadFromExtension('framework', [ 'secret' => 'test', 'test' => true, - 'templating' => ['engine' => ['twig']], + //'templating' => ['engine' => ['twig']], 'assets' => ['enabled' => false], - 'router' => ['resource' => '%kernel.root_dir%/../Resources/config/routing.xml'], + 'router' => ['resource' => '%kernel.project_dir%/Resources/config/routing.xml'], ]); }); } diff --git a/Tests/ForwardCompatTestCaseTrait.php b/Tests/ForwardCompatTestCaseTrait.php new file mode 100644 index 0000000..d0e3a69 --- /dev/null +++ b/Tests/ForwardCompatTestCaseTrait.php @@ -0,0 +1,37 @@ +hasReturnType()) { + eval(' + namespace Overblog\GraphiQLBundle\Tests; + + /** + * @internal + */ + trait ForwardCompatTestCaseTrait + { + protected function tearDown(): void + { + static::ensureKernelShutdown(); + static::$kernel = null; + } + } + '); +} else { + /** + * @internal + */ + trait ForwardCompatTestCaseTrait + { + protected function tearDown() + { + static::ensureKernelShutdown(); + static::$kernel = null; + } + } +} diff --git a/Tests/Integration/OverblogGraphQLBundle/Controller/GraphiQLControllerTest.php b/Tests/Integration/OverblogGraphQLBundle/Controller/GraphiQLControllerTest.php index 02e2a7a..61be264 100644 --- a/Tests/Integration/OverblogGraphQLBundle/Controller/GraphiQLControllerTest.php +++ b/Tests/Integration/OverblogGraphQLBundle/Controller/GraphiQLControllerTest.php @@ -7,19 +7,6 @@ final class GraphiQLControllerTest extends TestCase { - public function testSecondSchema() - { - $client = static::createClient(); - - $client->request('GET', '/graphiql/secondFakeSchema'); - $response = $client->getResponse(); - - $this->assertInstanceOf(Response::class, $response); - $this->assertSame(200, $response->getStatusCode()); - $this->stringContains('Loading...', $response->getContent()); - $this->stringContains('var endpoint = "\/graphql\/secondFakeSchema"', $response->getContent()); - } - public function testDefaultSchema() { $client = static::createClient(); diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 4832ec4..0f789d7 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -7,8 +7,7 @@ abstract class TestCase extends WebTestCase { - /** @var TestKernel[] */ - private static $kernels = []; + use ForwardCompatTestCaseTrait; /** * {@inheritdoc} @@ -23,27 +22,15 @@ protected static function getKernelClass() */ protected static function createKernel(array $options = []) { - static::$class = static::getKernelClass(); + if (null === static::$class) { + static::$class = static::getKernelClass(); + } $options['test_case'] = isset($options['test_case']) ? $options['test_case'] : 'default'; $env = isset($options['environment']) ? $options['environment'] : 'overbloggraphibundletest'.strtolower($options['test_case']); $debug = isset($options['debug']) ? $options['debug'] : true; - $kernelKey = '//'.$env.'//'.var_export($debug, true); - - if (!isset(self::$kernels[$kernelKey])) { - self::$kernels[$kernelKey] = new static::$class($env, $debug, $options['test_case']); - } - - return self::$kernels[$kernelKey]; - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - static::$kernel = null; + return new static::$class($env, $debug, $options['test_case']); } } diff --git a/composer.json b/composer.json index 7b2f87b..06683c4 100644 --- a/composer.json +++ b/composer.json @@ -21,23 +21,17 @@ "sort-packages": true }, "require": { - "php": "^5.6 || ^7.0", - "symfony/http-foundation": "^3.2.2 || ^4.0", - "symfony/twig-bundle": "^3.2.10 || ^4.0", - "symfony/routing": "^3.2 || ^4.0" + "php": ">=5.6", + "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0", + "symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0" }, "require-dev": { - "overblog/graphql-bundle": "^0.9.0 || ^0.10.0", + "overblog/graphql-bundle": ">=0.9", "phpunit/phpunit": "^5.7 || ^6.0", - "sensio/framework-extra-bundle": "^3.0 || ^4.0", - "symfony/browser-kit": "^3.2 || ^4.0", - "symfony/config": "^3.2 || ^4.0", - "symfony/console": "^3.2 || ^4.0", - "symfony/dependency-injection": "^3.2 || ^4.0", - "symfony/expression-language": "^3.2 || ^4.0", - "symfony/framework-bundle": "^3.2.2 || ^4.0", - "symfony/templating": "^3.2 || ^4.0", - "symfony/yaml": "^3.2 || ^4.0" + "sensio/framework-extra-bundle": "^3.0 || ^4.0 || ^5.0", + "symfony/browser-kit": "^3.4 || ^4.0 || ^5.0", + "symfony/templating": "^3.4 || ^4.0 || ^5.0", + "symfony/yaml": "^3.4 || ^4.0 || ^5.0" }, "autoload": { "psr-4": { "Overblog\\GraphiQLBundle\\": "" }, @@ -49,5 +43,17 @@ "branch-alias": { "dev-master": "0.1-dev" } + }, + "scripts": { + "test": "bin/phpunit --color=always -v --debug", + "install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.15.3/php-cs-fixer.phar -O php-cs-fixer.phar", + "fix-cs": [ + "@install-cs", + "@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi" + ], + "check-cs": [ + "@install-cs", + "@php php-cs-fixer.phar fix --dry-run --diff -v --allow-risky=yes --ansi" + ] } }