Repository navigation
Expand file tree
/
Copy pathYii2.php
More file actions
75 lines (69 loc) · 1.89 KB
/
Copy pathYii2.php
File metadata and controls
75 lines (69 loc) · 1.89 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
<?php
namespace Codeception\Module;
use Yii;
use Codeception\Util\Framework;
use Codeception\Exception\ModuleConfig;
/**
* This module provides integration with [Yii framework](http://www.yiiframework.com/) (2.0).
*
* The following configurations are required for this module:
* <ul>
* <li>entryScript - the path of the entry script</li>
* <li>url - the URL of the entry script</li>
* </ul>
*
* The entry script must return the application configuration array.
*
* You can use this module by setting params in your functional.suite.yml:
* <pre>
* class_name: TestGuy
* modules:
* enabled: [FileSystem, TestHelper, Yii2]
* config:
* Yii2:
* entryScript: '/path/to/index.php'
* url: 'http://localhost/path/to/index.php'
* </pre>
*
* ## Status
*
* Maintainer: **qiangxue**
* Stability: **beta**
*
*/
class Yii2 extends Framework
{
/**
* Application path and url must be set always
* @var array
*/
protected $requiredFields = array('entryScript', 'url');
public function _before(\Codeception\TestCase $test)
{
if (empty($this->config['entryScript'])) {
throw new ModuleConfig(__CLASS__, "Missing required config: entryScript");
}
if (empty($this->config['url'])) {
throw new ModuleConfig(__CLASS__, "Missing required config: url");
}
if (!is_file($this->config['entryScript'])) {
throw new ModuleConfig(__CLASS__, "The entry script file does not exist: {$this->config['entryScript']}");
}
$this->client = new \Codeception\Util\Connector\Yii2();
$this->client->entryScript = realpath($this->config['entryScript']);
$this->client->url = $this->config['url'];
}
public function _after(\Codeception\TestCase $test)
{
$_SESSION = array();
$_FILES = array();
$_GET = array();
$_POST = array();
$_COOKIE = array();
$_REQUEST = array();
if (Yii::$app) {
Yii::$app->session->close();
}
parent::_after($test);
}
}