Issues (6)

src/Module/ZendExpressive.php (2 issues)

1
<?php
2
3
namespace Svycka\Codeception\Module;
4
5
use Codeception\Lib\Framework;
6
use Codeception\TestInterface;
7
use Codeception\Configuration;
8
use Svycka\Codeception\Lib\Connector\ZendExpressive as ZendExpressiveConnector;
9
use Codeception\Lib\Interfaces\DoctrineProvider;
10
11
/**
12
 * This module allows you to run tests inside Zend Expressive 3.
13
 *
14
 * Uses `config/container.php` file by default.
15
 *
16
 * ## Config
17
 *
18
 * * container: relative path to file which returns Container (default: `config/container.php`)
19
 * * pipeline: relative path to file which returns pipeline config (default: `config/pipeline.php`)
20
 * * routes: relative path to file which returns routes config (default: `config/routes.php`)
21
 * * orm_service: the service name for `Doctrine\ORM\EntityManager` within container (default: `doctrine.entity_manager.orm_default`)
22
 *
23
 * ## API
24
 *
25
 * * application - instance of `\Zend\Expressive\Application`
26
 * * container - instance of `\Psr\Container\ContainerInterface`
27
 * * client - BrowserKit client
28
 *
29
 */
30
final class ZendExpressive extends Framework implements DoctrineProvider
31
{
32
    protected $config = [
33
        'container' => 'config/container.php',
34
        'pipeline' => 'config/pipeline.php',
35
        'routes' => 'config/routes.php',
36
        'orm_service' => 'doctrine.entity_manager.orm_default',
37
    ];
38
39
    /**
40
     * @var \Codeception\Lib\Connector\ZendExpressive
41
     */
42
    public $client;
43
44
    /**
45
     * @var \Psr\Container\ContainerInterface
46
     */
47
    public $container;
48
49
    /**
50
     * @var \Zend\Expressive\Application
51
     */
52
    public $application;
53
54
    protected $responseCollector;
55
56
    public function _initialize() : void
57
    {
58
        $cwd = getcwd();
59
        $projectDir = Configuration::projectDir();
60
        chdir($projectDir);
61
        $this->container = require $projectDir . $this->config['container'];
62
        $app = $this->container->get('Zend\Expressive\Application');
63
        $factory = $this->container->get(\Zend\Expressive\MiddlewareFactory::class);
64
65
        $pipelineFile = $projectDir . $this->config['pipeline'];
66
        if (file_exists($pipelineFile)) {
67
            (require $pipelineFile)($app, $factory, $this->container);
68
        }
69
        $routesFile = $projectDir . $this->config['routes'];
70
        if (file_exists($routesFile)) {
71
            (require $routesFile)($app, $factory, $this->container);
72
        }
73
        chdir($cwd);
74
75
        $this->application = $app;
76
    }
77
78
    public function _before(TestInterface $test) : void
79
    {
80
        $this->client = new ZendExpressiveConnector();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Svycka\Codeception\L...nector\ZendExpressive() of type Svycka\Codeception\Lib\Connector\ZendExpressive is incompatible with the declared type Codeception\Lib\Connector\ZendExpressive of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
81
        $this->client->setApplication($this->application);
82
    }
83
84
    public function _after(TestInterface $test) : void
85
    {
86
        //Close the session, if any are open
87
        if (session_status() == PHP_SESSION_ACTIVE) {
88
            session_write_close();
89
        }
90
    }
91
92
    public function _getEntityManager() : \Doctrine\ORM\EntityManagerInterface
0 ignored issues
show
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
    {
94
        $service = $this->config['orm_service'];
95
        if (!$this->container->has($service)) {
96
            throw new \PHPUnit\Framework\AssertionFailedError("Service $service is not available in container");
97
        }
98
99
        return $this->container->get($service);
100
    }
101
}
102