petan
petan

Reputation: 3

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?

Upvotes: 0

Views: 334

Answers (2)

Naktibalda
Naktibalda

Reputation: 14110

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

Upvotes: 0

petan
petan

Reputation: 3

Thank your for your answer.

Working code with some improvements:

<?php
namespace Helper;

use Codeception\Lib\Interfaces\DependsOnModule;

class Zf2Helper extends \Codeception\Module implements DependsOnModule
{

    protected $dependencyMessage = <<<EOF
Example configuring ZF2Helper as proxy for ZF2 module method grabServiceFromContainer.
--
modules:
    enabled:
        - \Helper\ZF2Helper:
            depends: ZF2
--
EOF;

    private $zf2;

    public function _inject(\Codeception\Module\ZF2 $zf2)
    {
        $this->zf2 = $zf2;
    }

    public function _depends()
    {
        return ['Codeception\Lib\ZF2' => $this->dependencyMessage];
    }

    public function grabServiceFromContainer($service)
    {
        return $this->zf2->grabServiceFromContainer($service);
    }
}

Upvotes: 0

Related Questions