Repository navigation
"Module is not enabled" error [HELP REQUESTED] #163
Description
Activity
- changed the title
[-]"Module is not enabled", grabService error [HELP REQUESTED][/-][+]"Module is not enabled" error [HELP REQUESTED][/+]on Sep 12, 2022 Do you have any other suites?
Just what's generated from the install/setup:
cat tests/*.suite.yml # Codeception Test Suite Configuration # # Suite for acceptance tests. # Perform tests in browser using the WebDriver or PhpBrowser. # If you need both WebDriver and PHPBrowser tests - create a separate suite. # acceptene.suite.yml actor: AcceptanceTester modules: enabled: - Symfony: part: services app_path: 'src' environment: 'dev' - PhpBrowser: url: https://127.0.0.1:8000/ # http://mysite.wip http_proxy: 127.0.0.1 http_proxy_port: 7080 - \App\Tests\Helper\Acceptance # Codeception Test Suite Configuration # # Suite for functional tests # Emulate web requests and make application process them # Include one of framework modules (Symfony2, Yii2, Laravel5) to use it # Remove this suite if you don't use frameworks actor: FunctionalTester modules: enabled: - Symfony: app_path: 'src' environment: 'test' # - Doctrine2: # depends: Symfony # cleanup: true - \App\Tests\Helper\Functional # Codeception Test Suite Configuration # # Suite for unit or integration tests. actor: UnitTester modules: enabled: - Asserts - \App\Tests\Helper\Unit
Is there a demo project I can add this to to show my issue? The Symfony demo + Codeception repo is pretty far out of date.
I'll post a 6.1 version shortly.
I've created a repo of the Symfony demo that shows the problem:
https://github.com/tacman/codeception-symfony-demo
It's the Symfony demo, with codeception installed (and some modules).
The yaml files have changed, as above, and there's a trivial Listener that tries to get the module.
But something's not right. PHPStorm hightlights the Symfony module as missing.
Also, the constructor fails unless I explicitly create a contributor in my class, because $options isn't set. I think the parent class can safely make those an empty array.
FWIW, the code I'm using used to access the Symfony module worked in an older version of Codeception. So I'm pretty sure I'm just configuring something incorrectly.
I'm playing with a project that creates a detailed tutorial from a cest, but am stuck on the setup. Any help would be appreciated.
Thanks.
Any chance someone could take a look at what's wrong with my setup? It's just the symfony demo with codeception and an extension that tries to get a Symfony module.
git clone https://github.com/tacman/codeception-symfony-demo && cd codeception-symfony-demo composer install symfony server:start -d vendor/bin/codecept run -v
I imagine it's a simple fix, some configuration issue, but I can't figure it out. Thanks.
I continue to hack, unsuccessfully:
public function afterSuite(SuiteEvent $e) { $suite = $e->getSuite(); $modules = $suite->getModules(); foreach ($modules as $module) { if ($module->_getName() === 'Symfony') { // throws Service `twig` is required by Codeception, but not loaded by Symfony since you're not using it anywhere in your app. $twig = $module->grabService('twig'); // } } assert($twig, "Twig is not loaded"); // this way throws an errror In Extension.php line 123: // [Symfony] module requirements not met -- // module is not enabled /** @var Symfony $symfony */ $symfony = $this->getModule('Symfony'); $twig = $symfony->grabService('twig'); }
Can anyone point me to working example code that grabs a Symfony service in a Module Extension? @Naktibalda ?
Sorry for late response.
You enabled extension codeception.yml so it
afterSuitemethod is executed for all suites, but Symfony module is not enabled in Unit suite, so I guess that you get error when unit suite is executed.I don't understand.
I've enabled it everywhere that I can think of (https://github.com/tacman/codeception-symfony-demo/blob/main/tests/unit.suite.yml).
Can you give me an example of a configure that does work?
The problem is that your extension overrides
getSubscribedEventsmethod andExtension::receiveModuleContainermethod is not executed.Either change
getSubscribedEventstopublic static function getSubscribedEvents(): array { return [ Events::SUITE_INIT => 'receiveModuleContainer', Events::SUITE_AFTER => 'afterSuite', ]; }
or delete
getSubscribedEventsmethod and declarepublic static array $events = [ Events::SUITE_AFTER => 'afterSuite', ];
Thanks! I'm making a bit of progress.
Now it's got a strange error message:
In Assert.php line 2760: [PHPUnit\Framework\AssertionFailedError] Service `twig` is required by Codeception, but not loaded by Symfony since you're not using it anywhere in your app. Recommended solution: Set it to `public` in your `config/services_test.php`/`.yaml`, see https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private Exception trace: at /home/tac/survos/demos/codeception-symfony-demo/vendor/phpunit/phpunit/src/Framework/Assert.php:2760 PHPUnit\Framework\Assert::fail() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/lib-asserts/src/Codeception/Util/Shared/InheritedAsserts.php:1162 Codeception\Module->fail() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/module-symfony/src/Codeception/Module/Symfony/ServicesAssertionsTrait.php:29 Codeception\Module\Symfony->grabService() at /home/tac/survos/demos/codeception-symfony-demo/src/EventSubscriber/LoggerSubscriber.php:29 App\EventSubscriber\LoggerSubscriber->afterSuite() at /home/tac/survos/demos/codeception-symfony-demo/vendor/symfony/event-dispatcher/EventDispatcher.php:230 Symfony\Component\EventDispatcher\EventDispatcher->callListeners() at /home/tac/survos/demos/codeception-symfony-demo/vendor/symfony/event-dispatcher/EventDispatcher.php:59 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/src/Codeception/SuiteManager.php:150 Codeception\SuiteManager->run() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/src/Codeception/Codecept.php:260 Codeception\Codecept->runSuite() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/src/Codeception/Codecept.php:216 Codeception\Codecept->run() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/src/Codeception/Command/Run.php:648 Codeception\Command\Run->runSuites() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/src/Codeception/Command/Run.php:469 Codeception\Command\Run->execute() at /home/tac/survos/demos/codeception-symfony-demo/vendor/symfony/console/Command/Command.php:308 Symfony\Component\Console\Command\Command->run() at /home/tac/survos/demos/codeception-symfony-demo/vendor/symfony/console/Application.php:1002 Symfony\Component\Console\Application->doRunCommand() at /home/tac/survos/demos/codeception-symfony-demo/vendor/symfony/console/Application.php:299 Symfony\Component\Console\Application->doRun() at /home/tac/survos/demos/codeception-symfony-demo/vendor/symfony/console/Application.php:171 Symfony\Component\Console\Application->run() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/src/Codeception/Application.php:112 Codeception\Application->run() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/app.php:45 {closure}() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/app.php:46 require() at /home/tac/survos/demos/codeception-symfony-demo/vendor/codeception/codeception/codecept:7 include() at /home/tac/survos/demos/codeception-symfony-demo/vendor/bin/codecept:120 run [-o|--override OVERRIDE] [-e|--ext EXT] [--report] [--html [HTML]] [--xml [XML]] [--phpunit-xml [PHPUNIT-XML]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--shard SHARD] [--filter FILTER] [--grep GREP] [--bootstrap [BOOTSTRAP]] [--no-redirect] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--coverage-crap4j [COVERAGE-CRAP4J]] [--coverage-cobertura [COVERAGE-COBERTURA]] [--coverage-phpunit [COVERAGE-PHPUNIT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast [FAIL-FAST]] [--no-rebuild] [--seed SEED] [--no-artifacts] [--] [<suite> [<test>]]Of course, I tried making twig public in services.yaml, as suggested:
Twig\Environment: public: true
but it won't load correctly because it needs the file loader.
And I can't simply inject twig in LoggerSubscriber.
You
getService('twig'), so I think that you must maketwigpublic:services: twig: public: true alias: Twig\Environment
Based on https://symfony.com/doc/current/service_container/alias_private.html#aliasing
no, now the cache won't even clear.
git clone https://github.com/tacman/codeception-symfony-demo twig-error && cd twig-error && composer install && vendor/bin/codecept run -v
it is a Symfony configuration issue, I can't help with it.
But this is the module-symfony library. Are there are projects that use it?
Indeed, I haven't touched the symfony configuration, I've only configured this codeception yaml files.
- locked and limited conversation to collaborators
on Jan 11, 2024
I'm not configuring something correctly, but not sure what. It fails on getModule, so I'm probably not enabling the module correctly.
The error log