1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\codeception\common\_support; |
4
|
|
|
|
5
|
|
|
use tests\codeception\common\fixtures\UserFixture; |
6
|
|
|
use Codeception\Module; |
7
|
|
|
use yii\test\FixtureTrait; |
8
|
|
|
use yii\test\InitDbFixture; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This helper is used to populate the database with needed fixtures before any tests are run. |
12
|
|
|
* In this example, the database is populated with the demo login user, which is used in acceptance |
13
|
|
|
* and functional tests. All fixtures will be loaded before the suite is started and unloaded after it |
14
|
|
|
* completes. |
15
|
|
|
*/ |
16
|
|
|
class FixtureHelper extends Module |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Redeclare visibility because codeception includes all public methods that do not start with "_" |
21
|
|
|
* and are not excluded by module settings, in actor class. |
22
|
|
|
*/ |
23
|
|
|
use FixtureTrait { |
24
|
|
|
loadFixtures as public; |
25
|
|
|
fixtures as public; |
26
|
|
|
globalFixtures as public; |
27
|
|
|
createFixtures as public; |
28
|
|
|
unloadFixtures as protected; |
29
|
|
|
getFixtures as protected; |
30
|
|
|
getFixture as protected; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Method called before any suite tests run. Loads User fixture login user |
35
|
|
|
* to use in acceptance and functional tests. |
36
|
|
|
* @param array $settings |
37
|
|
|
*/ |
38
|
|
|
public function _beforeSuite($settings = []) |
39
|
|
|
{ |
40
|
|
|
$this->loadFixtures(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Method is called after all suite tests run |
45
|
|
|
*/ |
46
|
|
|
public function _afterSuite() |
47
|
|
|
{ |
48
|
|
|
$this->unloadFixtures(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritdoc |
53
|
|
|
*/ |
54
|
|
|
public function globalFixtures() |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
InitDbFixture::className(), |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritdoc |
63
|
|
|
*/ |
64
|
|
|
public function fixtures() |
65
|
|
|
{ |
66
|
|
|
return [ |
67
|
|
|
'user' => [ |
68
|
|
|
'class' => UserFixture::className(), |
69
|
|
|
'dataFile' => '@tests/codeception/common/fixtures/data/init_login.php', |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|