|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Yii 2 tests stuff |
|
4
|
|
|
* |
|
5
|
|
|
* @see https://github.com/sergeymakinen/yii2-tests |
|
6
|
|
|
* @copyright Copyright (c) 2016-2017 Sergey Makinen (https://makinen.ru) |
|
7
|
|
|
* @license https://github.com/sergeymakinen/yii2-tests/blob/master/LICENSE MIT License |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace sergeymakinen\yii\tests; |
|
11
|
|
|
|
|
12
|
|
|
use yii\helpers\ArrayHelper; |
|
13
|
|
|
|
|
14
|
|
|
abstract class TestCase extends \SergeyMakinen\Tests\TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @inheritDoc |
|
18
|
|
|
*/ |
|
19
|
1 |
|
protected function tearDown() |
|
20
|
|
|
{ |
|
21
|
1 |
|
parent::tearDown(); |
|
22
|
1 |
|
$this->destroyApplication(); |
|
23
|
1 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Creates a Yii 2 console application. |
|
27
|
|
|
* @param array $config |
|
28
|
|
|
* @param string $class |
|
29
|
|
|
*/ |
|
30
|
1 |
|
protected function createConsoleApplication(array $config = [], $class = 'yii\console\Application') |
|
31
|
|
|
{ |
|
32
|
1 |
|
new $class(ArrayHelper::merge([ |
|
33
|
1 |
|
'id' => 'console-test', |
|
34
|
1 |
|
'basePath' => \Yii::getAlias('@tests'), |
|
35
|
1 |
|
'vendorPath' => \Yii::getAlias('@tests/../vendor'), |
|
36
|
1 |
|
], $config)); |
|
37
|
1 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Creates a Yii 2 web application. |
|
41
|
|
|
* @param array $config |
|
42
|
|
|
* @param string $class |
|
43
|
|
|
*/ |
|
44
|
1 |
|
protected function createWebApplication(array $config = [], $class = 'yii\web\Application') |
|
45
|
|
|
{ |
|
46
|
1 |
|
new $class(ArrayHelper::merge([ |
|
47
|
1 |
|
'id' => 'web-test', |
|
48
|
1 |
|
'basePath' => \Yii::getAlias('@tests'), |
|
49
|
1 |
|
'vendorPath' => \Yii::getAlias('@tests/../vendor'), |
|
50
|
|
|
'components' => [ |
|
51
|
|
|
'request' => [ |
|
52
|
1 |
|
'enableCookieValidation' => false, |
|
53
|
1 |
|
'scriptFile' => \Yii::getAlias('@tests/index.php'), |
|
54
|
1 |
|
'scriptUrl' => '/index.php', |
|
55
|
1 |
|
], |
|
56
|
1 |
|
], |
|
57
|
1 |
|
], $config)); |
|
58
|
1 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Destroys an active Yii 2 application. |
|
62
|
|
|
*/ |
|
63
|
1 |
|
protected function destroyApplication() |
|
64
|
|
|
{ |
|
65
|
1 |
|
if (\Yii::$app === null) { |
|
66
|
1 |
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
if (\Yii::$app->has('session', true)) { |
|
70
|
1 |
|
\Yii::$app->session->close(); |
|
71
|
1 |
|
} |
|
72
|
1 |
|
\Yii::$app = null; |
|
73
|
1 |
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|