Codeception can't find Kernel using Symfony module with Symfony 4

Created on 1 Mar 2018  路  6Comments  路  Source: Codeception/Codeception

Trying to run test suite autogenerated by codeception

Got exception Kernel class was not found in /srv/dsp-blacklister/src/Kernel.php. Specify directory where file with Kernel class for your application is located withapp_pathparameter.

Codeception PHP Testing Framework v2.4.0
Powered by PHPUnit 7.0.2 by Sebastian Bergmann and contributors.

In Symfony.php line 300:

  [Codeception\Exception\ModuleRequireException]
  [Symfony] module requirements not met --

  Kernel class was not found in /srv/dsp-blacklister/src/Kernel.php. Specify directory where file with Kernel class for your application is located with `app_path` parameter.


Exception trace:
 Codeception\Module\Symfony->getKernelClass() at /srv/dsp-blacklister/vendor/codeception/codeception/src/Codeception/Module/Symfony.php:153
 Codeception\Module\Symfony->_initialize() at /srv/dsp-blacklister/vendor/codeception/codeception/src/Codeception/SuiteManager.php:80
 Codeception\SuiteManager->initialize() at /srv/dsp-blacklister/vendor/codeception/codeception/src/Codeception/Codecept.php:187
 Codeception\Codecept->runSuite() at /srv/dsp-blacklister/vendor/codeception/codeception/src/Codeception/Codecept.php:158
 Codeception\Codecept->run() at /srv/dsp-blacklister/vendor/codeception/codeception/src/Codeception/Command/Run.php:466
 Codeception\Command\Run->runSuites() at /srv/dsp-blacklister/vendor/codeception/codeception/src/Codeception/Command/Run.php:361
 Codeception\Command\Run->execute() at /srv/dsp-blacklister/vendor/symfony/console/Command/Command.php:252
 Symfony\Component\Console\Command\Command->run() at /srv/dsp-blacklister/vendor/symfony/console/Application.php:865
 Symfony\Component\Console\Application->doRunCommand() at /srv/dsp-blacklister/vendor/symfony/console/Application.php:241
 Symfony\Component\Console\Application->doRun() at /srv/dsp-blacklister/vendor/symfony/console/Application.php:143
 Symfony\Component\Console\Application->run() at /srv/dsp-blacklister/vendor/codeception/codeception/src/Codeception/Application.php:108
 Codeception\Application->run() at /srv/dsp-blacklister/vendor/codeception/codeception/codecept:42

run [-o|--override OVERRIDE] [-e|--ext EXT] [--report] [--html [HTML]] [--xml [XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--coverage-crap4j [COVERAGE-CRAP4J]] [--coverage-phpunit [COVERAGE-PHPUNIT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--] [<suite>] [<test>]

Details

  • Codeception version: 2.4.0
  • PHP Version: 7.1.14
  • Operating System: docker image on alpine
  • Installation type: Composer
  • List of installed packages (composer show) considering codeception
    codeception/codeception 2.4.0
    codeception/phpunit-wrapper 7.0.2
    codeception/stub 1.0.2
  • Suite configuration:
actor: FunctionalTester
modules:
    enabled:
        - Symfony:
            app_path: 'src'
            environment: 'test'
            debug: true
        - Doctrine2:
            depends: Symfony
        - \Helper\Functional

Most helpful comment

You can add to your src/Kernel.php class_alias

<?php
namespace MyCompany\MyProduct;
// uses
class Kernel extends BaseKernel
{
    // content from Symfony 4
}

class_alias(Kernel::class, 'App\Kernel', true);

All 6 comments

Discovered this error to be because of changing namespaces in application, when i return Kernel to namespace App. Everything started working correctly except that symfony bridge doesn't support PHPUnit 7 yet. So now the question is that - from where does Codeception get to Kernel full class name or smth like this? I tried to change it in phpunit.xml, this have not helped.

If i add my namespaced Kernel class to Symphony module in getKernelClass method it starts working with changed namespace. May be we should add configuration of namespace to Symfony module to allow developers work with different namespaces. Or i miss smth about this option in docs?

You can add to your src/Kernel.php class_alias

<?php
namespace MyCompany\MyProduct;
// uses
class Kernel extends BaseKernel
{
    // content from Symfony 4
}

class_alias(Kernel::class, 'App\Kernel', true);

Or eventually add new Kernel.php eg. in src_test/Kernel.php with content

<?php
namespace App;
class Kernel extends \MyCompany\MyProduct\Kernel { }

And add to composer.json

"autoload-dev": {
  "psr-4": {
    "App\\": "src_test/",
    "MyCompany\\MyProduct\\Test\\": "tests/"
  }
},

Also don't forget to upgrade your *.suite.yml

modules:
  enabled:
    - Symfony
  config:
    Symfony:
      app_path: src_test
      environment: test

But it's still workaround for real problem

I simply changed the namespace of my app from My\Custom\NamespaceApp to App.

Then changed the autoloads in composer.json and ran composer dump-autoload.

Now Codeception acceptance tests works! 馃挭

There is kernel_class parameter

modules:
  enabled:
    - Symfony
  config:
    Symfony:
      app_path: src
      environment: test
      kernel_class: 'MyApp\\Kernel'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebastianneubert picture sebastianneubert  路  3Comments

raistlin picture raistlin  路  3Comments

Renkas picture Renkas  路  3Comments

allen0817 picture allen0817  路  3Comments

gimler picture gimler  路  3Comments