1 | <?php |
||
27 | trait FixtureTrait |
||
28 | { |
||
29 | /** |
||
30 | * @var array the list of fixture objects available for the current test. |
||
31 | * The array keys are the corresponding fixture class names. |
||
32 | * The fixtures are listed in their dependency order. That is, fixture A is listed before B |
||
33 | * if B depends on A. |
||
34 | */ |
||
35 | private $_fixtures; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Declares the fixtures that are needed by the current test case. |
||
40 | * The return value of this method must be an array of fixture configurations. For example, |
||
41 | * |
||
42 | * ```php |
||
43 | * [ |
||
44 | * // anonymous fixture |
||
45 | * PostFixture::class, |
||
46 | * // "users" fixture |
||
47 | * 'users' => UserFixture::class, |
||
48 | * // "cache" fixture with configuration |
||
49 | * 'cache' => [ |
||
50 | * 'class' => CacheFixture::class, |
||
51 | * 'host' => 'xxx', |
||
52 | * ], |
||
53 | * ] |
||
54 | * ``` |
||
55 | * |
||
56 | * Note that the actual fixtures used for a test case will include both [[globalFixtures()]] |
||
57 | * and [[fixtures()]]. |
||
58 | * |
||
59 | * @return array the fixtures needed by the current test case |
||
60 | */ |
||
61 | public function fixtures() |
||
65 | |||
66 | /** |
||
67 | * Declares the fixtures shared required by different test cases. |
||
68 | * The return value should be similar to that of [[fixtures()]]. |
||
69 | * You should usually override this method in a base class. |
||
70 | * @return array the fixtures shared and required by different test cases. |
||
71 | * @see fixtures() |
||
72 | */ |
||
73 | 10 | public function globalFixtures() |
|
77 | |||
78 | /** |
||
79 | * Loads the specified fixtures. |
||
80 | * This method will call [[Fixture::load()]] for every fixture object. |
||
81 | * @param Fixture[] $fixtures the fixtures to be loaded. If this parameter is not specified, |
||
82 | * the return value of [[getFixtures()]] will be used. |
||
83 | */ |
||
84 | 15 | public function loadFixtures($fixtures = null) |
|
101 | |||
102 | /** |
||
103 | * Unloads the specified fixtures. |
||
104 | * This method will call [[Fixture::unload()]] for every fixture object. |
||
105 | * @param Fixture[] $fixtures the fixtures to be loaded. If this parameter is not specified, |
||
106 | * the return value of [[getFixtures()]] will be used. |
||
107 | */ |
||
108 | 19 | public function unloadFixtures($fixtures = null) |
|
126 | |||
127 | /** |
||
128 | * Initialize the fixtures |
||
129 | * @since 2.0.12 |
||
130 | */ |
||
131 | 8 | public function initFixtures() |
|
136 | |||
137 | /** |
||
138 | * Returns the fixture objects as specified in [[globalFixtures()]] and [[fixtures()]]. |
||
139 | * @return Fixture[] the loaded fixtures for the current test case |
||
140 | */ |
||
141 | 10 | public function getFixtures() |
|
149 | |||
150 | /** |
||
151 | * Returns the named fixture. |
||
152 | * @param string $name the fixture name. This can be either the fixture alias name, or the class name if the alias is not used. |
||
153 | * @return Fixture the fixture object, or null if the named fixture does not exist. |
||
154 | */ |
||
155 | 9 | public function getFixture($name) |
|
164 | |||
165 | /** |
||
166 | * Creates the specified fixture instances. |
||
167 | * All dependent fixtures will also be created. |
||
168 | * @param array $fixtures the fixtures to be created. You may provide fixture names or fixture configurations. |
||
169 | * If this parameter is not provided, the fixtures specified in [[globalFixtures()]] and [[fixtures()]] will be created. |
||
170 | * @return Fixture[] the created fixture instances |
||
171 | * @throws InvalidConfigException if fixtures are not properly configured or if a circular dependency among |
||
172 | * the fixtures is detected. |
||
173 | */ |
||
174 | 20 | protected function createFixtures(array $fixtures) |
|
220 | } |
||
221 |