diff --git a/.travis.yml b/.travis.yml index 958a5c769..1e26a4c47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ matrix: - php: 5.6 env: SYMFONY_VERSION=3.1.* SYMFONY_DEPRECATIONS_HELPER=disabled - php: 7.0 - env: SYMFONY_VERSION=3.2.* + env: SYMFONY_VERSION=3.2.* PHPUNIT_VERSION=^5.7.26 - php: 7.1 - php: 7.2 env: PHP_CS_FIXER=true @@ -30,12 +30,10 @@ matrix: - php: 7.2 env: SYMFONY_VERSION=4.0.* TEST_COVERAGE=true - php: 7.2 - env: SYMFONY_VERSION=4.1.* DEPENDENCIES=dev + env: SYMFONY_VERSION=4.1.* STABILITY=beta - php: nightly env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs allow_failures: - - php: 7.2 - env: SYMFONY_VERSION=4.1.* DEPENDENCIES=dev - php: nightly env: COMPOSER_UPDATE_FLAGS=--ignore-platform-reqs @@ -46,15 +44,17 @@ cache: - vendor/ before_install: - - if [ ${DEPENDENCIES} = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi; + - if [ "${STABILITY}" != "" ]; then perl -pi -e 's/^}$/,"minimum-stability":"'"${STABILITY}"'"}/' composer.json; fi; + - if [ "${SYMFONY_VERSION}" != "" ]; then perl -pi -e 's#"(symfony/.*)":\s*".*"#"$1":"'"${SYMFONY_VERSION}"'"#' composer.json; fi; + - if [ "${PHPUNIT_VERSION}" != "" ]; then composer req "phpunit/phpunit:${PHPUNIT_VERSION}" --dev --no-update; fi; - if [ ${TEST_COVERAGE} != true ]; then phpenv config-rm xdebug.ini || true; fi - composer selfupdate - - if [ $SYMFONY_VERSION ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --dev --no-update; fi; - if [ $GRAPHQLPHP_VERSION ]; then composer require "webonyx/graphql-php:${GRAPHQLPHP_VERSION}" --dev --no-update; fi; install: composer update --prefer-source --no-interaction --optimize-autoloader ${COMPOSER_UPDATE_FLAGS} script: + - composer validate --no-check-lock --strict - bin/phpunit --debug $( if [ $TEST_COVERAGE = true ]; then echo "-d xdebug.max_nesting_level=1000 --coverage-clover=build/logs/clover.xml"; fi; ) - if [ ${PHP_CS_FIXER} = true ]; then composer require --dev 'friendsofphp/php-cs-fixer:^2.0' && bin/php-cs-fixer fix --diff --dry-run -v; fi; diff --git a/DependencyInjection/OverblogGraphQLTypesExtension.php b/DependencyInjection/OverblogGraphQLTypesExtension.php index 3c46a047e..350e69532 100644 --- a/DependencyInjection/OverblogGraphQLTypesExtension.php +++ b/DependencyInjection/OverblogGraphQLTypesExtension.php @@ -41,44 +41,57 @@ class OverblogGraphQLTypesExtension extends Extension public function load(array $configs, ContainerBuilder $container) { - $this->checkTypesDuplication($configs); - // flatten config is a requirement to support inheritance - $flattenConfig = [call_user_func_array('array_merge', $configs)]; - $configuration = $this->getConfiguration($flattenConfig, $container); - $config = $this->processConfiguration($configuration, $flattenConfig); + $configs = array_filter($configs); + //$configs = array_filter($configs); + if (count($configs) > 1) { + throw new \InvalidArgumentException('Configs type should never contain more than one config to deal with inheritance.'); + } + $configuration = $this->getConfiguration($configs, $container); + $config = $this->processConfiguration($configuration, $configs); $container->setParameter($this->getAlias().'.config', $config); } - public function containerPrependExtensionConfig(array $config, ContainerBuilder $container) + public function containerPrependExtensionConfig(array $configs, ContainerBuilder $container) { - $typesMappings = $this->mappingConfig($config, $container); + $typesMappings = $this->mappingConfig($configs, $container); // reset treated files $this->treatedFiles = []; $typesMappings = call_user_func_array('array_merge', $typesMappings); + $typeConfigs = []; // treats mappings foreach ($typesMappings as $params) { - $this->prependExtensionConfigFromFiles($params['type'], $params['files'], $container); + $typeConfigs = array_merge($typeConfigs, $this->parseTypeConfigFiles($params['type'], $params['files'], $container)); } + + $this->checkTypesDuplication($typeConfigs); + // flatten config is a requirement to support inheritance + $flattenTypeConfig = call_user_func_array('array_merge', $typeConfigs); + + $container->prependExtensionConfig($this->getAlias(), $flattenTypeConfig); } /** * @param $type * @param SplFileInfo[] $files * @param ContainerBuilder $container + * + * @return array */ - private function prependExtensionConfigFromFiles($type, $files, ContainerBuilder $container) + private function parseTypeConfigFiles($type, $files, ContainerBuilder $container) { + $config = []; foreach ($files as $file) { $fileRealPath = $file->getRealPath(); if (isset($this->treatedFiles[$fileRealPath])) { continue; } - $typeConfig = call_user_func(self::PARSERS[$type].'::parse', $file, $container); - $container->prependExtensionConfig($this->getAlias(), $typeConfig); + $config[] = call_user_func(self::PARSERS[$type].'::parse', $file, $container); $this->treatedFiles[$file->getRealPath()] = true; } + + return $config; } private function checkTypesDuplication(array $typeConfigs) diff --git a/Tests/DependencyInjection/OverblogGraphQLTypesExtensionTest.php b/Tests/DependencyInjection/OverblogGraphQLTypesExtensionTest.php index f1ea2583e..929cdcae2 100644 --- a/Tests/DependencyInjection/OverblogGraphQLTypesExtensionTest.php +++ b/Tests/DependencyInjection/OverblogGraphQLTypesExtensionTest.php @@ -35,12 +35,12 @@ public function tearDown() } /** - * @expectedException \Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Configs type should never contain more than one config to deal with inheritance. */ - public function testDuplicatedType() + public function testMultipleConfigNotAllowed() { - $type = ['foo' => []]; - $configs = [$type, $type]; + $configs = [['foo' => []], ['bar' => []]]; $this->extension->load($configs, $this->container); } diff --git a/Tests/Functional/App/TestKernel.php b/Tests/Functional/App/TestKernel.php index a226f0f6b..f40fc357f 100644 --- a/Tests/Functional/App/TestKernel.php +++ b/Tests/Functional/App/TestKernel.php @@ -5,7 +5,6 @@ use Overblog\GraphQLBundle\OverblogGraphQLBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\SecurityBundle\SecurityBundle; -use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -23,7 +22,6 @@ public function registerBundles() return [ new FrameworkBundle(), new SecurityBundle(), - new TwigBundle(), new OverblogGraphQLBundle(), ]; } diff --git a/Tests/Functional/App/config/access/config.yml b/Tests/Functional/App/config/access/config.yml index b9158fe75..bc6af7294 100644 --- a/Tests/Functional/App/config/access/config.yml +++ b/Tests/Functional/App/config/access/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config.yml } - - { resource: ../security.yml } - { resource: ../connection/services.yml } - { resource: ../mutation/services.yml } diff --git a/Tests/Functional/App/config/config.yml b/Tests/Functional/App/config/config.yml index f2e9aaa7c..fca8eeecf 100644 --- a/Tests/Functional/App/config/config.yml +++ b/Tests/Functional/App/config/config.yml @@ -3,11 +3,29 @@ framework: secret: test router: resource: "%kernel.root_dir%/config/routing.yml" - templating: - engines: ['twig'] profiler: enabled: false +security: + providers: + in_memory: + memory: + users: + ryan: + password: 123 + roles: 'ROLE_USER' + admin: + password: 123 + roles: 'ROLE_ADMIN' + encoders: + Symfony\Component\Security\Core\User\User: plaintext + firewalls: + graph: + pattern: ^/ + http_basic: ~ + stateless: true + anonymous: true + overblog_graphql: errors_handler: debug: false diff --git a/Tests/Functional/App/config/public/config.yml b/Tests/Functional/App/config/public/config.yml index 901ce6e7d..d6147da5f 100644 --- a/Tests/Functional/App/config/public/config.yml +++ b/Tests/Functional/App/config/public/config.yml @@ -1,6 +1,5 @@ imports: - { resource: ../config.yml } - - { resource: ../security.yml } overblog_graphql: definitions: diff --git a/Tests/Functional/App/config/queryComplexityEnv/config.yml b/Tests/Functional/App/config/queryComplexityEnv/config.yml index e2eb1d756..4ffdeac06 100644 --- a/Tests/Functional/App/config/queryComplexityEnv/config.yml +++ b/Tests/Functional/App/config/queryComplexityEnv/config.yml @@ -3,7 +3,7 @@ imports: - { resource: ../connection/services.yml } parameters: - env(GRAPHQL_QUERY_MAX_COMPLEXITY): 10 + env(GRAPHQL_QUERY_MAX_COMPLEXITY): "10" overblog_graphql: security: diff --git a/Tests/Functional/App/config/queryMaxDepthEnv/config.yml b/Tests/Functional/App/config/queryMaxDepthEnv/config.yml index ae134d970..029f93458 100644 --- a/Tests/Functional/App/config/queryMaxDepthEnv/config.yml +++ b/Tests/Functional/App/config/queryMaxDepthEnv/config.yml @@ -3,7 +3,7 @@ imports: - { resource: ../connection/services.yml } parameters: - env(GRAPHQL_QUERY_MAX_DEPTH): 3 + env(GRAPHQL_QUERY_MAX_DEPTH): "3" overblog_graphql: security: diff --git a/Tests/Functional/App/config/security.yml b/Tests/Functional/App/config/security.yml deleted file mode 100644 index 37325245c..000000000 --- a/Tests/Functional/App/config/security.yml +++ /dev/null @@ -1,19 +0,0 @@ -security: - providers: - in_memory: - memory: - users: - ryan: - password: 123 - roles: 'ROLE_USER' - admin: - password: 123 - roles: 'ROLE_ADMIN' - encoders: - Symfony\Component\Security\Core\User\User: plaintext - firewalls: - graph: - pattern: ^/ - http_basic: ~ - stateless: true - anonymous: true diff --git a/Tests/Functional/Command/CompileCommandTest.php b/Tests/Functional/Command/CompileCommandTest.php index 05ed59570..b94b3863d 100644 --- a/Tests/Functional/Command/CompileCommandTest.php +++ b/Tests/Functional/Command/CompileCommandTest.php @@ -78,11 +78,11 @@ private function displayExpected($isVerbose = false) \-[\-]+\s+\-[\-]+\s class\s+path\s* \-[\-]+\s+\-[\-]+\s - Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\PageInfoType {{PATH}}/PageInfoType.php Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\QueryType {{PATH}}/QueryType.php Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\UserType {{PATH}}/UserType.php Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\friendConnectionType {{PATH}}/friendConnectionType.php Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\userConnectionType {{PATH}}/userConnectionType.php + Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\PageInfoType {{PATH}}/PageInfoType.php Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\friendEdgeType {{PATH}}/friendEdgeType.php Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\userEdgeType {{PATH}}/userEdgeType.php \-[\-]+\s+\-[\-]+\s diff --git a/composer.json b/composer.json index ec8825850..08dbea9a4 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,6 @@ "symfony/process": "^3.1 || ^4.0", "symfony/security-bundle": "^3.1 || ^4.0", "symfony/templating": "^3.1 || ^4.0", - "symfony/twig-bundle": "^3.1 || ^4.0", "symfony/web-profiler-bundle": "^3.1 || ^4.0", "symfony/yaml": "^3.1 || ^4.0" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 464c72439..c16e2199f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -29,8 +29,10 @@ - + - + + +