From 48ec7c61ebcaf04955926a985b67d0389137a0ae Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Tue, 31 Oct 2017 15:31:49 +0100 Subject: [PATCH] Dependencies upgrade --- .php_cs.dist | 16 ++ .travis.yml | 18 +-- ExampleTests/ExampleFunctionalTest.php | 12 +- ExampleTests/ExampleUnitTest.php | 4 +- ExampleTests/Fixtures/LoadUserData.php | 4 +- README.md | 37 +---- composer.json | 35 ++-- phpunit.xml.dist | 2 +- src/Annotations/QueryCount.php | 11 ++ src/Command/RunParatestCommand.php | 19 ++- src/Command/TestCommand.php | 48 ++---- .../Compiler/OptionalValidatorPass.php | 13 +- .../Compiler/SetTestClientPass.php | 15 +- src/DependencyInjection/Configuration.php | 4 +- .../LiipFunctionalTestExtension.php | 13 +- src/EventListener/ExceptionListener.php | 10 +- .../AllowedQueriesExceededException.php | 11 ++ src/Factory/ConnectionFactory.php | 13 +- src/LiipFunctionalTestBundle.php | 4 +- src/QueryCountClient.php | 39 +++-- src/QueryCountClientSymfony3Trait.php | 37 +++++ src/QueryCountClientTrait.php | 37 +++++ src/QueryCounter.php | 25 ++- src/Test/ValidationErrorsConstraint.php | 12 +- src/Test/WebTestCase.php | 149 +++++++----------- src/Utils/HttpAssertions.php | 12 +- src/Validator/DataCollectingValidator.php | 24 +-- tests/AcmeBundle.php | 4 +- tests/App/AppKernel.php | 54 ++++--- tests/App/Controller/DefaultController.php | 27 ++-- .../ORM/LoadDependentUserData.php | 8 +- tests/App/DataFixtures/ORM/LoadUserData.php | 6 +- tests/App/Entity/User.php | 4 +- tests/App/bootstrap.php | 11 ++ tests/AppConfig/AppConfigKernel.php | 28 ++-- .../Faker/Provider/FooProvider.php | 16 +- tests/AppConfig/config.yml | 2 +- .../AppConfigLeanFrameworkKernel.php | 18 ++- tests/AppConfigMysql/AppConfigMysqlKernel.php | 18 ++- tests/AppConfigPhpcr/AppConfigPhpcrKernel.php | 22 ++- .../DataFixtures/PHPCR/LoadTaskData.php | 4 +- tests/AppConfigPhpcr/Document/Task.php | 6 +- tests/Command/CommandConfigTest.php | 11 +- tests/Command/CommandTest.php | 31 ++-- tests/Command/ParatestCommandTest.php | 9 +- .../Compiler/SetTestClientPassMockTest.php | 6 +- .../ConfigurationConfigTest.php | 12 +- .../DependencyInjection/ConfigurationTest.php | 8 +- .../WebTestCaseConfigLeanFrameworkTest.php | 13 +- tests/Test/WebTestCaseConfigMysqlTest.php | 21 +-- tests/Test/WebTestCaseConfigPhpcrTest.php | 18 ++- tests/Test/WebTestCaseConfigTest.php | 108 ++----------- tests/Test/WebTestCaseTest.php | 81 ++++------ 53 files changed, 612 insertions(+), 558 deletions(-) create mode 100644 src/QueryCountClientSymfony3Trait.php create mode 100644 src/QueryCountClientTrait.php diff --git a/.php_cs.dist b/.php_cs.dist index cf6228bb..cf1f963e 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,5 +1,14 @@ + +This source file is subject to the MIT license that is bundled +with this source code in the file LICENSE. +HEADER; + $finder = PhpCsFixer\Finder::create() ->in(__DIR__) ->notPath('/cache/') @@ -16,6 +25,9 @@ return PhpCsFixer\Config::create() ], 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, + 'header_comment' => [ + 'header' => $header, + ], 'no_extra_consecutive_blank_lines' => true, 'no_php4_constructor' => true, 'no_useless_else' => true, @@ -24,6 +36,10 @@ return PhpCsFixer\Config::create() 'phpdoc_order' => true, '@PHP56Migration' => true, '@PHP56Migration:risky' => true, + '@PHP70Migration' => true, + '@PHP70Migration:risky' => true, + '@PHP71Migration' => true, + '@PHP71Migration:risky' => true, 'strict_comparison' => true, 'strict_param' => true, 'php_unit_strict' => true, diff --git a/.travis.yml b/.travis.yml index 53b3322d..cb064c20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ dist: trusty language: php php: - - 5.6 - - 7.0 - 7.1 - 7.2 @@ -19,29 +17,23 @@ services: matrix: include: - - php: 5.6 - env: COMPOSER_FLAGS="--prefer-lowest" - - php: 7.1 - env: SYMFONY_VERSION="2.7.*" - - php: 7.1 - env: SYMFONY_VERSION="2.8.*" - - php: 7.1 - env: SYMFONY_VERSION="3.3.*" - php: 7.1 - env: SYMFONY_VERSION="3.4.*" + env: COMPOSER_FLAGS="--prefer-lowest" - php: 7.2 env: SYMFONY_VERSION="3.4.*" - php: 7.2 env: SYMFONY_VERSION="4.0.*" + - php: 7.2 + env: EXTRA_PACKAGES="doctrine/phpcr-bundle:^1.3 brianium/paratest:^1.0 doctrine/phpcr-odm:^1.3" allow_failures: - php: 7.2 - env: SYMFONY_VERSION="4.0.*" + env: SYMFONY_VERSION="dev-master" fast_finish: true before_install: - - if [[ $TRAVIS_PHP_VERSION != '7.0' && $TRAVIS_PHP_VERSION != '7.1' && $TRAVIS_PHP_VERSION != '7.2' ]]; then phpenv config-rm xdebug.ini; fi - echo "memory_limit = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/symfony=$SYMFONY_VERSION; fi + - if [ "$EXTRA_PACKAGES" != "" ]; then composer require --no-update $EXTRA_PACKAGES; fi install: # use "update" instead of "install" since it allows using the "--prefer-lowest" option diff --git a/ExampleTests/ExampleFunctionalTest.php b/ExampleTests/ExampleFunctionalTest.php index 7eabe09c..1ec25571 100644 --- a/ExampleTests/ExampleFunctionalTest.php +++ b/ExampleTests/ExampleFunctionalTest.php @@ -1,5 +1,7 @@ loadFixtures(['Liip\FooBundle\Tests\Fixtures\LoadUserData']); @@ -37,7 +39,7 @@ public function testUserFooIndex() /** * Example using LiipFunctionalBundle WebTestCase helpers and with authentication. */ - public function testBasicAuthentication() + public function testBasicAuthentication(): void { $this->loadFixtures(['Liip\FooBundle\Tests\Fixtures\LoadUserData']); @@ -48,18 +50,18 @@ public function testBasicAuthentication() $this->assertContains('logout', $content); } - public function test404Page() + public function test404Page(): void { $this->fetchContent('/asdasdas', 'GET', false, false); } - public function testLoginPage() + public function testLoginPage(): void { $content = $this->fetchContent('/', 'GET', false); $this->assertContains('login', $content); } - public function testValidationErrors() + public function testValidationErrors(): void { $client = $this->makeClient(true); $crawler = $client->request('GET', '/users/1/edit'); diff --git a/ExampleTests/ExampleUnitTest.php b/ExampleTests/ExampleUnitTest.php index fefa8e46..cf8ee6b8 100644 --- a/ExampleTests/ExampleUnitTest.php +++ b/ExampleTests/ExampleUnitTest.php @@ -1,5 +1,7 @@ getServiceMockBuilder('FooView')->getMock(); diff --git a/ExampleTests/Fixtures/LoadUserData.php b/ExampleTests/Fixtures/LoadUserData.php index 56203716..90490d85 100644 --- a/ExampleTests/Fixtures/LoadUserData.php +++ b/ExampleTests/Fixtures/LoadUserData.php @@ -1,5 +1,7 @@ setName('foo bar'); diff --git a/README.md b/README.md index 64b646c3..006fbbf3 100644 --- a/README.md +++ b/README.md @@ -404,8 +404,9 @@ Tips for Fixture Loading Tests If you would like to setup your fixtures with yml files using [Alice](https://github.com/nelmio/alice), [`Liip\FunctionalTestBundle\Test\WebTestCase`](Test/WebTestCase.php) has a helper function `loadFixtureFiles` which takes an array of resources, or paths to yml files, and returns an array of objects. -This method uses the [Alice Loader](https://github.com/nelmio/alice/blob/master/src/Nelmio/Alice/Fixtures/Loader.php) -rather than the FunctionalTestBundle's load methods. You should be aware that there are some difference between the ways these two libraries handle loading. +This method uses the [Theofidry AliceDataFixtures loader](https://github.com/theofidry/AliceDataFixtures#doctrine-orm) +rather than the FunctionalTestBundle's load methods. +You should be aware that there are some difference between the ways these two libraries handle loading. ```php $fixtures = $this->loadFixtureFiles(array( @@ -446,38 +447,6 @@ $files = array( $fixtures = $this->loadFixtureFiles($files, true, null, 'doctrine', ORMPurger::PURGE_MODE_TRUNCATE ); ``` -#### HautelookAliceBundle Faker Providers - -This bundle supports faker providers from HautelookAliceBundle. -Install the bundle with `composer require --dev hautelook/alice-bundle:~1.2` and use the -[HautelookAliceBundle documentation](https://github.com/hautelook/AliceBundle/blob/1.x/src/Resources/doc/faker-providers.md#faker-providers) -in order to define your faker providers. - -You'll have to add the following line in the `app/AppKernel.php` file: - -```php -getEnvironment(), array('dev', 'test'))) { - $bundles[] = new Hautelook\AliceBundle\HautelookAliceBundle(); - } - - return $bundles; - } - - // ... -} -``` - -Then you can load fixtures with `$this->loadFixtureFiles(array('@AcmeBundle/…/fixture.yml'));`. - ### Non-SQLite The Bundle will not automatically create your schema for you unless you use SQLite. diff --git a/composer.json b/composer.json index 7ca58d53..798db57a 100644 --- a/composer.json +++ b/composer.json @@ -15,28 +15,23 @@ } ], "require": { - "php": "^5.6|^7.0", - "symfony/framework-bundle": "^2.7|^3.0|^4.0", - "symfony/browser-kit": "^2.7|^3.0|^4.0", - "doctrine/common": "~2.0" + "php": "^7.1", + "symfony/framework-bundle": "^3.4 || ^4.0", + "symfony/browser-kit": "^3.4 || ^4.0", + "doctrine/common": "^2.0" }, "require-dev": { - "symfony/symfony": "^2.7.1|^3.3|^4.0", - "symfony/phpunit-bridge": "^2.7|^3.0|^4.0", - "doctrine/orm": "~2.5", - "symfony/console": "^2.7|^3.0|^4.0", - "symfony/assetic-bundle": "^2.7|^3.0|^4.0", - "symfony/monolog-bundle": "^2.7|^3.0|^4.0", - "doctrine/doctrine-fixtures-bundle": "~2.3", - "phpunit/phpunit": "^4.8.35|^5.7|^6.1", - "twig/twig": "~1.12|~2.0", - "nelmio/alice": "~1.7|~2.0", - "jackalope/jackalope-doctrine-dbal": "1.1.*|1.2.*", - "doctrine/phpcr-odm": "~1.3", - "doctrine/phpcr-bundle": "~1.3", - "hautelook/alice-bundle": "~0.2|~1.2", - "brianium/paratest": "~0.12.0|~0.13.2", - "doctrine/data-fixtures": "1.2.2" + "symfony/symfony": "^3.4 || ^4.0", + "symfony/phpunit-bridge": "^3.4 || ^4.0", + "doctrine/orm": "^2.5", + "symfony/monolog-bundle": "^3.1", + "doctrine/doctrine-fixtures-bundle": "^3.0", + "doctrine/doctrine-bundle": "^1.8", + "phpunit/phpunit": "^6.1", + "twig/twig": "^2.0", + "theofidry/alice-data-fixtures": "^1.0.1", + "jackalope/jackalope-doctrine-dbal": "^1.3", + "doctrine/data-fixtures": "^1.3" }, "suggest": { "symfony/framework-bundle": "To use assertStatusCode and assertValidationErrors ~2.5", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f5fa271a..7f3fe992 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,7 +10,7 @@ > - + diff --git a/src/Annotations/QueryCount.php b/src/Annotations/QueryCount.php index d01c321e..ff33f371 100644 --- a/src/Annotations/QueryCount.php +++ b/src/Annotations/QueryCount.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Liip\FunctionalTestBundle\Annotations; /** diff --git a/src/Command/RunParatestCommand.php b/src/Command/RunParatestCommand.php index d4ce657e..29bc3bf7 100644 --- a/src/Command/RunParatestCommand.php +++ b/src/Command/RunParatestCommand.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Liip\FunctionalTestBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; @@ -26,7 +37,7 @@ class RunParatestCommand extends ContainerAwareCommand /** * Configuration of the command. */ - protected function configure() + protected function configure(): void { $this ->setName('paratest:run') @@ -36,7 +47,7 @@ protected function configure() ; } - protected function prepare() + protected function prepare(): void { $this->phpunit = $this->getContainer()->getParameter('liip_functional_test.paratest.phpunit'); $this->process = $this->getContainer()->getParameter('liip_functional_test.paratest.process'); @@ -73,7 +84,7 @@ protected function prepare() * @param InputInterface $input * @param OutputInterface $output */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $this->output = $output; $this->prepare(); @@ -88,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output) '-p '.$this->process.' '. $input->getArgument('options') ); - $runProcess->run(function ($type, $buffer) use ($output) { + $runProcess->run(function ($type, $buffer) use ($output): void { $output->write($buffer); }); } diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php index 6ea79504..71476ba2 100644 --- a/src/Command/TestCommand.php +++ b/src/Command/TestCommand.php @@ -1,5 +1,7 @@ writeln('Symfony version: '.$version); $output->writeln('Environment: '.$this->container->get('kernel')->getEnvironment()); $output->writeln('Verbosity level set: '.$output->getVerbosity()); - // Check for the version of Symfony: 20803 is the 2.8 - if ($version >= 20803) { - $output->writeln('Environment: '.$this->container->get('kernel')->getEnvironment(), OutputInterface::VERBOSITY_NORMAL); - - // Write a line with OutputInterface::VERBOSITY_NORMAL (also if this level is set by default by Console) - $output->writeln('Verbosity level: NORMAL', OutputInterface::VERBOSITY_NORMAL); - - // Write a line with OutputInterface::VERBOSITY_VERBOSE - $output->writeln('Verbosity level: VERBOSE', OutputInterface::VERBOSITY_VERBOSE); - - // Write a line with OutputInterface::VERBOSITY_VERY_VERBOSE - $output->writeln('Verbosity level: VERY_VERBOSE', OutputInterface::VERBOSITY_VERY_VERBOSE); + $output->writeln('Environment: '.$this->container->get('kernel')->getEnvironment(), OutputInterface::VERBOSITY_NORMAL); - // Write a line with OutputInterface::VERBOSITY_DEBUG - $output->writeln('Verbosity level: DEBUG', OutputInterface::VERBOSITY_DEBUG); - } else { - if ($output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL) { - $output->writeln('Verbosity level: NORMAL'); - } + // Write a line with OutputInterface::VERBOSITY_NORMAL (also if this level is set by default by Console) + $output->writeln('Verbosity level: NORMAL', OutputInterface::VERBOSITY_NORMAL); - if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { - $output->writeln('Verbosity level: VERBOSE'); - } + // Write a line with OutputInterface::VERBOSITY_VERBOSE + $output->writeln('Verbosity level: VERBOSE', OutputInterface::VERBOSITY_VERBOSE); - if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { - $output->writeln('Verbosity level: VERY_VERBOSE'); - } + // Write a line with OutputInterface::VERBOSITY_VERY_VERBOSE + $output->writeln('Verbosity level: VERY_VERBOSE', OutputInterface::VERBOSITY_VERY_VERBOSE); - if (OutputInterface::VERBOSITY_DEBUG === $output->getVerbosity()) { - $output->writeln('Verbosity level: DEBUG'); - } - } + // Write a line with OutputInterface::VERBOSITY_DEBUG + $output->writeln('Verbosity level: DEBUG', OutputInterface::VERBOSITY_DEBUG); } } diff --git a/src/DependencyInjection/Compiler/OptionalValidatorPass.php b/src/DependencyInjection/Compiler/OptionalValidatorPass.php index c874b433..5740b7e0 100644 --- a/src/DependencyInjection/Compiler/OptionalValidatorPass.php +++ b/src/DependencyInjection/Compiler/OptionalValidatorPass.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Liip\FunctionalTestBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -7,7 +18,7 @@ class OptionalValidatorPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasDefinition('validator')) { $container->removeDefinition('liip_functional_test.validator'); diff --git a/src/DependencyInjection/Compiler/SetTestClientPass.php b/src/DependencyInjection/Compiler/SetTestClientPass.php index f29e2a5b..f6e3cf26 100644 --- a/src/DependencyInjection/Compiler/SetTestClientPass.php +++ b/src/DependencyInjection/Compiler/SetTestClientPass.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Liip\FunctionalTestBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Alias; @@ -8,7 +19,7 @@ class SetTestClientPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (null === $container->getParameter('liip_functional_test.query.max_query_count')) { $container->removeDefinition('liip_functional_test.query.count_client'); @@ -32,6 +43,6 @@ public function process(ContainerBuilder $container) throw new \Exception('The LiipFunctionalTestBundle\'s Query Counter can only be used in the test environment.'.PHP_EOL.'See https://github.com/liip/LiipFunctionalTestBundle#only-in-test-environment'); } - $container->setAlias('test.client', 'liip_functional_test.query.count_client'); + $container->setAlias('test.client', new Alias('liip_functional_test.query.count_client', true)); } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index da54a959..eb8f3b2a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -1,5 +1,7 @@ root('liip_functional_test', 'array'); diff --git a/src/DependencyInjection/LiipFunctionalTestExtension.php b/src/DependencyInjection/LiipFunctionalTestExtension.php index 91d75fc0..8601d99a 100644 --- a/src/DependencyInjection/LiipFunctionalTestExtension.php +++ b/src/DependencyInjection/LiipFunctionalTestExtension.php @@ -1,5 +1,7 @@ processConfiguration(new Configuration(), $configs); @@ -53,13 +55,6 @@ public function load(array $configs, ContainerBuilder $container) } $definition = $container->getDefinition('liip_functional_test.query.count_client'); - if (method_exists($definition, 'setShared')) { - $definition->setShared(false); - } else { - // This block will never be reached with Symfony <2.8 - // @codeCoverageIgnoreStart - $definition->setScope('prototype'); - // @codeCoverageIgnoreEnd - } + $definition->setShared(false); } } diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 6e25fb78..6a360584 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -1,5 +1,7 @@ lastException = $event->getException(); } - public function clearLastException(GetResponseEvent $event) + public function clearLastException(GetResponseEvent $event): void { if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { $this->lastException = null; } } - public function getLastException() + public function getLastException(): ?\Exception { return $this->lastException; } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::EXCEPTION => ['setException', 99999], diff --git a/src/Exception/AllowedQueriesExceededException.php b/src/Exception/AllowedQueriesExceededException.php index b6bfce42..a9444caa 100644 --- a/src/Exception/AllowedQueriesExceededException.php +++ b/src/Exception/AllowedQueriesExceededException.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Liip\FunctionalTestBundle\Exception; class AllowedQueriesExceededException extends \Exception diff --git a/src/Factory/ConnectionFactory.php b/src/Factory/ConnectionFactory.php index 71ae9d03..f57812e5 100644 --- a/src/Factory/ConnectionFactory.php +++ b/src/Factory/ConnectionFactory.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Liip\FunctionalTestBundle\Factory; use Doctrine\Bundle\DoctrineBundle\ConnectionFactory as BaseConnectionFactory; @@ -35,7 +46,7 @@ public function createConnection(array $params, Configuration $config = null, Ev return parent::createConnection($params, $config, $eventManager, $mappingTypes); } - private function getDbNameFromEnv($dbName) + private function getDbNameFromEnv(string $dbName) { return 'dbTest'.getenv('TEST_TOKEN'); } diff --git a/src/LiipFunctionalTestBundle.php b/src/LiipFunctionalTestBundle.php index e40b923b..36a92984 100644 --- a/src/LiipFunctionalTestBundle.php +++ b/src/LiipFunctionalTestBundle.php @@ -1,5 +1,7 @@ addCompilerPass(new SetTestClientPass()); $container->addCompilerPass(new OptionalValidatorPass()); diff --git a/src/QueryCountClient.php b/src/QueryCountClient.php index cbcab1b9..f4132949 100644 --- a/src/QueryCountClient.php +++ b/src/QueryCountClient.php @@ -1,30 +1,43 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Liip\FunctionalTestBundle; use Symfony\Bundle\FrameworkBundle\Client; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass; + +// Symfony <4 BC +if (class_exists(CompilerDebugDumpPass::class)) { + class_alias(QueryCountClientSymfony3Trait::class, QueryCountClientTrait::class); +} class QueryCountClient extends Client { + /* + * We use trait only because of Client::request signature strict type mismatch between Symfony 3 and 4. + */ + use QueryCountClientTrait; + /** @var QueryCounter */ private $queryCounter; - public function setQueryCounter(QueryCounter $queryCounter) + public function setQueryCounter(QueryCounter $queryCounter): void { $this->queryCounter = $queryCounter; } - public function request( - $method, - $uri, - array $parameters = [], - array $files = [], - array $server = [], - $content = null, - $changeHistory = true - ) { - $crawler = parent::request($method, $uri, $parameters, $files, $server, $content, $changeHistory); - + private function checkQueryCount(): void + { if ($this->getProfile()) { $this->queryCounter->checkQueryCount( $this->getProfile()->getCollector('db')->getQueryCount() @@ -38,7 +51,5 @@ public function request( "\n"; // @codeCoverageIgnoreEnd } - - return $crawler; } } diff --git a/src/QueryCountClientSymfony3Trait.php b/src/QueryCountClientSymfony3Trait.php new file mode 100644 index 00000000..25f9818f --- /dev/null +++ b/src/QueryCountClientSymfony3Trait.php @@ -0,0 +1,37 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Liip\FunctionalTestBundle; + +/** + * @author Sullivan Senechal + * + * @internal + */ +trait QueryCountClientSymfony3Trait +{ + public function request( + $method, + $uri, + array $parameters = [], + array $files = [], + array $server = [], + $content = null, + $changeHistory = true + ) { + $crawler = parent::request($method, $uri, $parameters, $files, $server, $content, $changeHistory); + $this->checkQueryCount(); + + return $crawler; + } +} diff --git a/src/QueryCountClientTrait.php b/src/QueryCountClientTrait.php new file mode 100644 index 00000000..d710f104 --- /dev/null +++ b/src/QueryCountClientTrait.php @@ -0,0 +1,37 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Liip\FunctionalTestBundle; + +/** + * @author Sullivan Senechal + * + * @internal + */ +trait QueryCountClientTrait +{ + public function request( + string $method, + string $uri, + array $parameters = [], + array $files = [], + array $server = [], + string $content = null, + bool $changeHistory = true + ) { + $crawler = parent::request($method, $uri, $parameters, $files, $server, $content, $changeHistory); + $this->checkQueryCount(); + + return $crawler; + } +} diff --git a/src/QueryCounter.php b/src/QueryCounter.php index 0ec20879..2e97d173 100644 --- a/src/QueryCounter.php +++ b/src/QueryCounter.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Liip\FunctionalTestBundle; use Doctrine\Common\Annotations\Reader; @@ -11,16 +22,16 @@ class QueryCounter /** @var int */ private $defaultMaxCount; - /** @var \Doctrine\Common\Annotations\AnnotationReader */ + /** @var Reader */ private $annotationReader; - public function __construct($defaultMaxCount, Reader $annotationReader) + public function __construct(int $defaultMaxCount, Reader $annotationReader) { $this->defaultMaxCount = $defaultMaxCount; $this->annotationReader = $annotationReader; } - public function checkQueryCount($actualQueryCount) + public function checkQueryCount(int $actualQueryCount): void { $maxQueryCount = $this->getMaxQueryCount(); @@ -35,18 +46,18 @@ public function checkQueryCount($actualQueryCount) } } - private function getMaxQueryCount() + private function getMaxQueryCount(): int { $maxQueryCount = $this->getMaxQueryAnnotation(); - if (false !== $maxQueryCount) { + if (null !== $maxQueryCount) { return $maxQueryCount; } return $this->defaultMaxCount; } - private function getMaxQueryAnnotation() + private function getMaxQueryAnnotation(): ?int { foreach (debug_backtrace() as $step) { if ('test' === substr($step['function'], 0, 4)) { //TODO: handle tests with the @test annotation @@ -64,6 +75,6 @@ private function getMaxQueryAnnotation() } } - return false; + return null; } } diff --git a/src/Test/ValidationErrorsConstraint.php b/src/Test/ValidationErrorsConstraint.php index 128185cc..f06ae1a8 100644 --- a/src/Test/ValidationErrorsConstraint.php +++ b/src/Test/ValidationErrorsConstraint.php @@ -1,5 +1,7 @@ getContainer()->get($id); $class = get_class($service); @@ -115,7 +101,7 @@ protected function getServiceMockBuilder($id) * * @return string */ - protected function runCommand($name, array $params = [], $reuseKernel = false) + protected function runCommand(string $name, array $params = [], bool $reuseKernel = false): string { array_unshift($params, $name); @@ -158,7 +144,7 @@ protected function runCommand($name, array $params = [], $reuseKernel = false) * * @return int */ - protected function getVerbosityLevel() + protected function getVerbosityLevel(): int { // If `null`, is not yet set if (null === $this->verbosityLevel) { @@ -186,7 +172,7 @@ protected function getVerbosityLevel() return $this->verbosityLevel; } - public function setVerbosityLevel($level) + public function setVerbosityLevel($level): void { $this->verbosityLevel = $level; } @@ -198,7 +184,7 @@ public function setVerbosityLevel($level) * * @param $level */ - private function setVerbosityLevelEnv($level) + private function setVerbosityLevelEnv($level): void { putenv('SHELL_VERBOSITY='.$level); } @@ -208,7 +194,7 @@ private function setVerbosityLevelEnv($level) * * @return bool */ - protected function getDecorated() + protected function getDecorated(): bool { if (null === $this->decorated) { // Set the global decoration flag that is set to `true` by the TreeBuilder in Configuration @@ -225,7 +211,7 @@ protected function getDecorated() return $this->decorated; } - public function isDecorated($decorated) + public function isDecorated(bool $decorated): void { $this->decorated = $decorated; } @@ -236,14 +222,9 @@ public function isDecorated($decorated) * * @return ContainerInterface */ - protected function getContainer() + protected function getContainer(): ContainerInterface { - if (!empty($this->kernelDir)) { - $tmpKernelDir = isset($_SERVER['KERNEL_DIR']) ? $_SERVER['KERNEL_DIR'] : null; - $_SERVER['KERNEL_DIR'] = getcwd().$this->kernelDir; - } - - $cacheKey = $this->kernelDir.'|'.$this->environment; + $cacheKey = $this->environment; if (empty($this->containers[$cacheKey])) { $options = [ 'environment' => $this->environment, @@ -254,10 +235,6 @@ protected function getContainer() $this->containers[$cacheKey] = $kernel->getContainer(); } - if (isset($tmpKernelDir)) { - $_SERVER['KERNEL_DIR'] = $tmpKernelDir; - } - return $this->containers[$cacheKey]; } @@ -271,7 +248,7 @@ protected function getContainer() * * @return \DateTime|null */ - protected function getFixtureLastModified($class) + protected function getFixtureLastModified($class): ?\DateTime { $lastModifiedDateTime = null; @@ -296,7 +273,7 @@ protected function getFixtureLastModified($class) * @return bool TRUE if the backup was made since the modifications to the * fixtures; FALSE otherwise */ - protected function isBackupUpToDate(array $classNames, $backup) + protected function isBackupUpToDate(array $classNames, string $backup): bool { $backupLastModifiedDateTime = new \DateTime(); $backupLastModifiedDateTime->setTimestamp(filemtime($backup)); @@ -338,7 +315,7 @@ protected function isBackupUpToDate(array $classNames, $backup) * * @return null|AbstractExecutor */ - protected function loadFixtures(array $classNames = [], $omName = null, $registryName = 'doctrine', $purgeMode = null) + protected function loadFixtures(array $classNames = [], ?string $omName = null, string $registryName = 'doctrine', ?int $purgeMode = null): ?AbstractExecutor { $container = $this->getContainer(); /** @var ManagerRegistry $registry */ @@ -365,7 +342,7 @@ protected function loadFixtures(array $classNames = [], $omName = null, $registr $params = $params['master']; } - $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false); + $name = $params['path'] ?? ($params['dbname'] ?? false); if (!$name) { throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped."); } @@ -464,11 +441,11 @@ protected function loadFixtures(array $classNames = [], $omName = null, $registr * * @param ManagerRegistry $registry * @param EntityManager $om - * @param null $omName + * @param string|null $omName * @param string $registryName * @param int $purgeMode */ - private function cleanDatabase(ManagerRegistry $registry, EntityManager $om, $omName = null, $registryName = 'doctrine', $purgeMode = null) + private function cleanDatabase(ManagerRegistry $registry, EntityManager $om, ?string $omName = null, $registryName = 'doctrine', ?int $purgeMode = null): void { $connection = $om->getConnection(); @@ -495,7 +472,7 @@ private function cleanDatabase(ManagerRegistry $registry, EntityManager $om, $om * * @return array $files */ - private function locateResources($paths) + private function locateResources(array $paths): array { $files = []; @@ -528,18 +505,16 @@ private function locateResources($paths) * * @return array */ - public function loadFixtureFiles(array $paths = [], $append = false, $omName = null, $registryName = 'doctrine', $purgeMode = null) + public function loadFixtureFiles(array $paths = [], bool $append = false, ?string $omName = null, $registryName = 'doctrine', ?int $purgeMode = null) { - if (!class_exists('Nelmio\Alice\Fixtures')) { - // This class is available during tests, no exception will be thrown. - // @codeCoverageIgnoreStart - throw new \BadMethodCallException('nelmio/alice should be installed to use this method.'); - // @codeCoverageIgnoreEnd - } - /** @var ContainerInterface $container */ $container = $this->getContainer(); + $persisterLoaderServiceName = 'fidry_alice_data_fixtures.loader.doctrine'; + if (!$container->has($persisterLoaderServiceName)) { + throw new \BadMethodCallException('theofidry/alice-data-fixtures must be installed to use this method.'); + } + /** @var ManagerRegistry $registry */ $registry = $container->get($registryName); @@ -552,25 +527,14 @@ public function loadFixtureFiles(array $paths = [], $append = false, $omName = n $files = $this->locateResources($paths); - // Check if the Hautelook AliceBundle is registered and if yes, use it instead of Nelmio Alice - $hautelookLoaderServiceName = 'hautelook_alice.fixtures.loader'; - if ($container->has($hautelookLoaderServiceName)) { - $loaderService = $container->get($hautelookLoaderServiceName); - $persisterClass = class_exists('Nelmio\Alice\ORM\Doctrine') ? - 'Nelmio\Alice\ORM\Doctrine' : - 'Nelmio\Alice\Persister\Doctrine'; - - return $loaderService->load(new $persisterClass($om), $files); - } - - return Fixtures::load($files, $om); + return $container->get($persisterLoaderServiceName)->load($files); } /** * Callback function to be executed after Schema creation. * Use this to execute acl:init or other things necessary. */ - protected function postFixtureSetup() + protected function postFixtureSetup(): void { } @@ -606,7 +570,7 @@ protected function preFixtureRestore(ObjectManager $manager, ProxyReferenceRepos * * @return WebTestCase */ - protected function postFixtureBackupRestore($backupFilePath) + protected function postFixtureBackupRestore($backupFilePath): self { $this->postFixtureRestore(); @@ -625,8 +589,8 @@ protected function postFixtureBackupRestore($backupFilePath) protected function preFixtureBackupRestore( ObjectManager $manager, ProxyReferenceRepository $referenceRepository, - $backupFilePath - ) { + string $backupFilePath + ): self { $this->preFixtureRestore($manager, $referenceRepository); return $this; @@ -639,10 +603,11 @@ protected function preFixtureBackupRestore( * @param AbstractExecutor $executor Executor of the data fixtures * @param string $backupFilePath Path of file used to backup the references of the data fixtures * - * @return WebTestCase + * @return WebTestCase|null */ - protected function postReferenceSave(ObjectManager $manager, AbstractExecutor $executor, $backupFilePath) + protected function postReferenceSave(ObjectManager $manager, AbstractExecutor $executor, string $backupFilePath): self { + return $this; } /** @@ -652,10 +617,11 @@ protected function postReferenceSave(ObjectManager $manager, AbstractExecutor $e * @param AbstractExecutor $executor Executor of the data fixtures * @param string $backupFilePath Path of file used to backup the references of the data fixtures * - * @return WebTestCase + * @return WebTestCase|null */ - protected function preReferenceSave(ObjectManager $manager, AbstractExecutor $executor, $backupFilePath) + protected function preReferenceSave(ObjectManager $manager, AbstractExecutor $executor, ?string $backupFilePath): self { + return $this; } /** @@ -666,18 +632,9 @@ protected function preReferenceSave(ObjectManager $manager, AbstractExecutor $ex * * @return Loader */ - protected function getFixtureLoader(ContainerInterface $container, array $classNames) + protected function getFixtureLoader(ContainerInterface $container, array $classNames): Loader { - $loaderClass = class_exists('Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader') - ? 'Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader' - : (class_exists('Doctrine\Bundle\FixturesBundle\Common\DataFixtures\Loader') - // This class is not available during tests. - // @codeCoverageIgnoreStart - ? 'Doctrine\Bundle\FixturesBundle\Common\DataFixtures\Loader' - // @codeCoverageIgnoreEnd - : 'Symfony\Bundle\DoctrineFixturesBundle\Common\DataFixtures\Loader'); - - $loader = new $loaderClass($container); + $loader = new ContainerAwareLoader($container); foreach ($classNames as $className) { $this->loadFixtureClass($loader, $className); @@ -692,7 +649,7 @@ protected function getFixtureLoader(ContainerInterface $container, array $classN * @param Loader $loader * @param string $className */ - protected function loadFixtureClass($loader, $className) + protected function loadFixtureClass(Loader $loader, string $className): void { $fixture = null; @@ -732,7 +689,7 @@ protected function loadFixtureClass($loader, $className) * * @return Client */ - protected function makeClient($authentication = false, array $params = []) + protected function makeClient($authentication = false, array $params = []): Client { if ($authentication) { if (true === $authentication) { @@ -797,7 +754,7 @@ protected function makeClient($authentication = false, array $params = []) * * @return TokenInterface The token to be used in the security context */ - protected function createUserToken(UserInterface $user, $firewallName) + protected function createUserToken(UserInterface $user, string $firewallName): TokenInterface { return new UsernamePasswordToken( $user, @@ -816,7 +773,7 @@ protected function createUserToken(UserInterface $user, $firewallName) * * @return string */ - protected function getUrl($route, $params = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) + protected function getUrl(string $route, array $params = [], int $absolute = UrlGeneratorInterface::ABSOLUTE_PATH): string { return $this->getContainer()->get('router')->generate($route, $params, $absolute); } @@ -828,7 +785,7 @@ protected function getUrl($route, $params = [], $absolute = UrlGeneratorInterfac * @param bool $success to define whether the response is expected to be successful * @param string $type */ - public function isSuccessful(Response $response, $success = true, $type = 'text/html') + public function isSuccessful(Response $response, $success = true, $type = 'text/html'): void { HttpAssertions::isSuccessful($response, $success, $type); } @@ -845,7 +802,7 @@ public function isSuccessful(Response $response, $success = true, $type = 'text/ * * @return string */ - public function fetchContent($path, $method = 'GET', $authentication = false, $success = true) + public function fetchContent(string $path, string $method = 'GET', bool $authentication = false, bool $success = true): string { $client = $this->makeClient($authentication); $client->request($method, $path); @@ -870,7 +827,7 @@ public function fetchContent($path, $method = 'GET', $authentication = false, $s * * @return Crawler */ - public function fetchCrawler($path, $method = 'GET', $authentication = false, $success = true) + public function fetchCrawler(string $path, string $method = 'GET', bool $authentication = false, bool $success = true): Crawler { $client = $this->makeClient($authentication); $crawler = $client->request($method, $path); @@ -886,7 +843,7 @@ public function fetchCrawler($path, $method = 'GET', $authentication = false, $s * * @return WebTestCase */ - public function loginAs(UserInterface $user, $firewallName) + public function loginAs(UserInterface $user, string $firewallName): self { $this->firewallLogins[$firewallName] = $user; @@ -898,10 +855,10 @@ public function loginAs(UserInterface $user, $firewallName) * $client matches the expected code. If not, raises an error with more * information. * - * @param $expectedStatusCode + * @param int $expectedStatusCode * @param Client $client */ - public function assertStatusCode($expectedStatusCode, Client $client) + public function assertStatusCode(int $expectedStatusCode, Client $client): void { HttpAssertions::assertStatusCode($expectedStatusCode, $client); } @@ -913,7 +870,7 @@ public function assertStatusCode($expectedStatusCode, Client $client) * @param array $expected A flat array of field names * @param ContainerInterface $container */ - public function assertValidationErrors(array $expected, ContainerInterface $container) + public function assertValidationErrors(array $expected, ContainerInterface $container): void { HttpAssertions::assertValidationErrors($expected, $container); } @@ -921,7 +878,7 @@ public function assertValidationErrors(array $expected, ContainerInterface $cont /** * @param array $excludedDoctrineTables */ - public function setExcludedDoctrineTables($excludedDoctrineTables) + public function setExcludedDoctrineTables(array $excludedDoctrineTables): void { $this->excludedDoctrineTables = $excludedDoctrineTables; } diff --git a/src/Utils/HttpAssertions.php b/src/Utils/HttpAssertions.php index 8e94830e..7be81660 100644 --- a/src/Utils/HttpAssertions.php +++ b/src/Utils/HttpAssertions.php @@ -1,5 +1,7 @@ getPropertyPath(), $error->getMessage()); } } else { - $helpfulErrorMessage = substr($client->getResponse(), 0, 200); + $helpfulErrorMessage = substr((string) $client->getResponse(), 0, 200); } } @@ -88,7 +90,7 @@ public static function assertStatusCode($expectedStatusCode, Client $client) * @param array $expected A flat array of field names * @param ContainerInterface $container */ - public static function assertValidationErrors(array $expected, ContainerInterface $container) + public static function assertValidationErrors(array $expected, ContainerInterface $container): void { if (!$container->has('liip_functional_test.validator')) { trigger_error(sprintf('Method %s() can not be used as the validation component of the Symfony framework is disabled.', __METHOD__, __CLASS__), E_USER_WARNING); diff --git a/src/Validator/DataCollectingValidator.php b/src/Validator/DataCollectingValidator.php index cc8e5d9e..73dc5b74 100644 --- a/src/Validator/DataCollectingValidator.php +++ b/src/Validator/DataCollectingValidator.php @@ -1,5 +1,7 @@ clearLastErrors(); } - public function clearLastErrors() + public function clearLastErrors(): void { $this->lastErrors = new ConstraintViolationList(); } - public function getLastErrors() + public function getLastErrors(): ConstraintViolationListInterface { return $this->lastErrors; } - public function getMetadataFor($value) + public function getMetadataFor($value): MetadataInterface { return $this->wrappedValidator->getMetadataFor($value); } - public function hasMetadataFor($value) + public function hasMetadataFor($value): bool { return $this->wrappedValidator->hasMetadataFor($value); } - public function validate($value, $constraints = null, $groups = null) + public function validate($value, $constraints = null, $groups = null): ConstraintViolationListInterface { return $this->lastErrors = $this->wrappedValidator->validate($value, $constraints, $groups); } - public function validateProperty($object, $propertyName, $groups = null) + public function validateProperty($object, $propertyName, $groups = null): ConstraintViolationListInterface { return $this->wrappedValidator->validateProperty($object, $propertyName, $groups); } - public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null) + public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null): ConstraintViolationListInterface { return $this->wrappedValidator->validatePropertyValue($objectOrClass, $propertyName, $value, $groups); } - public function startContext() + public function startContext(): ContextualValidatorInterface { return $this->wrappedValidator->startContext(); } - public function inContext(ExecutionContextInterface $context) + public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface { return $this->wrappedValidator->inContext($context); } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => ['clearLastErrors', 99999], diff --git a/tests/AcmeBundle.php b/tests/AcmeBundle.php index a5b55775..a44a75b7 100644 --- a/tests/AcmeBundle.php +++ b/tests/AcmeBundle.php @@ -1,5 +1,7 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. */ use Symfony\Component\Config\Loader\LoaderInterface; @@ -17,39 +28,32 @@ class AppKernel extends Kernel { - public function registerBundles() + public function registerBundles(): array { $bundles = [ - new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), - new Symfony\Bundle\SecurityBundle\SecurityBundle(), - new Symfony\Bundle\TwigBundle\TwigBundle(), - new Symfony\Bundle\MonologBundle\MonologBundle(), - new Symfony\Bundle\AsseticBundle\AsseticBundle(), - new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), - new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), - new Liip\FunctionalTestBundle\LiipFunctionalTestBundle(), - new Liip\FunctionalTestBundle\Tests\AcmeBundle(), + new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new \Symfony\Bundle\SecurityBundle\SecurityBundle(), + new \Symfony\Bundle\TwigBundle\TwigBundle(), + new \Symfony\Bundle\MonologBundle\MonologBundle(), + new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), + new \Liip\FunctionalTestBundle\LiipFunctionalTestBundle(), + new \Liip\FunctionalTestBundle\Tests\AcmeBundle(), + new \Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle(), + new \Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle(), ]; return $bundles; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(__DIR__.'/config.yml'); - // graciously stolen from https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Tests/Fixtures/App/AppKernel.php#L39-L45 - if ($this->isSymfony3()) { - $loader->load(function (ContainerBuilder $container) { - $container->loadFromExtension('framework', [ - 'assets' => null, - ]); - }); - } - } - - protected function isSymfony3() - { - return 3 === Kernel::MAJOR_VERSION; + $loader->load(function (ContainerBuilder $container): void { + $container->loadFromExtension('framework', [ + 'assets' => null, + ]); + }); } } diff --git a/tests/App/Controller/DefaultController.php b/tests/App/Controller/DefaultController.php index 50ae5b0d..1cbdc6fd 100644 --- a/tests/App/Controller/DefaultController.php +++ b/tests/App/Controller/DefaultController.php @@ -1,5 +1,7 @@ render( 'LiipFunctionalTestBundle::layout.html.twig' @@ -31,9 +35,9 @@ public function indexAction() /** * @param int $userId * - * @return \Symfony\Component\HttpFoundation\Response + * @return Response */ - public function userAction($userId) + public function userAction(int $userId): Response { /** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */ $user = $this->getDoctrine() @@ -55,22 +59,19 @@ public function userAction($userId) /** * @param Request $request * - * @return \Symfony\Component\HttpFoundation\Response + * @return Response */ - public function formAction(Request $request) + public function formAction(Request $request): Response { $object = new \ArrayObject(); $object->name = null; - $textType = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\TextType' : 'text'; - $submitType = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\SubmitType' : 'submit'; - $form = $this->createFormBuilder($object) - ->add('name', $textType, [ + ->add('name', TextType::class, [ /* @see http://symfony.com/doc/2.7/book/forms.html#adding-validation */ 'constraints' => new NotBlank(), ]) - ->add('Submit', $submitType) + ->add('Submit', SubmitType::class) ->getForm(); $form->handleRequest($request); @@ -90,9 +91,9 @@ public function formAction(Request $request) /** * Used to test a JSON content with corresponding Content-Type. * - * @return \Symfony\Component\HttpFoundation\Response + * @return Response */ - public function jsonAction() + public function jsonAction(): Response { $response = new Response(json_encode(['name' => 'John Doe'])); $response->headers->set('Content-Type', 'application/json'); diff --git a/tests/App/DataFixtures/ORM/LoadDependentUserData.php b/tests/App/DataFixtures/ORM/LoadDependentUserData.php index 611cfca8..98d64a84 100644 --- a/tests/App/DataFixtures/ORM/LoadDependentUserData.php +++ b/tests/App/DataFixtures/ORM/LoadDependentUserData.php @@ -1,5 +1,7 @@ container = $container; } @@ -34,7 +36,7 @@ public function setContainer(ContainerInterface $container = null) /** * {@inheritdoc} */ - public function load(ObjectManager $manager) + public function load(ObjectManager $manager): void { /** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */ $user = clone $this->getReference('user'); @@ -55,7 +57,7 @@ public function load(ObjectManager $manager) /** * {@inheritdoc} */ - public function getDependencies() + public function getDependencies(): array { return [ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', diff --git a/tests/App/DataFixtures/ORM/LoadUserData.php b/tests/App/DataFixtures/ORM/LoadUserData.php index e4e25e0f..79ee38c0 100644 --- a/tests/App/DataFixtures/ORM/LoadUserData.php +++ b/tests/App/DataFixtures/ORM/LoadUserData.php @@ -1,5 +1,7 @@ container = $container; } @@ -35,7 +37,7 @@ public function setContainer(ContainerInterface $container = null) /** * {@inheritdoc} */ - public function load(ObjectManager $manager) + public function load(ObjectManager $manager): void { /** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */ $user = new User(); diff --git a/tests/App/Entity/User.php b/tests/App/Entity/User.php index 876b83a7..fad26304 100644 --- a/tests/App/Entity/User.php +++ b/tests/App/Entity/User.php @@ -1,5 +1,7 @@ getName(); } - public function eraseCredentials() + public function eraseCredentials(): void { } diff --git a/tests/App/bootstrap.php b/tests/App/bootstrap.php index 693f0217..b6e2ee5f 100644 --- a/tests/App/bootstrap.php +++ b/tests/App/bootstrap.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + use Doctrine\Common\Annotations\AnnotationRegistry; $loader = require __DIR__.'/../../vendor/autoload.php'; diff --git a/tests/AppConfig/AppConfigKernel.php b/tests/AppConfig/AppConfigKernel.php index ef037e35..93fb6b32 100644 --- a/tests/AppConfig/AppConfigKernel.php +++ b/tests/AppConfig/AppConfigKernel.php @@ -1,5 +1,7 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +use Liip\FunctionalTestBundle\Tests\App\AppKernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppConfigKernel extends AppKernel { - public function registerBundles() - { - return array_merge( - parent::registerBundles(), - [ - new Hautelook\AliceBundle\HautelookAliceBundle(), - ] - ); - } - /** * Load the config.yml from the current directory. */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { // Load the default file. parent::registerContainerConfiguration($loader); diff --git a/tests/AppConfig/DataFixtures/Faker/Provider/FooProvider.php b/tests/AppConfig/DataFixtures/Faker/Provider/FooProvider.php index 1840ba70..5b26b293 100644 --- a/tests/AppConfig/DataFixtures/Faker/Provider/FooProvider.php +++ b/tests/AppConfig/DataFixtures/Faker/Provider/FooProvider.php @@ -1,13 +1,15 @@ -* -* This source file is subject to the MIT license that is bundled -* with this source code in the file LICENSE. -*/ + * This file is part of the Liip/FunctionalTestBundle + * + * (c) Lukas Kahwe Smith + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace Liip\FunctionalTestBundle\Tests\AppConfig\DataFixtures\Faker\Provider; diff --git a/tests/AppConfig/config.yml b/tests/AppConfig/config.yml index a5299399..43ff6043 100644 --- a/tests/AppConfig/config.yml +++ b/tests/AppConfig/config.yml @@ -23,4 +23,4 @@ liip_functional_test: services: faker.provider.foo: class: Liip\FunctionalTestBundle\Tests\AppConfig\DataFixtures\Faker\Provider\FooProvider - tags: [ { name: hautelook_alice.faker.provider } ] + tags: [ { name: nelmio_alice.faker.provider } ] diff --git a/tests/AppConfigLeanFramework/AppConfigLeanFrameworkKernel.php b/tests/AppConfigLeanFramework/AppConfigLeanFrameworkKernel.php index 2b7ca78e..065b7b54 100644 --- a/tests/AppConfigLeanFramework/AppConfigLeanFrameworkKernel.php +++ b/tests/AppConfigLeanFramework/AppConfigLeanFrameworkKernel.php @@ -1,5 +1,7 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +use Liip\FunctionalTestBundle\Tests\App\AppKernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppConfigLeanFrameworkKernel extends AppKernel @@ -20,7 +30,7 @@ class AppConfigLeanFrameworkKernel extends AppKernel /** * Load the config.yml from the current directory. */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { // Load the default file. parent::registerContainerConfiguration($loader); diff --git a/tests/AppConfigMysql/AppConfigMysqlKernel.php b/tests/AppConfigMysql/AppConfigMysqlKernel.php index 06409031..e2533b22 100644 --- a/tests/AppConfigMysql/AppConfigMysqlKernel.php +++ b/tests/AppConfigMysql/AppConfigMysqlKernel.php @@ -1,5 +1,7 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +use Liip\FunctionalTestBundle\Tests\App\AppKernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppConfigMysqlKernel extends AppKernel @@ -20,7 +30,7 @@ class AppConfigMysqlKernel extends AppKernel /** * Load the config.yml from the current directory. */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { // Load the default file. parent::registerContainerConfiguration($loader); diff --git a/tests/AppConfigPhpcr/AppConfigPhpcrKernel.php b/tests/AppConfigPhpcr/AppConfigPhpcrKernel.php index f1ecb827..4c2f6587 100644 --- a/tests/AppConfigPhpcr/AppConfigPhpcrKernel.php +++ b/tests/AppConfigPhpcr/AppConfigPhpcrKernel.php @@ -1,5 +1,7 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ +use Liip\FunctionalTestBundle\Tests\App\AppKernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppConfigPhpcrKernel extends AppKernel { - public function registerBundles() + public function registerBundles(): array { return array_merge( parent::registerBundles(), [ - new Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(), + new \Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(), ] ); } @@ -30,7 +40,7 @@ public function registerBundles() /** * Load the config.yml from the current directory. */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { // Load the default file. parent::registerContainerConfiguration($loader); diff --git a/tests/AppConfigPhpcr/DataFixtures/PHPCR/LoadTaskData.php b/tests/AppConfigPhpcr/DataFixtures/PHPCR/LoadTaskData.php index 7c2628e0..99ff231b 100644 --- a/tests/AppConfigPhpcr/DataFixtures/PHPCR/LoadTaskData.php +++ b/tests/AppConfigPhpcr/DataFixtures/PHPCR/LoadTaskData.php @@ -1,5 +1,7 @@ description = $description; } - public function setParentDocument($parentDocument) + public function setParentDocument($parentDocument): void { $this->parentDocument = $parentDocument; } diff --git a/tests/Command/CommandConfigTest.php b/tests/Command/CommandConfigTest.php index 68e9cdd2..a7436073 100644 --- a/tests/Command/CommandConfigTest.php +++ b/tests/Command/CommandConfigTest.php @@ -1,5 +1,7 @@ display = $this->runCommand('liipfunctionaltestbundle:test'); diff --git a/tests/Command/CommandTest.php b/tests/Command/CommandTest.php index 1432fb05..d86fc7bb 100644 --- a/tests/Command/CommandTest.php +++ b/tests/Command/CommandTest.php @@ -1,5 +1,7 @@ display = $this->runCommand('liipfunctionaltestbundle:test'); @@ -44,7 +46,7 @@ public function testRunCommandWithoutOptionsAndReuseKernel() $this->assertContains('Verbosity level: NORMAL', $this->display); } - public function testRunCommandWithoutOptionsAndNotReuseKernel() + public function testRunCommandWithoutOptionsAndNotReuseKernel(): void { // Run command without options $this->display = $this->runCommand('liipfunctionaltestbundle:test'); @@ -64,7 +66,7 @@ public function testRunCommandWithoutOptionsAndNotReuseKernel() $this->assertContains('Verbosity level: NORMAL', $this->display); } - public function testRunCommandWithoutDecoration() + public function testRunCommandWithoutDecoration(): void { // Set `decorated` to false $this->isDecorated(false); @@ -79,7 +81,7 @@ public function testRunCommandWithoutDecoration() $this->assertFalse($this->getDecorated()); } - public function testRunCommandVerbosityQuiet() + public function testRunCommandVerbosityQuiet(): void { $this->setVerbosityLevel('quiet'); $this->assertSame(OutputInterface::VERBOSITY_QUIET, $this->getVerbosityLevel()); @@ -99,7 +101,7 @@ public function testRunCommandVerbosityQuiet() $this->assertNotContains('Verbosity level: DEBUG', $this->display); } - public function testRunCommandVerbosityImplicitlyNormal() + public function testRunCommandVerbosityImplicitlyNormal(): void { // Run command without setting verbosity: default set is normal $this->assertSame(OutputInterface::VERBOSITY_NORMAL, $this->getVerbosityLevel()); @@ -120,7 +122,7 @@ public function testRunCommandVerbosityImplicitlyNormal() $this->assertNotContains('Verbosity level: DEBUG', $this->display); } - public function testRunCommandVerbosityExplicitlyNormal() + public function testRunCommandVerbosityExplicitlyNormal(): void { $this->setVerbosityLevel('normal'); $this->assertSame(OutputInterface::VERBOSITY_NORMAL, $this->getVerbosityLevel()); @@ -132,18 +134,13 @@ public function testRunCommandVerbosityExplicitlyNormal() $this->assertInternalType('string', $this->display); - // In this version of Symfony, NORMAL is practically equal to VERBOSE - if ('203' === substr(Kernel::VERSION_ID, 0, 3)) { - $this->assertContains('Verbosity level: VERBOSE', $this->display); - } else { - $this->assertNotContains('Verbosity level: VERBOSE', $this->display); - } + $this->assertNotContains('Verbosity level: VERBOSE', $this->display); $this->assertNotContains('Verbosity level: VERY_VERBOSE', $this->display); $this->assertNotContains('Verbosity level: DEBUG', $this->display); } - public function testRunCommandVerbosityVerbose() + public function testRunCommandVerbosityVerbose(): void { $this->setVerbosityLevel('verbose'); $this->assertSame(OutputInterface::VERBOSITY_VERBOSE, $this->getVerbosityLevel()); @@ -158,7 +155,7 @@ public function testRunCommandVerbosityVerbose() $this->assertNotContains('Verbosity level: DEBUG', $this->display); } - public function testRunCommandVerbosityVeryVerbose() + public function testRunCommandVerbosityVeryVerbose(): void { $this->setVerbosityLevel('very_verbose'); $this->assertSame(OutputInterface::VERBOSITY_VERY_VERBOSE, $this->getVerbosityLevel()); @@ -177,7 +174,7 @@ public function testRunCommandVerbosityVeryVerbose() $this->assertNotContains('Verbosity level: DEBUG', $this->display); } - public function testRunCommandVerbosityDebug() + public function testRunCommandVerbosityDebug(): void { $this->setVerbosityLevel('debug'); $this->assertSame(OutputInterface::VERBOSITY_DEBUG, $this->getVerbosityLevel()); @@ -199,14 +196,14 @@ public function testRunCommandVerbosityDebug() /** * @expectedException \OutOfBoundsException */ - public function testRunCommandVerbosityOutOfBound() + public function testRunCommandVerbosityOutOfBound(): void { $this->setVerbosityLevel('foobar'); $this->runCommand('command:test'); } - public function tearDown() + public function tearDown(): void { parent::tearDown(); diff --git a/tests/Command/ParatestCommandTest.php b/tests/Command/ParatestCommandTest.php index 8d3b175a..f4adfba0 100644 --- a/tests/Command/ParatestCommandTest.php +++ b/tests/Command/ParatestCommandTest.php @@ -1,5 +1,7 @@ getContainer()->get('kernel'); $application = new Application($kernel); diff --git a/tests/DependencyInjection/Compiler/SetTestClientPassMockTest.php b/tests/DependencyInjection/Compiler/SetTestClientPassMockTest.php index 16c964be..a43d2e30 100644 --- a/tests/DependencyInjection/Compiler/SetTestClientPassMockTest.php +++ b/tests/DependencyInjection/Compiler/SetTestClientPassMockTest.php @@ -1,5 +1,7 @@ container = $client->getContainer(); @@ -33,7 +35,7 @@ public function setUp() * @param string $node Array key from parametersProvider * @param string $value Array value from parametersProvider */ - public function testParameter($node, $value) + public function testParameter($node, $value): void { $name = 'liip_functional_test.'.$node; @@ -50,7 +52,7 @@ public function testParameter($node, $value) ); } - public function parametersProvider() + public function parametersProvider(): array { return [ ['cache_sqlite_db', false], diff --git a/tests/Test/WebTestCaseConfigLeanFrameworkTest.php b/tests/Test/WebTestCaseConfigLeanFrameworkTest.php index b6efedd9..2300bee2 100644 --- a/tests/Test/WebTestCaseConfigLeanFrameworkTest.php +++ b/tests/Test/WebTestCaseConfigLeanFrameworkTest.php @@ -1,5 +1,7 @@ assertStatusCode(200, $client); } - public function testAssertValidationErrorsTriggersError() + public function testAssertValidationErrorsTriggersError(): void { $client = static::makeClient(); diff --git a/tests/Test/WebTestCaseConfigMysqlTest.php b/tests/Test/WebTestCaseConfigMysqlTest.php index de520a05..74cb0c21 100644 --- a/tests/Test/WebTestCaseConfigMysqlTest.php +++ b/tests/Test/WebTestCaseConfigMysqlTest.php @@ -1,5 +1,7 @@ getContainer()->get('doctrine')->getManager(); @@ -59,7 +60,7 @@ public function setUp() * * @group mysql */ - public function testLoadEmptyFixtures() + public function testLoadEmptyFixtures(): void { $fixtures = $this->loadFixtures([]); @@ -72,7 +73,7 @@ public function testLoadEmptyFixtures() /** * @group mysql */ - public function testLoadFixtures() + public function testLoadFixtures(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', @@ -125,7 +126,7 @@ public function testLoadFixtures() * * @group mysql */ - public function testLoadFixturesAndExcludeFromPurge() + public function testLoadFixturesAndExcludeFromPurge(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', @@ -165,7 +166,7 @@ public function testLoadFixturesAndExcludeFromPurge() * * @group mysql */ - public function testLoadFixturesAndPurge() + public function testLoadFixturesAndPurge(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', @@ -224,7 +225,7 @@ public function testLoadFixturesAndPurge() * * @group mysql */ - public function testLoadFixturesFiles() + public function testLoadFixturesFiles(): void { $fixtures = $this->loadFixtureFiles([ '@AcmeBundle/App/DataFixtures/ORM/user.yml', diff --git a/tests/Test/WebTestCaseConfigPhpcrTest.php b/tests/Test/WebTestCaseConfigPhpcrTest.php index 190ca1ec..290b5eba 100644 --- a/tests/Test/WebTestCaseConfigPhpcrTest.php +++ b/tests/Test/WebTestCaseConfigPhpcrTest.php @@ -1,5 +1,7 @@ markTestSkipped('Need doctrine/phpcr-bundle package.'); + } + // https://github.com/liip/LiipFunctionalTestBundle#non-sqlite $em = $this->getContainer()->get('doctrine')->getManager(); if (!isset($metadatas)) { @@ -50,7 +56,7 @@ public function setUp() $this->runCommand('doctrine:phpcr:repository:init'); } - public function testLoadFixturesPhPCr() + public function testLoadFixturesPhPCr(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\AppConfigPhpcr\DataFixtures\PHPCR\LoadTaskData', diff --git a/tests/Test/WebTestCaseConfigTest.php b/tests/Test/WebTestCaseConfigTest.php index d69d5b43..6001a297 100644 --- a/tests/Test/WebTestCaseConfigTest.php +++ b/tests/Test/WebTestCaseConfigTest.php @@ -1,5 +1,7 @@ loadFixtures([]); @@ -78,7 +79,7 @@ public function testIndexAuthenticationArray() * "liip_functional_test.authentication" * node from the configuration file. */ - public function testIndexAuthenticationTrue() + public function testIndexAuthenticationTrue(): void { $this->loadFixtures([]); @@ -107,7 +108,7 @@ public function testIndexAuthenticationTrue() /** * Log in as the user defined in the Data Fixture. */ - public function testIndexAuthenticationLoginAs() + public function testIndexAuthenticationLoginAs(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', @@ -155,7 +156,7 @@ public function testIndexAuthenticationLoginAs() * * @expectedException \Liip\FunctionalTestBundle\Exception\AllowedQueriesExceededException */ - public function testAllowedQueriesExceededException() + public function testAllowedQueriesExceededException(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', @@ -186,7 +187,7 @@ public function testAllowedQueriesExceededException() * * @expectedException \Liip\FunctionalTestBundle\Exception\AllowedQueriesExceededException */ - public function testAnnotationAndException() + public function testAnnotationAndException(): void { $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', @@ -201,93 +202,10 @@ public function testAnnotationAndException() } /** - * Test if there is a call-out to the service if defined. - */ - public function testHautelookServiceUsage() - { - $hautelookLoaderMock = $this->getMockBuilder('\Hautelook\AliceBundle\Alice\DataFixtures\Loader') - ->disableOriginalConstructor() - ->setMethods(['load']) - ->getMock(); - $hautelookLoaderMock->expects(self::once())->method('load'); - - $this->getContainer()->set('hautelook_alice.fixtures.loader', $hautelookLoaderMock); - - $this->loadFixtureFiles([ - '@AcmeBundle/App/DataFixtures/ORM/user.yml', - ]); - } - - /** - * Use hautelook. - */ - public function testLoadFixturesFilesWithHautelook() - { - if (!class_exists('Hautelook\AliceBundle\Faker\Provider\ProviderChain')) { - self::markTestSkipped('Please use hautelook/alice-bundle >=1.2'); - } - - $fakerProcessorChain = new \Hautelook\AliceBundle\Faker\Provider\ProviderChain([]); - $aliceProcessorChain = new \Hautelook\AliceBundle\Alice\ProcessorChain([]); - $fixtureLoader = new \Hautelook\AliceBundle\Alice\DataFixtures\Fixtures\Loader('en_US', $fakerProcessorChain); - $loader = new \Hautelook\AliceBundle\Alice\DataFixtures\Loader($fixtureLoader, $aliceProcessorChain, true, 10); - $this->getContainer()->set('hautelook_alice.fixtures.loader', $loader); - - $fixtures = $this->loadFixtureFiles([ - '@AcmeBundle/App/DataFixtures/ORM/user.yml', - ]); - - $this->assertInternalType( - 'array', - $fixtures - ); - - // 10 users are loaded - $this->assertCount( - 10, - $fixtures - ); - - $em = $this->getContainer() - ->get('doctrine.orm.entity_manager'); - - $users = $em->getRepository('LiipFunctionalTestBundle:User') - ->findAll(); - - $this->assertSame( - 10, - count($users) - ); - - /** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */ - $user = $em->getRepository('LiipFunctionalTestBundle:User') - ->findOneBy([ - 'id' => 1, - ]); - - $this->assertTrue( - $user->getEnabled() - ); - - $user = $em->getRepository('LiipFunctionalTestBundle:User') - ->findOneBy([ - 'id' => 10, - ]); - - $this->assertTrue( - $user->getEnabled() - ); - } - - /** - * Load Data Fixtures with hautelook and custom loader defined in configuration. + * Load Data Fixtures with custom loader defined in configuration. */ - public function testLoadFixturesFilesWithHautelookCustomProvider() + public function testLoadFixturesFilesWithCustomProvider(): void { - if (!class_exists('Hautelook\AliceBundle\Faker\Provider\ProviderChain')) { - self::markTestSkipped('Please use hautelook/alice-bundle >=1.2'); - } - // Load default Data Fixtures. $fixtures = $this->loadFixtureFiles([ '@AcmeBundle/App/DataFixtures/ORM/user.yml', @@ -331,7 +249,7 @@ public function testLoadFixturesFilesWithHautelookCustomProvider() /** * Update a fixture file and check that the cache will be refreshed. */ - public function testBackupIsRefreshed() + public function testBackupIsRefreshed(): void { // This value is generated in loadFixtures(). $md5 = '0ded9d8daaeaeca1056b18b9d0d433b2'; diff --git a/tests/Test/WebTestCaseTest.php b/tests/Test/WebTestCaseTest.php index b3eda813..5ddad129 100644 --- a/tests/Test/WebTestCaseTest.php +++ b/tests/Test/WebTestCaseTest.php @@ -1,5 +1,7 @@ client = static::makeClient(); } @@ -33,7 +30,7 @@ public function setUp() /** * Call methods from the parent class. */ - public function testGetContainer() + public function testGetContainer(): void { $this->assertInstanceOf( 'Symfony\Component\DependencyInjection\ContainerInterface', @@ -41,7 +38,7 @@ public function testGetContainer() ); } - public function testMakeClient() + public function testMakeClient(): void { $this->assertInstanceOf( 'Symfony\Bundle\FrameworkBundle\Client', @@ -49,7 +46,7 @@ public function testMakeClient() ); } - public function testGetUrl() + public function testGetUrl(): void { $path = $this->getUrl( 'liipfunctionaltestbundle_user', @@ -67,7 +64,7 @@ public function testGetUrl() /** * Call methods from Symfony to ensure the Controller works. */ - public function testIndex() + public function testIndex(): void { $path = '/'; @@ -95,7 +92,7 @@ public function testIndex() /** * @depends testIndex */ - public function testIndexAssertStatusCode() + public function testIndexAssertStatusCode(): void { $this->loadFixtures([]); @@ -109,12 +106,8 @@ public function testIndexAssertStatusCode() /** * Check the failure message returned by assertStatusCode(). */ - public function testAssertStatusCodeFail() + public function testAssertStatusCodeFail(): void { - if (!interface_exists('Symfony\Component\Validator\Validator\ValidatorInterface')) { - $this->markTestSkipped('The Symfony\Component\Validator\Validator\ValidatorInterface does not exist'); - } - $this->loadFixtures([]); $path = '/'; @@ -143,7 +136,7 @@ public function testAssertStatusCodeFail() /** * Check the failure message returned by assertStatusCode(). */ - public function testAssertStatusCodeException() + public function testAssertStatusCodeException(): void { $this->loadFixtures([]); @@ -169,7 +162,7 @@ public function testAssertStatusCodeException() /** * @depends testIndex */ - public function testIndexIsSuccesful() + public function testIndexIsSuccesful(): void { $this->loadFixtures([]); @@ -183,7 +176,7 @@ public function testIndexIsSuccesful() /** * @depends testIndex */ - public function testIndexFetchCrawler() + public function testIndexFetchCrawler(): void { $this->loadFixtures([]); @@ -213,7 +206,7 @@ public function testIndexFetchCrawler() /** * @depends testIndex */ - public function testIndexFetchContent() + public function testIndexFetchContent(): void { $this->loadFixtures([]); @@ -229,7 +222,7 @@ public function testIndexFetchContent() ); } - public function test404Error() + public function test404Error(): void { $this->loadFixtures([]); @@ -246,7 +239,7 @@ public function test404Error() * Throw an Exception in the try/catch block and check the failure message * returned by assertStatusCode(). */ - public function testIsSuccessfulException() + public function testIsSuccessfulException(): void { $this->loadFixtures([]); @@ -277,7 +270,7 @@ public function testIsSuccessfulException() /** * Data fixtures. */ - public function testLoadEmptyFixtures() + public function testLoadEmptyFixtures(): void { $fixtures = $this->loadFixtures([]); @@ -287,7 +280,7 @@ public function testLoadEmptyFixtures() ); } - public function testLoadFixturesWithoutParameters() + public function testLoadFixturesWithoutParameters(): void { $fixtures = $this->loadFixtures(); @@ -297,7 +290,7 @@ public function testLoadFixturesWithoutParameters() ); } - public function testLoadFixtures() + public function testLoadFixtures(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', @@ -355,7 +348,7 @@ public function testLoadFixtures() /** * Load fixture which has a dependency. */ - public function testLoadDependentFixtures() + public function testLoadDependentFixtures(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadDependentUserData', @@ -382,7 +375,7 @@ public function testLoadDependentFixtures() /** * Use nelmio/alice. */ - public function testLoadFixturesFiles() + public function testLoadFixturesFiles(): void { $fixtures = $this->loadFixtureFiles([ '@AcmeBundle/App/DataFixtures/ORM/user.yml', @@ -435,7 +428,7 @@ public function testLoadFixturesFiles() * * @expectedException \InvalidArgumentException */ - public function testLoadNonexistentFixturesFiles() + public function testLoadNonexistentFixturesFiles(): void { $this->loadFixtureFiles([ '@AcmeBundle/App/DataFixtures/ORM/nonexistent.yml', @@ -447,7 +440,7 @@ public function testLoadNonexistentFixturesFiles() * * @depends testLoadFixturesFiles */ - public function testLoadFixturesFilesWithPurgeModeTruncate() + public function testLoadFixturesFilesWithPurgeModeTruncate(): void { $fixtures = $this->loadFixtureFiles([ '@AcmeBundle/App/DataFixtures/ORM/user.yml', @@ -474,7 +467,7 @@ public function testLoadFixturesFilesWithPurgeModeTruncate() /** * Use nelmio/alice with full path to the file. */ - public function testLoadFixturesFilesPaths() + public function testLoadFixturesFilesPaths(): void { $fixtures = $this->loadFixtureFiles([ $this->client->getContainer()->get('kernel')->locateResource( @@ -524,7 +517,7 @@ public function testLoadFixturesFilesPaths() /** * Use nelmio/alice with full path to the file without calling locateResource(). */ - public function testLoadFixturesFilesPathsWithoutLocateResource() + public function testLoadFixturesFilesPathsWithoutLocateResource(): void { $fixtures = $this->loadFixtureFiles([ __DIR__.'/../App/DataFixtures/ORM/user.yml', @@ -558,13 +551,13 @@ public function testLoadFixturesFilesPathsWithoutLocateResource() * * @expectedException \InvalidArgumentException */ - public function testLoadNonexistentFixturesFilesPaths() + public function testLoadNonexistentFixturesFilesPaths(): void { $path = ['/nonexistent.yml']; $this->loadFixtureFiles($path); } - public function testUserWithFixtures() + public function testUserWithFixtures(): void { $fixtures = $this->loadFixtures([ 'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', @@ -620,12 +613,8 @@ public function testUserWithFixtures() /** * Form. */ - public function testForm() + public function testForm(): void { - if (!interface_exists('Symfony\Component\Validator\Validator\ValidatorInterface')) { - $this->markTestSkipped('The Symfony\Component\Validator\Validator\ValidatorInterface does not exist'); - } - $this->loadFixtures([]); $path = '/form'; @@ -659,12 +648,8 @@ public function testForm() * * @expectedException \PHPUnit\Framework\ExpectationFailedException */ - public function testFormWithException() + public function testFormWithException(): void { - if (!interface_exists('Symfony\Component\Validator\Validator\ValidatorInterface')) { - $this->markTestSkipped('The Symfony\Component\Validator\Validator\ValidatorInterface does not exist'); - } - $this->loadFixtures([]); $path = '/form'; @@ -685,12 +670,8 @@ public function testFormWithException() * Check the failure message returned by assertStatusCode() * when an invalid form is submitted. */ - public function testFormWithExceptionAssertStatusCode() + public function testFormWithExceptionAssertStatusCode(): void { - if (!interface_exists('Symfony\Component\Validator\Validator\ValidatorInterface')) { - $this->markTestSkipped('The Symfony\Component\Validator\Validator\ValidatorInterface does not exist'); - } - $this->loadFixtures([]); $path = '/form'; @@ -721,7 +702,7 @@ public function testFormWithExceptionAssertStatusCode() /** * Call isSuccessful() with "application/json" content type. */ - public function testJsonIsSuccesful() + public function testJsonIsSuccesful(): void { $this->loadFixtures([]); @@ -738,7 +719,7 @@ public function testJsonIsSuccesful() ); } - public function tearDown() + public function tearDown(): void { parent::tearDown();