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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
namespace yiiunit\framework\console\controllers;
use Yii;
use yiiunit\TestCase;
use yiiunit\data\console\controllers\fixtures\FixtureStorage;
use yii\console\controllers\FixtureController;
/**
* Unit test for [[\yii\console\controllers\FixtureController]].
* @see FixtureController
*
* @group console
*/
class FixtureControllerTest extends TestCase
{
/**
* @var \yiiunit\framework\console\controllers\FixtureConsoledController
*/
private $_fixtureController;
protected function setUp()
{
parent::setUp();
$this->_fixtureController = Yii::createObject([
'class' => 'yiiunit\framework\console\controllers\FixtureConsoledController',
'interactive' => false,
'globalFixtures' => [],
'namespace' => 'yiiunit\data\console\controllers\fixtures',
],[null, null]); //id and module are null
}
protected function tearDown()
{
$this->_fixtureController = null;
FixtureStorage::clear();
parent::tearDown();
}
public function testLoadGlobalFixture()
{
$this->_fixtureController->globalFixtures = [
'\yiiunit\data\console\controllers\fixtures\Global'
];
$this->_fixtureController->actionLoad('First');
$this->assertCount(1, FixtureStorage::$globalFixturesData, 'global fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
}
public function testUnloadGlobalFixture()
{
$this->_fixtureController->globalFixtures = [
'\yiiunit\data\console\controllers\fixtures\Global'
];
FixtureStorage::$globalFixturesData[] = 'some seeded global fixture data';
FixtureStorage::$firstFixtureData[] = 'some seeded first fixture data';
$this->assertCount(1, FixtureStorage::$globalFixturesData, 'global fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->_fixtureController->actionUnload('First');
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should be unloaded');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
}
public function testLoadAll()
{
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should be empty');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be empty');
$this->assertEmpty(FixtureStorage::$secondFixtureData, 'second fixture data should be empty');
$this->_fixtureController->actionLoad('*');
$this->assertCount(1, FixtureStorage::$globalFixturesData, 'global fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$secondFixtureData, 'second fixture data should be loaded');
}
public function testUnloadAll()
{
FixtureStorage::$globalFixturesData[] = 'some seeded global fixture data';
FixtureStorage::$firstFixtureData[] = 'some seeded first fixture data';
FixtureStorage::$secondFixtureData[] = 'some seeded second fixture data';
$this->assertCount(1, FixtureStorage::$globalFixturesData, 'global fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->assertCount(1, FixtureStorage::$secondFixtureData, 'second fixture data should be loaded');
$this->_fixtureController->actionUnload('*');
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should be unloaded');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
$this->assertEmpty(FixtureStorage::$secondFixtureData, 'second fixture data should be unloaded');
}
public function testLoadParticularExceptOnes()
{
$this->_fixtureController->actionLoad('First', '-Second', '-Global');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should not be loaded');
$this->assertEmpty(FixtureStorage::$secondFixtureData, 'second fixture data should not be loaded');
}
public function testUnloadParticularExceptOnes()
{
FixtureStorage::$globalFixturesData[] = 'some seeded global fixture data';
FixtureStorage::$firstFixtureData[] = 'some seeded first fixture data';
FixtureStorage::$secondFixtureData[] = 'some seeded second fixture data';
$this->_fixtureController->actionUnload('First', '-Second', '-Global');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
$this->assertNotEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should not be unloaded');
$this->assertNotEmpty(FixtureStorage::$secondFixtureData, 'second fixture data should not be unloaded');
}
public function testLoadAllExceptOnes()
{
$this->_fixtureController->actionLoad('*', '-Second', '-Global');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->assertEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should not be loaded');
$this->assertEmpty(FixtureStorage::$secondFixtureData, 'second fixture data should not be loaded');
}
public function testUnloadAllExceptOnes()
{
FixtureStorage::$globalFixturesData[] = 'some seeded global fixture data';
FixtureStorage::$firstFixtureData[] = 'some seeded first fixture data';
FixtureStorage::$secondFixtureData[] = 'some seeded second fixture data';
$this->_fixtureController->actionUnload('*', '-Second', '-Global');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
$this->assertNotEmpty(FixtureStorage::$globalFixturesData, 'global fixture data should not be unloaded');
$this->assertNotEmpty(FixtureStorage::$secondFixtureData, 'second fixture data should not be unloaded');
}
public function testNothingToLoadParticularExceptOnes()
{
$this->_fixtureController->actionLoad('First', '-First');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should not be loaded');
}
public function testNothingToUnloadParticularExceptOnes()
{
$this->_fixtureController->actionUnload('First', '-First');
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should not be loaded');
}
public function testAppendFixtureData()
{
$this->assertEmpty(FixtureStorage::$firstFixtureData, 'first fixture data should be unloaded');
$this->_fixtureController->actionLoad('First');
$this->assertCount(1, FixtureStorage::$firstFixtureData, 'first fixture data should be loaded');
$this->_fixtureController->append = true;
$this->_fixtureController->actionLoad('First');
$this->assertCount(2, FixtureStorage::$firstFixtureData, 'first fixture data should be appended to already existed one');
}
/**
* @expectedException \yii\console\Exception
*/
public function testNoFixturesWereFoundInLoad()
{
$this->_fixtureController->actionLoad('NotExistingFixture');
}
/**
* @expectedException \yii\console\Exception
*/
public function testNoFixturesWereFoundInUnload()
{
$this->_fixtureController->actionUnload('NotExistingFixture');
}
}
class FixtureConsoledController extends FixtureController
{
public function stdout($string)
{
}
}