From 9eee1611710d0a55715ba32e2021c91dbef83574 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Mon, 25 Jan 2021 10:08:24 -0500 Subject: [PATCH] Remove Symfony 3.4 Support --- .github/workflows/main.yml | 10 +- src/Codeception/Lib/Connector/Symfony.php | 5 - src/Codeception/Module/Symfony.php | 122 ++++++---------------- 3 files changed, 31 insertions(+), 106 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f9df29cf..da8b8d71 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: php: [7.3, 7.4, 8.0] - symfony: [3.4, 4.4, 5.2] + symfony: [4.4, 5.2] steps: - name: Checkout code @@ -23,14 +23,6 @@ jobs: extensions: ctype, iconv, intl, json, mbstring, pdo, pdo_sqlite coverage: none - - name: Checkout Symfony 3.4 Sample - if: matrix.symfony == 3.4 - uses: actions/checkout@v2 - with: - repository: Codeception/symfony-module-tests - path: framework-tests - ref: 3.4 - - name: Checkout Symfony 4.4 Sample if: matrix.symfony == 4.4 uses: actions/checkout@v2 diff --git a/src/Codeception/Lib/Connector/Symfony.php b/src/Codeception/Lib/Connector/Symfony.php index cc928feb..af6f3334 100644 --- a/src/Codeception/Lib/Connector/Symfony.php +++ b/src/Codeception/Lib/Connector/Symfony.php @@ -11,13 +11,8 @@ use Symfony\Component\HttpKernel\HttpKernelBrowser; use Symfony\Component\HttpKernel\Kernel; use function array_keys; -use function class_alias; use function codecept_debug; -if (Kernel::VERSION_ID < 40300) { - class_alias('Symfony\Component\HttpKernel\Client', 'Symfony\Component\HttpKernel\HttpKernelBrowser'); -} - class Symfony extends HttpKernelBrowser { /** diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 2b96f4dd..f1327e22 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -5,8 +5,6 @@ namespace Codeception\Module; use BadMethodCallException; -use Codeception\Configuration; -use Codeception\Exception\ModuleException; use Codeception\Exception\ModuleRequireException; use Codeception\Lib\Connector\Symfony as SymfonyConnector; use Codeception\Lib\Framework; @@ -53,8 +51,8 @@ use function ini_get; use function ini_set; use function is_null; -use function is_string; use function iterator_to_array; +use function number_format; use function sprintf; /** @@ -66,15 +64,15 @@ * * ## Config * - * ### Symfony 5.x or 4.x + * ### Symfony 5.x or 4.4 * - * * app_path: 'src' - in Symfony 4 Kernel is located inside `src` - * * environment: 'local' - environment used for load kernel - * * kernel_class: 'App\Kernel' - kernel class name - * * em_service: 'doctrine.orm.entity_manager' - use the stated EntityManager to pair with Doctrine Module. - * * debug: true - turn on/off debug mode - * * cache_router: 'false' - enable router caching between tests in order to [increase performance](http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire) - * * rebootable_client: 'true' - reboot client's kernel before each request + * * app_path: 'src' - Specify custom path to your app dir, where the kernel interface is located. + * * environment: 'local' - Environment used for load kernel + * * kernel_class: 'App\Kernel' - Kernel class name + * * em_service: 'doctrine.orm.entity_manager' - Use the stated EntityManager to pair with Doctrine Module. + * * debug: true - Turn on/off debug mode + * * cache_router: 'false' - Enable router caching between tests in order to [increase performance](http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire) + * * rebootable_client: 'true' - Reboot client's kernel before each request * * #### Example (`functional.suite.yml`) - Symfony 4 Directory Structure * @@ -85,27 +83,6 @@ * environment: 'test' * * - * ### Symfony 3.x - * - * * app_path: 'app' - specify custom path to your app dir, where the kernel interface is located. - * * var_path: 'var' - specify custom path to your var dir, where bootstrap cache is located. - * * environment: 'local' - environment used for load kernel - * * kernel_class: 'AppKernel' - kernel class name - * * em_service: 'doctrine.orm.entity_manager' - use the stated EntityManager to pair with Doctrine Module. - * * debug: true - turn on/off debug mode - * * cache_router: 'false' - enable router caching between tests in order to [increase performance](http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire) - * * rebootable_client: 'true' - reboot client's kernel before each request - * - * #### Example (`functional.suite.yml`) - Symfony 3 Directory Structure - * - * modules: - * enabled: - * - Symfony: - * app_path: 'app/front' - * var_path: 'var' - * environment: 'local_test' - * - * * ## Public Properties * * * kernel - HttpKernel instance @@ -158,11 +135,6 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule TwigAssertionsTrait ; - private static $possibleKernelClasses = [ - 'AppKernel', // Symfony Standard - 'App\Kernel', // Symfony Flex - ]; - /** * @var Kernel */ @@ -170,8 +142,7 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule public $config = [ 'app_path' => 'app', - 'var_path' => 'app', - 'kernel_class' => null, + 'kernel_class' => 'App\Kernel', 'environment' => 'test', 'debug' => true, 'cache_router' => false, @@ -209,7 +180,6 @@ public function _parts(): array public function _initialize(): void { - $this->initializeSymfonyCache(); $this->kernelClass = $this->getKernelClass(); $maxNestingLevel = 200; // Symfony may have very long nesting level $xdebugMaxLevelKey = 'xdebug.max_nesting_level'; @@ -225,18 +195,6 @@ public function _initialize(): void } } - /** - * Require Symfony's bootstrap.php.cache - */ - private function initializeSymfonyCache(): void - { - $cache = Configuration::projectDir() . $this->config['var_path'] . DIRECTORY_SEPARATOR . 'bootstrap.php.cache'; - - if (file_exists($cache)) { - require_once $cache; - } - } - /** * Initialize new client instance before each test * @@ -263,7 +221,6 @@ public function _after(TestInterface $test): void protected function onReconfigure($settings = []): void { - parent::_beforeSuite($settings); $this->_initialize(); } @@ -297,24 +254,27 @@ public function _getEntityManager() /** * Return container. - * - * @return ContainerInterface|mixed */ public function _getContainer(): ContainerInterface { - $container = $this->kernel->getContainer(); - - if (!($container instanceof ContainerInterface)) { - $this->fail('Could not get Symfony container'); + $testContainer = $this->getTestContainer(); + if ($testContainer instanceof ContainerInterface) { + return $testContainer; } - if ($container->has('test.service_container')) { - return $container->get('test.service_container'); + $container = $this->kernel->getContainer(); + if (!$container instanceof ContainerInterface) { + $this->fail('Could not get Symfony container'); } - return $container; } + protected function getTestContainer(): ?object + { + $container = $this->kernel->getContainer(); + return $container->get('test.service_container'); + } + /** * Attempts to guess the kernel location. * @@ -355,20 +315,20 @@ protected function getKernelClass(): string return $file->getRealPath(); }, $results); - $possibleKernelClasses = $this->getPossibleKernelClasses(); + $kernelClass = $this->config['kernel_class']; - foreach ($possibleKernelClasses as $class) { - if (class_exists($class)) { - $refClass = new ReflectionClass($class); - if ($file = array_search($refClass->getFileName(), $filesRealPath)) { - return $class; - } + if (class_exists($kernelClass)) { + $reflectionClass = new ReflectionClass($kernelClass); + if ($file = array_search($reflectionClass->getFileName(), $filesRealPath)) { + return $kernelClass; } + + throw new ModuleRequireException(self::class, "Kernel class was not found in {$file}."); } throw new ModuleRequireException( self::class, - "Kernel class was not found in $file. " + "Kernel class was not found.\n" . 'Specify directory where file with Kernel class for your application is located with `app_path` parameter.' ); } @@ -491,26 +451,4 @@ protected function getInternalDomains(): array return array_unique($internalDomains); } - - /** - * Returns list of the possible kernel classes based on the module configuration - * - * @return array - * @throws ModuleException - */ - private function getPossibleKernelClasses(): array - { - if (empty($this->config['kernel_class'])) { - return self::$possibleKernelClasses; - } - - if (!is_string($this->config['kernel_class'])) { - throw new ModuleException( - self::class, - "Parameter 'kernel_class' must have 'string' type.\n" - ); - } - - return [$this->config['kernel_class']]; - } }