Repository navigation
Expand file tree
/
Copy pathZF2.php
More file actions
96 lines (81 loc) · 2.62 KB
/
Copy pathZF2.php
File metadata and controls
96 lines (81 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Codeception\Module;
use Codeception\Codecept;
use Zend\Console\Console;
use Zend\EventManager\StaticEventManager;
use Zend\Mvc\Application;
use Zend\View\Helper\Placeholder;
use Zend\Version\Version;
/**
* This module allows you to run tests inside Zend Framework 2.
*
* File `init_autoloader` in project's root is required.
* Uses `tests/application.config.php` config file by default.
*
* ## Status
*
* * Maintainer: **bladeofsteel**
* * Stability: **alpha**
* * Contact: https://github.com/bladeofsteel
*
* ## Config
*
* * config: relative path to config file (default: `tests/application.config.php`)
*
* ## API
*
* * application - instance of `\Zend\Mvc\ApplicationInterface`
* * db - instance of `\Zend\Db\Adapter\AdapterInterface`
* * client - BrowserKit client
*
*/
class ZF2 extends \Codeception\Lib\Framework
{
protected $config = array(
'config' => 'tests/application.config.php',
);
/**
* @var \Zend\Mvc\ApplicationInterface
*/
public $application;
/**
* @var \Zend\Db\Adapter\AdapterInterface
*/
public $db;
/**
* @var \Codeception\Lib\Connector\ZF2
*/
public $client;
protected $queries = 0;
protected $time = 0;
public function _initialize() {
require \Codeception\Configuration::projectDir().'init_autoloader.php';
$this->client = new \Codeception\Lib\Connector\ZF2();
}
public function _before(\Codeception\TestCase $test) {
$applicationConfig = require \Codeception\Configuration::projectDir() . $this->config['config'];
if (isset($applicationConfig['module_listener_options']['config_cache_enabled'])) {
$applicationConfig['module_listener_options']['config_cache_enabled'] = false;
}
Console::overrideIsConsole(false);
$this->application = Application::init($applicationConfig);
$events = $this->application->getEventManager();
$events->detach($this->application->getServiceManager()->get('SendResponseListener'));
$this->client->setApplication($this->application);
$_SERVER['REQUEST_URI'] = '';
}
public function _after(\Codeception\TestCase $test) {
$_SESSION = array();
$_GET = array();
$_POST = array();
$_COOKIE = array();
// reset singleton
StaticEventManager::resetInstance();
// Reset singleton placeholder if version < 2.2.0, no longer required in 2.2.0+
if (Version::compareVersion('2.2.0') >= 0) {
Placeholder\Registry::unsetRegistry();
}
$this->queries = 0;
$this->time = 0;
}
}