Behat / Symfony2Extension

Symfony2 extension for Behat
MIT License
393 stars 106 forks source link

Extension sets Definition->file to root-dir #154

Open leberknecht opened 4 years ago

leberknecht commented 4 years ago

I upgraded my api-platform project from 2.4.2 to 2.5.3, im not exactly sure where the different behavior from the behat-extension comes from, but i found that: on the older version, the environment on vendor/behat/symfony2-extension/src/Behat/Symfony2Extension/ServiceContainer/Symfony2Extension.php:process looks like this:

$basePath = "/home/delf/<project>/api"
$bootstrap = "/home/delf/<project>/api/tests/features/bootstrap/bootstrap.php"
$bootstrapPath = "tests/features/bootstrap/bootstrap.php"
$container = {Symfony\Component\DependencyInjection\ContainerBuilder} [33]
$kernelPath = "app/AppKernel.php"

while after the upgrade it is this:

$basePath = "/home/delf/dev/efi/api"
$bootstrapPath = null
$container = {Symfony\Component\DependencyInjection\ContainerBuilder} [33]
$kernelPath = null

then we do on Symfony2Extension.php:138

if (file_exists($kernel = $basePath . '/' . $kernelPath)) 

which will be true, as the concatenated string points to a directory and file_exists treats files and directories the same. If we would trigger the other if-branch, we would set just $kernelPath (null) to Definition->file (and i think that would actually work on createService later on..?) So, question: i'm not quite sure about that, but shouldnt we use

if (file_exists($kernel = $basePath . '/' . $kernelPath) && is_file($kernel))

instead, to ensure that we are pointing to a file and not a directory?

Site-note, if someone else runs into this: just set the path on the extension definition:

    extensions:
        Behat\Symfony2Extension:
            kernel:
                bootstrap: "tests/features/bootstrap/bootstrap.php"
                class: App\Kernel
                path: "app/AppKernel.php"