Skip to content

Commit a0bbb7c

Browse files
VolChDavertMik
authored andcommitted
[Symfony] Minimal support for Symfony Flex directory and namespace structure (#4563)
Introduce support od Symfony Flex - Symfony 3.3+ recommended way for Symfony app. Demo app can be found at https://github.com/VolCh/symfony-flex-demo
1 parent 6c76828 commit a0bbb7c

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Codeception\Lib\Interfaces\PartedModule;
1010
use Symfony\Component\Finder\Finder;
1111
use Symfony\Component\DependencyInjection\ContainerInterface;
12+
use Symfony\Component\Finder\SplFileInfo;
1213
use Symfony\Component\VarDumper\Cloner\Data;
1314

1415
/**
@@ -257,17 +258,32 @@ protected function getKernelClass()
257258
if (!count($results)) {
258259
throw new ModuleRequireException(
259260
__CLASS__,
260-
"AppKernel was not found at $path. "
261-
. "Specify directory where Kernel class for your application is located with `app_path` parameter."
261+
"File with Kernel class was not found at $path. "
262+
. "Specify directory where file with Kernel class for your application is located with `app_path` parameter."
262263
);
263264
}
264-
265265
$file = current($results);
266-
$class = $file->getBasename('.php');
267266

268267
require_once $file;
269268

270-
return $class;
269+
$possibleKernelClasses = [
270+
'AppKernel', // Symfony Standard
271+
'App\Kernel', // Symfony Flex
272+
];
273+
foreach ($possibleKernelClasses as $class) {
274+
if (class_exists($class)) {
275+
$refClass = new \ReflectionClass($class);
276+
if ($refClass->getFileName() === $file->getRealpath()) {
277+
return $class;
278+
}
279+
}
280+
}
281+
282+
throw new ModuleRequireException(
283+
__CLASS__,
284+
"Kernel class was not found in $file. "
285+
. "Specify directory where file with Kernel class for your application is located with `app_path` parameter."
286+
);
271287
}
272288

273289
/**

0 commit comments

Comments
 (0)