44
55namespace Codeception \Module ;
66
7+ use Codeception \Exception \ModuleException ;
78use Codeception \Lib \Interfaces \DataMapper ;
89use Codeception \Lib \Interfaces \DependsOnModule ;
910use Codeception \Lib \Interfaces \ORM ;
10- use Codeception \Exception \ModuleException ;
1111use Codeception \Lib \Interfaces \RequiresPackage ;
12+ use Codeception \Module ;
1213use Codeception \TestInterface ;
1314use League \FactoryMuffin \Definition ;
15+ use League \FactoryMuffin \Exceptions \DefinitionAlreadyDefinedException as FactoryMuffinDefinitionAlreadyDefinedException ;
1416use League \FactoryMuffin \FactoryMuffin ;
1517use League \FactoryMuffin \Stores \RepositoryStore ;
1618use League \FactoryMuffin \Stores \StoreInterface ;
2729 * }
2830 * ```
2931 *
30- * Generation rules can be defined in a factories file.
32+ * Generation rules can be defined in a factories file.
3133 * Create a folder for factories files: `tests/_support/factories`.
3234 *
33- * Create an ampty PHP file inside that folder `factories.php`.
35+ * Create an empty PHP file inside that folder `factories.php`.
3436 * Follow [FactoryMuffin documentation](https://github.com/thephpleague/factory-muffin) to set valid rules.
3537 * Randomly generated data provided by [Faker](https://github.com/fzaninotto/Faker) library.
3638 *
127129 * ```
128130 *
129131 * ### Custom store
130- *
132+ *
131133 * You can define a custom store for Factory Muffin using `customStore` parameter. It can be a simple class or a factory with `create` method.
132134 * The instantiated object must implement `\League\FactoryMuffin\Stores\StoreInterface`.
133- *
135+ *
134136 * Store factory example:
135137 * ```yaml
136138 * modules:
137139 * enabled:
138140 * - DataFactory:
139141 * customStore: \common\tests\store\MyCustomStoreFactory
140142 * ```
141- *
143+ *
142144 * ```php
143145 * use League\FactoryMuffin\Stores\StoreInterface;
144- *
146+ *
145147 * class MyCustomStoreFactory
146148 * {
147149 * public function create(): StoreInterface
148150 * {
149151 * return CustomStore();
150152 * }
151153 * }
152- *
154+ *
153155 * class CustomStore implements StoreInterface
154156 * {
155157 * // ...
156158 * }
157159 * ```
158160 */
159- class DataFactory extends \ Codeception \ Module implements DependsOnModule, RequiresPackage
161+ class DataFactory extends Module implements DependsOnModule, RequiresPackage
160162{
161163 protected string $ dependencyMessage = <<<EOF
162164ORM module (like Doctrine2) or Framework module with ActiveRecord support is required:
@@ -170,20 +172,25 @@ class DataFactory extends \Codeception\Module implements DependsOnModule, Requir
170172
171173 /**
172174 * ORM module on which we we depend on.
175+ *
176+ * @var Module
173177 */
174178 public ?ORM $ ormModule = null ;
175179
176180 public ?FactoryMuffin $ factoryMuffin = null ;
177181
178182 /**
179- * @var array
183+ * @var array<string, mixed>
180184 */
181- protected $ config = ['factories ' => null , 'customStore ' => null ];
185+ protected array $ config = [
186+ 'factories ' => null ,
187+ 'customStore ' => null ,
188+ ];
182189
183190 public function _requires (): array
184191 {
185192 return [
186- FactoryMuffin::class => '"league/factory-muffin": "^3.0 " ' ,
193+ FactoryMuffin::class => '"league/factory-muffin": "^3.3 " ' ,
187194 ];
188195 }
189196
@@ -193,8 +200,8 @@ public function _beforeSuite($settings = [])
193200 $ this ->factoryMuffin = new FactoryMuffin ($ store );
194201
195202 if ($ this ->config ['factories ' ]) {
196- foreach ((array ) $ this ->config ['factories ' ] as $ factoryPath ) {
197- $ realpath = realpath (codecept_root_dir (). $ factoryPath );
203+ foreach ((array )$ this ->config ['factories ' ] as $ factoryPath ) {
204+ $ realpath = realpath (codecept_root_dir () . $ factoryPath );
198205 if ($ realpath === false ) {
199206 throw new ModuleException ($ this , 'The path to one of your factories is not correct. Please specify the directory relative to the codeception.yml file (ie. _support/factories). ' );
200207 }
@@ -228,12 +235,12 @@ public function _inject(ORM $orm): void
228235 public function _after (TestInterface $ test )
229236 {
230237 $ skipCleanup = array_key_exists ('cleanup ' , $ this ->config ) && $ this ->config ['cleanup ' ] === false ;
231- $ cleanupOrmModule_Config = $ this ->ormModule ->_getConfig ('cleanup ' );
238+ $ cleanupOrmModuleConfig = $ this ->ormModule ->_getConfig ('cleanup ' );
232239 if ($ skipCleanup ) {
233240 return ;
234241 }
235242
236- if ($ cleanupOrmModule_Config ) {
243+ if ($ cleanupOrmModuleConfig ) {
237244 return ;
238245 }
239246
@@ -242,7 +249,9 @@ public function _after(TestInterface $test)
242249
243250 public function _depends (): array
244251 {
245- return [ORM ::class => $ this ->dependencyMessage ];
252+ return [
253+ ORM ::class => $ this ->dependencyMessage ,
254+ ];
246255 }
247256
248257 /**
@@ -268,7 +277,7 @@ public function onReconfigure($settings = [])
268277 * ]);
269278 * ```
270279 *
271- * @throws \League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException
280+ * @throws FactoryMuffinDefinitionAlreadyDefinedException
272281 */
273282 public function _define (string $ model , array $ fields ): Definition
274283 {
0 commit comments