ZendExpressive3::_initialize()   A
last analyzed

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 SlayerBirden\DataFlowServer\Doctrine\Persistence\EntityManagerRegistry;
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
    /**
36
     * @return \Doctrine\ORM\EntityManagerInterface|mixed
37
     * @throws \Doctrine\ORM\ORMException
38
     */
39
    public function _getEntityManager()
40
    {
41
        if (!$this->container->has(EntityManagerRegistry::class)) {
42
            throw new \PHPUnit\Framework\AssertionFailedError(
43
                "Service EntityManagerRegistry is not available in container"
44
            );
45
        }
46
        /** @var EntityManagerRegistry $registry */
47
        $registry = $this->container->get(EntityManagerRegistry::class);
48
49
        return $registry->getManager();
50
    }
51
}
52