SymfonyExtension icon indicating copy to clipboard operation
SymfonyExtension copied to clipboard

Kernel autodiscover

Open DonCallisto opened this issue 5 years ago • 12 comments

I think that https://github.com/FriendsOfBehat/SymfonyExtension/blob/2f038b27c60cf56b24f41a451d7e211975008c2f/src/ServiceContainer/SymfonyExtension.php#L210 should be, somehow, parametric as with this check we're forced to run behat command from the same folder of app. WDYT?

DonCallisto avatar Aug 28 '19 10:08 DonCallisto

Makes sense, using %paths.base% could help here.

pamil avatar Sep 09 '19 14:09 pamil

Sorry to be late on this. Are you sure that %pahts.base% would be the right choice? I mean, %paths.base% can easly contain any path so it would be virtually impossible to create a "fixed" path to discover the Kernel.php file. Am I missing something?

DonCallisto avatar Nov 26 '19 07:11 DonCallisto

%paths.base% is the directory that contains Behat config file IIRC.

pamil avatar Nov 26 '19 13:11 pamil

Yes, indeed but it could be placed wherever so that's no way to reach the Kernel.php in univocal fashion I suppose. Am I missing something?

DonCallisto avatar Nov 26 '19 13:11 DonCallisto

We need to rely on either the current working directory or the directory with Behat config files in order to autodiscover the kernel file. The purpose of the autodiscovering itself is to guess the path, while still leaving the possibility for someone to define their own path.

pamil avatar Nov 26 '19 14:11 pamil

I know this but using %paths.base% is literally not valid like "guessing" that we're running the command from the root of the project (so where app/ dir could be found). I don't know if there's any symfony parameter that would help us to find the directory of Kernel.php, have to take a look. If it is not, I would close this as using %paths.base% seems not to enhance the current mechanism from my standpoint.

DonCallisto avatar Nov 26 '19 14:11 DonCallisto

@DonCallisto yeah, I don't think there's any other way except for looking for the kernel location in common files like public/index.php or bin/console, which are the only points in standard Symfony applications that explicitly refer to the currently used kernel.

Could you provide which scenario is currently not working for you that could be solved here? (I mean in which way you would run behat that makes the current implementation not working as expected)

pamil avatar Nov 26 '19 14:11 pamil

I think that bin/console would be ok.

The scenario is where you run Behat outside the root of the project without specifiying my own path with the configuration. I know that sounds like that's not a problem, and indeed it isn't, I was just arguing about the fact that app/Kernel.php sounds no good as it is a relative path. In my case the solution would be to explicitly specify the path of Kernel.php that is in the "standard" path so it seems a little bit "strange".

DonCallisto avatar Nov 27 '19 08:11 DonCallisto

Is there any news on this feature? :)

wapcrazut avatar Feb 12 '20 11:02 wapcrazut

@wapcrazut I've tried an implementation but I failed (and TBH, I didn't spent too much time on this). As you can specify Kernel path in configuration, for the moment, I've switched to that solution. BTW this would be a nice feature. Any implementation idea?

DonCallisto avatar Feb 13 '20 08:02 DonCallisto

I tried to give it a shot, but it looks like it wouldn't work with Behat's autoloading:

if (is_file($autoload = getcwd() . '/vendor/autoload.php')) {
    require $autoload;
}

That's the snippet from vendor/bin/behat that makes it dependent on the current working directory.

pamil avatar Apr 04 '20 14:04 pamil

Umh, I guess we cannot do anything better...

DonCallisto avatar Apr 06 '20 07:04 DonCallisto