Skip to content

"Module is not enabled" error [HELP REQUESTED] #163

Description

@tacman

I'm not configuring something correctly, but not sure what. It fails on getModule, so I'm probably not enabling the module correctly.

// Survos\DocBundle\EventSubscriber\LoggerSubscriber.php
    private function getTwig(): Environment
    {
        /** @var Symfony $symfony */
        $symfony = $this->getModule('Symfony');
        $twig = $symfony->grabService('twig');
        return $twig;
    }
# acceptene.suite.yml
actor: AcceptanceTester
modules:
    enabled:
        - Symfony:
              part: services
              app_path: 'src'
              environment: 'dev'
# codeception.yml
namespace: App\Tests
extensions:
    enabled:
        - Codeception\Extension\RunFailed
        - Survos\DocBundle\EventSubscriber\LoggerSubscriber: # enabled extension
              max_files: 5 # logger configuration

params:
    - .env

The error log


In Extension.php line 123:
                                                  
  [Codeception\Exception\ModuleRequireException]  
  [Symfony] module requirements not met --        
                                                  
  module is not enabled                           
                                                  

Exception trace:
  at /home/tac/survos/apps/jardin/vendor/codeception/codeception/src/Codeception/Extension.php:123
 Codeception\Extension->getModule() at /home/tac/survos/bundles/doc-bundle/src/EventSubscriber/LoggerSubscriber.php:57
 Survos\DocBundle\EventSubscriber\LoggerSubscriber->getTwig() at /home/tac/survos/bundles/doc-bundle/src/EventSubscriber/LoggerSubscriber.php:150
 Survos\DocBundle\EventSubscriber\LoggerSubscriber->afterSuite() at /home/tac/survos/apps/jardin/vendor/symfony/event-dispatcher/EventDispatcher.php:230
 Symfony\Component\EventDispatcher\EventDispatcher->callListeners() at /home/tac/survos/apps/jardin/vendor/symfony/event-dispatcher/EventDispatcher.php:59

Activity

  1. changed the title [-]"Module is not enabled", grabService error [HELP REQUESTED][/-] [+]"Module is not enabled" error [HELP REQUESTED][/+] on Sep 12, 2022
  2. Naktibalda commented on Sep 12, 2022

    @Naktibalda
    Member

    Do you have any other suites?

  3. tacman commented on Sep 12, 2022

    @tacman
    Author

    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
    
  4. tacman commented on Sep 12, 2022

    @tacman
    Author

    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.

  5. tacman commented on Sep 12, 2022

    @tacman
    Author

    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.

  6. tacman commented on Sep 14, 2022

    @tacman
    Author

    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.

  7. tacman commented on Sep 15, 2022

    @tacman
    Author

    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.

  8. tacman commented on Sep 18, 2022

    @tacman
    Author

    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 ?

  9. Naktibalda commented on Oct 3, 2022

    @Naktibalda
    Member

    Sorry for late response.

    You enabled extension codeception.yml so it afterSuite method 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.

  10. tacman commented on Oct 3, 2022

    @tacman
    Author

    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?

  11. Naktibalda commented on Oct 4, 2022

    @Naktibalda
    Member

    The problem is that your extension overrides getSubscribedEvents method and Extension::receiveModuleContainer method is not executed.

    Either change getSubscribedEvents to

    public static function getSubscribedEvents(): array
    {
        return [
            Events::SUITE_INIT => 'receiveModuleContainer',
            Events::SUITE_AFTER => 'afterSuite',
        ];
    }

    or delete getSubscribedEvents method and declare

        public static array $events = [
            Events::SUITE_AFTER => 'afterSuite',
        ];
  12. tacman commented on Oct 4, 2022

    @tacman
    Author

    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.

  13. Naktibalda commented on Oct 5, 2022

    @Naktibalda
    Member

    You getService('twig'), so I think that you must make twig public:

    services:
      twig:
        public: true
        alias: Twig\Environment

    Based on https://symfony.com/doc/current/service_container/alias_private.html#aliasing

  14. tacman commented on Oct 5, 2022

    @tacman
    Author

    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
  15. Naktibalda commented on Oct 7, 2022

    @Naktibalda
    Member

    it is a Symfony configuration issue, I can't help with it.

  16. tacman commented on Oct 7, 2022

    @tacman
    Author

    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.

  17. locked and limited conversation to collaborators on Jan 11, 2024
  18. converted this issue into a discussion #181 on Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions