99use Codeception \TestInterface ;
1010use League \FactoryMuffin \FactoryMuffin ;
1111use League \FactoryMuffin \Stores \RepositoryStore ;
12+ use League \FactoryMuffin \Stores \StoreInterface ;
1213
1314/**
1415 * DataFactory allows you to easily generate and create test data using [**FactoryMuffin**](https://github.com/thephpleague/factory-muffin).
119120 * ```php
120121 * 'user' => 'entity|User'
121122 * ```
123+ *
124+ * ### Custom store
125+ *
126+ * You can define a custom store for Factory Muffin using `customStore` parameter. It can be a simple class or a factory with `create` method.
127+ * The instantiated object must implement `\League\FactoryMuffin\Stores\StoreInterface`.
128+ *
129+ * Store factory example:
130+ * ```yaml
131+ * modules:
132+ * enabled:
133+ * - DataFactory:
134+ * customStore: \common\tests\store\MyCustomStoreFactory
135+ * ```
136+ *
137+ * ```php
138+ * use League\FactoryMuffin\Stores\StoreInterface;
139+ *
140+ * class MyCustomStoreFactory
141+ * {
142+ * public function create(): StoreInterface
143+ * {
144+ * return CustomStore();
145+ * }
146+ * }
147+ *
148+ * class CustomStore implements StoreInterface
149+ * {
150+ * // ...
151+ * }
152+ * ```
122153 */
123154class DataFactory extends \Codeception \Module implements DependsOnModule, RequiresPackage
124155{
@@ -144,7 +175,7 @@ class DataFactory extends \Codeception\Module implements DependsOnModule, Requir
144175 */
145176 public $ factoryMuffin ;
146177
147- protected $ config = ['factories ' => null ];
178+ protected $ config = ['factories ' => null , ' customStore ' => null ];
148179
149180 public function _requires ()
150181 {
@@ -174,6 +205,15 @@ public function _beforeSuite($settings = [])
174205 */
175206 protected function getStore ()
176207 {
208+ if (!empty ($ this ->config ['customStore ' ])) {
209+ $ store = new $ this ->config ['customStore ' ];
210+ if (method_exists ($ store , 'create ' )) {
211+ return $ store ->create ();
212+ }
213+
214+ return $ store ;
215+ }
216+
177217 return $ this ->ormModule instanceof DataMapper
178218 ? new RepositoryStore ($ this ->ormModule ->_getEntityManager ()) // for Doctrine
179219 : null ;
0 commit comments