Skip to content

Commit 2ec9ff6

Browse files
omnilightDavertMik
authored andcommitted
Added support for custom kernel names for Symfony (#4949)
1 parent 79f3963 commit 2ec9ff6

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
2+
23
namespace Codeception\Module;
34

45
use Codeception\Configuration;
6+
use Codeception\Exception\ModuleException;
57
use Codeception\Lib\Framework;
68
use Codeception\Exception\ModuleRequireException;
79
use Codeception\Lib\Connector\Symfony as SymfonyConnector;
@@ -25,6 +27,7 @@
2527
*
2628
* * app_path: 'src' - in Symfony 4 Kernel is located inside `src`
2729
* * environment: 'local' - environment used for load kernel
30+
* * kernel_class: 'App\Kernel' - kernel class name
2831
* * em_service: 'doctrine.orm.entity_manager' - use the stated EntityManager to pair with Doctrine Module.
2932
* * debug: true - turn on/off debug mode
3033
* * 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)
@@ -44,6 +47,7 @@
4447
* * app_path: 'app' - specify custom path to your app dir, where the kernel interface is located.
4548
* * var_path: 'var' - specify custom path to your var dir, where bootstrap cache is located.
4649
* * environment: 'local' - environment used for load kernel
50+
* * kernel_class: 'AppKernel' - kernel class name
4751
* * em_service: 'doctrine.orm.entity_manager' - use the stated EntityManager to pair with Doctrine Module.
4852
* * debug: true - turn on/off debug mode
4953
* * 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)
@@ -63,6 +67,7 @@
6367
*
6468
* * app_path: 'app' - specify custom path to your app dir, where bootstrap cache and kernel interface is located.
6569
* * environment: 'local' - environment used for load kernel
70+
* * kernel_class: 'AppKernel' - kernel class name
6671
* * debug: true - turn on/off debug mode
6772
* * em_service: 'doctrine.orm.entity_manager' - use the stated EntityManager to pair with Doctrine Module.
6873
* * 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)
@@ -104,6 +109,11 @@
104109
*/
105110
class Symfony extends Framework implements DoctrineProvider, PartedModule
106111
{
112+
private static $possibleKernelClasses = [
113+
'AppKernel', // Symfony Standard
114+
'App\Kernel', // Symfony Flex
115+
];
116+
107117
/**
108118
* @var \Symfony\Component\HttpKernel\Kernel
109119
*/
@@ -112,6 +122,7 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule
112122
public $config = [
113123
'app_path' => 'app',
114124
'var_path' => 'app',
125+
'kernel_class' => null,
115126
'environment' => 'test',
116127
'debug' => true,
117128
'cache_router' => false,
@@ -284,10 +295,8 @@ protected function getKernelClass()
284295

285296
require_once $file;
286297

287-
$possibleKernelClasses = [
288-
'AppKernel', // Symfony Standard
289-
'App\Kernel', // Symfony Flex
290-
];
298+
$possibleKernelClasses = $this->getPossibleKernelClasses();
299+
291300
foreach ($possibleKernelClasses as $class) {
292301
if (class_exists($class)) {
293302
$refClass = new \ReflectionClass($class);
@@ -624,4 +633,25 @@ private function dataRevealsValue(Data $data)
624633
{
625634
return method_exists($data, 'getValue');
626635
}
636+
637+
/**
638+
* Returns list of the possible kernel classes based on the module configuration
639+
*
640+
* @return array
641+
*/
642+
private function getPossibleKernelClasses()
643+
{
644+
if (empty($this->config['kernel_class'])) {
645+
return self::$possibleKernelClasses;
646+
}
647+
648+
if (!is_string($this->config['kernel_class'])) {
649+
throw new ModuleException(
650+
__CLASS__,
651+
"Parameter 'kernel_class' must have 'string' type.\n"
652+
);
653+
}
654+
655+
return [$this->config['kernel_class']];
656+
}
627657
}

0 commit comments

Comments
 (0)