1
- Laravel Doctrine Data Fixtures
2
- ------------------------------
1
+ # Laravel Doctrine Data Fixtures
3
2
4
3
Laravel has built-in support for 'seed' data. In seed data, the classes
5
4
are not namespaced and many developers treat seed data as a one-time
@@ -90,8 +89,10 @@ List all groups or list all fixtures for a group.
90
89
php artisan doctrine:data-fixtures:list [< group> ]
91
90
```
92
91
93
- ### Executing Fixture Group through Artisan command
94
- ---------------------------------------------------
92
+ The ` <group> ` is optional.
93
+
94
+
95
+ ### Executing a Fixture Group through Artisan command
95
96
96
97
``` sh
97
98
php artisan doctrine:data-fixtures:import < group> [--purge-with-truncate] [--do-not-append]
@@ -109,23 +110,27 @@ running fixtures for the ORMPurger only.
109
110
` --do-not-append ` will delete all data in the database before running fixtures.
110
111
111
112
112
- Executing Fixture Group from code
113
+ Executing a Fixture Group from code
113
114
---------------------------------
114
115
115
116
For unit testing or other times you must run your fixtures from within code,
116
117
follow this example:
117
118
118
119
``` php
119
- $config = $application['config']['doctrine-data-fixtures.' . $groupName];
120
+ use use Doctrine\Common\DataFixtures\Loader;
121
+
122
+ $config = config('doctrine-data-fixtures')[$groupName];
120
123
121
- $objectManager = $application->get($config['objectManager']);
122
- $loader = $application->get($config['loader']);
123
- $purger = $application->get($config['purger']);
124
+ $objectManager = app($config['objectManager']);
125
+ $purger = app($config['purger']);
126
+ $executorClass = $config['executor'];
127
+ $loader = new Loader();
124
128
125
129
foreach ($config['fixtures'] as $fixture) {
126
130
$loader->addFixture($fixture);
127
131
}
128
132
133
+ $executor = new $executorClass($objectManager, $purger);
129
134
$executor->execute($loader->getFixtures());
130
135
```
131
136
0 commit comments