Search code examples
codeception

Codeception 2.2 api tests ZF2 and PhpBrowser module together


Codeception API tester require PhpBrowser module and I want to use ZF2 module because I need retrieve some services from ServiceManager.

After update Codeception to 2.2 it throws this exception:

[Codeception\Exception\ModuleConflictException] ZF2 module conflicts with PhpBrowser

Is there any way to enable ZF2 and PhpBrowser together in Codeception 2.2?


Solution

  • If you have a good reason to use ZF2 in the same suite as PhpBrowser, you can create your own helper class and load ZF2 module as a dependency.

    Configuration:

    modules:
        enabled:
            - PhpBrowser:
                url: http://localhost/
            - \Helper\Zf2Helper:
                depends: ZF2
    

    Code tests/_support/Helper/Zf2Helper.php:

    <?php
    namespace Helper;
    
    class Zf2Helper extends \Codeception\Module
    {
    
      private $zf2;
    
      public function _inject(\Codeception\Module\ZF2 $zf2)
      {
         $this->zf2 = $zf2;
      }
    
      public function doSomethingWithZf2
      {
         $this->zf2->doSomething();
      }
    }
    

    Update:

    Since Codeception 2.2.2 release it is possible to load services part of ZF2 which enables grabServiceFromContainer method.

    Configuration:

    modules:
        enabled:
            - PhpBrowser:
                url: http://localhost/
            - ZF2
                part: services