Skip to content

Remove Symfony 3.4 Support #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/Codeception/Lib/Connector/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
122 changes: 30 additions & 92 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand All @@ -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
*
Expand All @@ -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
Expand Down Expand Up @@ -158,20 +135,14 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule
TwigAssertionsTrait
;

private static $possibleKernelClasses = [
'AppKernel', // Symfony Standard
'App\Kernel', // Symfony Flex
];

/**
* @var Kernel
*/
public $kernel;

public $config = [
'app_path' => 'app',
'var_path' => 'app',
'kernel_class' => null,
'kernel_class' => 'App\Kernel',
'environment' => 'test',
'debug' => true,
'cache_router' => false,
Expand Down Expand Up @@ -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';
Expand All @@ -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
*
Expand All @@ -263,7 +221,6 @@ public function _after(TestInterface $test): void

protected function onReconfigure($settings = []): void
{

parent::_beforeSuite($settings);
$this->_initialize();
}
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.'
);
}
Expand Down Expand Up @@ -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']];
}
}