Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppKernel name only #4695

Closed
Mark1Z opened this issue Dec 15, 2017 · 11 comments
Closed

AppKernel name only #4695

Mark1Z opened this issue Dec 15, 2017 · 11 comments

Comments

@Mark1Z
Copy link

Mark1Z commented Dec 15, 2017

# codeception/codeception/src/Codeception/Module/Symfony.php:282

        $possibleKernelClasses = [
            'AppKernel', // Symfony Standard
            'App\Kernel', // Symfony Flex
        ];
        foreach ($possibleKernelClasses as $class) {
            if (class_exists($class)) {
                $refClass = new \ReflectionClass($class);
                if ($refClass->getFileName() === $file->getRealpath()) {
                    return $class;
                }
            }
        }

        throw new ModuleRequireException(
            __CLASS__,
            "Kernel class was not found in $file. "
            . "Specify directory where file with Kernel class for your application is located with `app_path` parameter."
        );

Details

Code listed above disables possibility to run tests with kernels named different than AppKernel.

  • Codeception version: 2.3.7
  • PHP Version: 7.1.9
  • Operating System: Linux Ubuntu
  • Installation type: Phar || Composer
  • List of installed packages (composer show)
  • Suite configuration:
@VolCh
Copy link
Contributor

VolCh commented Dec 15, 2017

What kernel name causes a problem?

@DavertMik
Copy link
Member

I think if it causes a problem kernel name should be added to the config.

@Mark1Z
Copy link
Author

Mark1Z commented Dec 15, 2017

I'm using app/Kernels/Frontend/FrontendKernel and have those suite.yml config:

class_name: FunctionalTester
modules:
    enabled:
        - Symfony:
            app_path: '../../app/Kernels/Frontend'
            var_path: '../../var'
            environment: 'test'
        - Doctrine2:
            depends: Symfony
        - \frontend\Helper\Functional

and got error from codeception:

Kernel class was not found in /var/www/html/tests/frontend/../../app/Kernels/Frontend/FrontendKernel.php. Specify directory where file with Kernel class for your application is located with app_path parameter.

If I add FrontendKernel here:

$possibleKernelClasses = [
            'FrontendKernel',
            'AppKernel', // Symfony Standard
            'App\Kernel', // Symfony Flex
        ];

all seems to be fine. As I see, this code was added for symfony 4 in one of last commits, because it was working for me before.

@DavertMik
Copy link
Member

Yes, that's right, we updated code for symfony 4. Sure as in all major update there could have happened some breaking things unnoticed. I think we should add this option to config

@VolCh
Copy link
Contributor

VolCh commented Dec 20, 2017

I have two options for simple resolving the issue:

  • path with optional filename (according PSR-0/PSR-4 conventions for classname) in the existing app_path option
  • new app_kernel option with empty value by default. Empty value provides current behavior, full classname overrides it.

@Mark1Z
Copy link
Author

Mark1Z commented Dec 20, 2017

I guess both options are fine, but I prefer first one, with app_path which can handle not only folder name but full filename too. Thanks:D

@VolCh
Copy link
Contributor

VolCh commented Dec 22, 2017

I have tried to implement first options without second and found that it is not trivial in the case of namespaced kernel like Symfony Flex provide by default. We need to provide full kernel class name or use something like https://github.com/goaop/parser-reflection/blob/master/src/ReflectionFile.php to detetmine it.

On other hand, we can ignore app_path here and use app_kernel only if we are sure that autoloader (composer in most cases) can load kernel or kernel loaded already.

@DavertMik what do you think about it?

@DavertMik
Copy link
Member

Providing full kernel class name sounds ok to me.

On other hand, we can ignore app_path here and use app_kernel only if we are sure that autoloader (composer in most cases) can load kernel or kernel loaded already.

Yes. That would be fine

@zstate
Copy link

zstate commented Feb 19, 2018

Any updates on the issue? We have the same problem with namespaced kernel class, it doesn't let as run any functional or integration tests, which require the kernel.

@alefcastelo
Copy link
Contributor

I made a PR to solve this #5022

@Naktibalda
Copy link
Member

This issue was solved by #5022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants