Completed
Push — master ( 630401...3eb757 )
by Oleg
02:43
created

ZendExpressive3::_initialize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
rs 9.568
cc 3
nc 4
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace codecept\Helper;
5
6
use Codeception\Configuration;
7
use Codeception\Lib\Connector\ZendExpressive as ZendExpressiveConnector;
8
use Doctrine\Common\Persistence\ManagerRegistry;
9
10
class ZendExpressive3 extends \Codeception\Module\ZendExpressive
11
{
12
    public function _initialize()
13
    {
14
        $cwd = getcwd();
15
        $projectDir = Configuration::projectDir();
16
        chdir($projectDir);
17
        $this->container = require $projectDir . $this->config['container'];
18
        $app = $this->container->get(\Zend\Expressive\Application::class);
19
20
        $pipelineFile = $projectDir . 'config/pipeline.php';
21
        if (file_exists($pipelineFile)) {
22
            require $pipelineFile;
23
        }
24
        $routesFile = $projectDir . 'config/routes.php';
25
        if (file_exists($routesFile)) {
26
            require $routesFile;
27
        }
28
        chdir($cwd);
29
30
        $this->application = $app;
31
        // remove the init method, since emitter is not part of ze3
32
        $this->responseCollector = new ZendExpressiveConnector\ResponseCollector;
33
    }
34
35
    public function _getEntityManager()
36
    {
37
        if (!$this->container->has(ManagerRegistry::class)) {
38
            throw new \PHPUnit\Framework\AssertionFailedError("Service ManagerRegistry is not available in container");
39
        }
40
        /** @var ManagerRegistry $registry */
41
        $registry = $this->container->get(ManagerRegistry::class);
42
43
        return $registry->getManager();
44
    }
45
}
46