Skip to content

Commit 70abb83

Browse files
authored
Remove Symfony 3.4 Support (#105)
1 parent fe90bca commit 70abb83

File tree

3 files changed

+31
-106
lines changed

3 files changed

+31
-106
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
php: [7.3, 7.4, 8.0]
12-
symfony: [3.4, 4.4, 5.2]
12+
symfony: [4.4, 5.2]
1313

1414
steps:
1515
- name: Checkout code
@@ -23,14 +23,6 @@ jobs:
2323
extensions: ctype, iconv, intl, json, mbstring, pdo, pdo_sqlite
2424
coverage: none
2525

26-
- name: Checkout Symfony 3.4 Sample
27-
if: matrix.symfony == 3.4
28-
uses: actions/checkout@v2
29-
with:
30-
repository: Codeception/symfony-module-tests
31-
path: framework-tests
32-
ref: 3.4
33-
3426
- name: Checkout Symfony 4.4 Sample
3527
if: matrix.symfony == 4.4
3628
uses: actions/checkout@v2

src/Codeception/Lib/Connector/Symfony.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@
1111
use Symfony\Component\HttpKernel\HttpKernelBrowser;
1212
use Symfony\Component\HttpKernel\Kernel;
1313
use function array_keys;
14-
use function class_alias;
1514
use function codecept_debug;
1615

17-
if (Kernel::VERSION_ID < 40300) {
18-
class_alias('Symfony\Component\HttpKernel\Client', 'Symfony\Component\HttpKernel\HttpKernelBrowser');
19-
}
20-
2116
class Symfony extends HttpKernelBrowser
2217
{
2318
/**

src/Codeception/Module/Symfony.php

Lines changed: 30 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
namespace Codeception\Module;
66

77
use BadMethodCallException;
8-
use Codeception\Configuration;
9-
use Codeception\Exception\ModuleException;
108
use Codeception\Exception\ModuleRequireException;
119
use Codeception\Lib\Connector\Symfony as SymfonyConnector;
1210
use Codeception\Lib\Framework;
@@ -53,8 +51,8 @@
5351
use function ini_get;
5452
use function ini_set;
5553
use function is_null;
56-
use function is_string;
5754
use function iterator_to_array;
55+
use function number_format;
5856
use function sprintf;
5957

6058
/**
@@ -66,15 +64,15 @@
6664
*
6765
* ## Config
6866
*
69-
* ### Symfony 5.x or 4.x
67+
* ### Symfony 5.x or 4.4
7068
*
71-
* * app_path: 'src' - in Symfony 4 Kernel is located inside `src`
72-
* * environment: 'local' - environment used for load kernel
73-
* * kernel_class: 'App\Kernel' - kernel class name
74-
* * em_service: 'doctrine.orm.entity_manager' - use the stated EntityManager to pair with Doctrine Module.
75-
* * debug: true - turn on/off debug mode
76-
* * 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)
77-
* * rebootable_client: 'true' - reboot client's kernel before each request
69+
* * app_path: 'src' - Specify custom path to your app dir, where the kernel interface is located.
70+
* * environment: 'local' - Environment used for load kernel
71+
* * kernel_class: 'App\Kernel' - Kernel class name
72+
* * em_service: 'doctrine.orm.entity_manager' - Use the stated EntityManager to pair with Doctrine Module.
73+
* * debug: true - Turn on/off debug mode
74+
* * 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)
75+
* * rebootable_client: 'true' - Reboot client's kernel before each request
7876
*
7977
* #### Example (`functional.suite.yml`) - Symfony 4 Directory Structure
8078
*
@@ -85,27 +83,6 @@
8583
* environment: 'test'
8684
*
8785
*
88-
* ### Symfony 3.x
89-
*
90-
* * app_path: 'app' - specify custom path to your app dir, where the kernel interface is located.
91-
* * var_path: 'var' - specify custom path to your var dir, where bootstrap cache is located.
92-
* * environment: 'local' - environment used for load kernel
93-
* * kernel_class: 'AppKernel' - kernel class name
94-
* * em_service: 'doctrine.orm.entity_manager' - use the stated EntityManager to pair with Doctrine Module.
95-
* * debug: true - turn on/off debug mode
96-
* * 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)
97-
* * rebootable_client: 'true' - reboot client's kernel before each request
98-
*
99-
* #### Example (`functional.suite.yml`) - Symfony 3 Directory Structure
100-
*
101-
* modules:
102-
* enabled:
103-
* - Symfony:
104-
* app_path: 'app/front'
105-
* var_path: 'var'
106-
* environment: 'local_test'
107-
*
108-
*
10986
* ## Public Properties
11087
*
11188
* * kernel - HttpKernel instance
@@ -158,20 +135,14 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule
158135
TwigAssertionsTrait
159136
;
160137

161-
private static $possibleKernelClasses = [
162-
'AppKernel', // Symfony Standard
163-
'App\Kernel', // Symfony Flex
164-
];
165-
166138
/**
167139
* @var Kernel
168140
*/
169141
public $kernel;
170142

171143
public $config = [
172144
'app_path' => 'app',
173-
'var_path' => 'app',
174-
'kernel_class' => null,
145+
'kernel_class' => 'App\Kernel',
175146
'environment' => 'test',
176147
'debug' => true,
177148
'cache_router' => false,
@@ -209,7 +180,6 @@ public function _parts(): array
209180

210181
public function _initialize(): void
211182
{
212-
$this->initializeSymfonyCache();
213183
$this->kernelClass = $this->getKernelClass();
214184
$maxNestingLevel = 200; // Symfony may have very long nesting level
215185
$xdebugMaxLevelKey = 'xdebug.max_nesting_level';
@@ -225,18 +195,6 @@ public function _initialize(): void
225195
}
226196
}
227197

228-
/**
229-
* Require Symfony's bootstrap.php.cache
230-
*/
231-
private function initializeSymfonyCache(): void
232-
{
233-
$cache = Configuration::projectDir() . $this->config['var_path'] . DIRECTORY_SEPARATOR . 'bootstrap.php.cache';
234-
235-
if (file_exists($cache)) {
236-
require_once $cache;
237-
}
238-
}
239-
240198
/**
241199
* Initialize new client instance before each test
242200
*
@@ -263,7 +221,6 @@ public function _after(TestInterface $test): void
263221

264222
protected function onReconfigure($settings = []): void
265223
{
266-
267224
parent::_beforeSuite($settings);
268225
$this->_initialize();
269226
}
@@ -297,24 +254,27 @@ public function _getEntityManager()
297254

298255
/**
299256
* Return container.
300-
*
301-
* @return ContainerInterface|mixed
302257
*/
303258
public function _getContainer(): ContainerInterface
304259
{
305-
$container = $this->kernel->getContainer();
306-
307-
if (!($container instanceof ContainerInterface)) {
308-
$this->fail('Could not get Symfony container');
260+
$testContainer = $this->getTestContainer();
261+
if ($testContainer instanceof ContainerInterface) {
262+
return $testContainer;
309263
}
310264

311-
if ($container->has('test.service_container')) {
312-
return $container->get('test.service_container');
265+
$container = $this->kernel->getContainer();
266+
if (!$container instanceof ContainerInterface) {
267+
$this->fail('Could not get Symfony container');
313268
}
314-
315269
return $container;
316270
}
317271

272+
protected function getTestContainer(): ?object
273+
{
274+
$container = $this->kernel->getContainer();
275+
return $container->get('test.service_container');
276+
}
277+
318278
/**
319279
* Attempts to guess the kernel location.
320280
*
@@ -355,20 +315,20 @@ protected function getKernelClass(): string
355315
return $file->getRealPath();
356316
}, $results);
357317

358-
$possibleKernelClasses = $this->getPossibleKernelClasses();
318+
$kernelClass = $this->config['kernel_class'];
359319

360-
foreach ($possibleKernelClasses as $class) {
361-
if (class_exists($class)) {
362-
$refClass = new ReflectionClass($class);
363-
if ($file = array_search($refClass->getFileName(), $filesRealPath)) {
364-
return $class;
365-
}
320+
if (class_exists($kernelClass)) {
321+
$reflectionClass = new ReflectionClass($kernelClass);
322+
if ($file = array_search($reflectionClass->getFileName(), $filesRealPath)) {
323+
return $kernelClass;
366324
}
325+
326+
throw new ModuleRequireException(self::class, "Kernel class was not found in {$file}.");
367327
}
368328

369329
throw new ModuleRequireException(
370330
self::class,
371-
"Kernel class was not found in $file. "
331+
"Kernel class was not found.\n"
372332
. 'Specify directory where file with Kernel class for your application is located with `app_path` parameter.'
373333
);
374334
}
@@ -491,26 +451,4 @@ protected function getInternalDomains(): array
491451

492452
return array_unique($internalDomains);
493453
}
494-
495-
/**
496-
* Returns list of the possible kernel classes based on the module configuration
497-
*
498-
* @return array
499-
* @throws ModuleException
500-
*/
501-
private function getPossibleKernelClasses(): array
502-
{
503-
if (empty($this->config['kernel_class'])) {
504-
return self::$possibleKernelClasses;
505-
}
506-
507-
if (!is_string($this->config['kernel_class'])) {
508-
throw new ModuleException(
509-
self::class,
510-
"Parameter 'kernel_class' must have 'string' type.\n"
511-
);
512-
}
513-
514-
return [$this->config['kernel_class']];
515-
}
516454
}

0 commit comments

Comments
 (0)