@@ -11,11 +11,11 @@ re-run my fixtures at any time. I want the data my fixtures populate
11
11
to be stored with my fixtures and I want to reference fixture values
12
12
though class constants within my code.
13
13
14
- For instance, to validate a user has an ACL resource the code may
14
+ For instance, to validate a user has an ACL role the code may
15
15
read:
16
16
17
17
``` php
18
- $acl->has ($user, 'admin');
18
+ $acl->hasRole ($user, 'admin');
19
19
```
20
20
21
21
but this use of strings in the code does not read well and may be
@@ -24,10 +24,114 @@ error-prone. Instead of the above, I want my code to read
24
24
``` php
25
25
use App\ORM\Fixture\RoleFixture;
26
26
27
- $acl->has ($user, RoleFixture::admin);
27
+ $acl->hasRole ($user, RoleFixture::admin);
28
28
```
29
29
30
30
This pattern is not possible with seed data because seed data does
31
31
not have namespaces. So, this repository exists not only as an
32
- alternative to Laravel seed data, but as an namespaced-integrated
32
+ alternative to Laravel seed data, but as a namespaced-integrated
33
33
tool for static database data.
34
+
35
+
36
+ Installation
37
+ ------------
38
+
39
+ Run the following to install this library using [ Composer] ( https://getcomposer.org/ ) :
40
+
41
+ ``` bash
42
+ composer require api-skeletons/laravel-doctrine-data-fixtures
43
+ ```
44
+
45
+ A ` doctrine-data-fixtures.php ` configuration file is required. Publish the included config to your project:
46
+
47
+ ``` sh
48
+ php artisan vendor:publish --tag=config
49
+ ```
50
+
51
+
52
+ Configuration
53
+ -------------
54
+
55
+ Doctrine MongoDB, ORM and PHPCR are supported. See the configuration file for details.
56
+
57
+ This example assumes ` laravel-doctrine/orm ` is installed and you'll be using fixtures
58
+ for ORM data:
59
+
60
+ ``` php
61
+ return [
62
+ 'default' => [ // This is the group name
63
+ 'entityManager' => EntityManager::class,
64
+ 'executor' => ORMExecutor::class,
65
+ 'purger' => ORMPurger::class,
66
+ 'fixtures' => [
67
+ Fixture1::class,
68
+ Fixture2::class,
69
+ ],
70
+ ],
71
+ ];
72
+ ```
73
+
74
+ ### Fixture Groups
75
+
76
+ Modeled from [ api-skeletons/doctrine-data-fixture] ( https://github.com/API-Skeletons/doctrine-data-fixture )
77
+ for Laminas, fixtures are organized into groups. This organization allows
78
+ fixtures for specific modules, development faker data, different entity
79
+ managers, and so on.
80
+
81
+
82
+ Use
83
+ ---
84
+
85
+ ### List Fixtures
86
+
87
+ List all groups or list all fixtures for a group.
88
+
89
+ ``` sh
90
+ php artisan doctrine:data-fixtures:list [< group> ]
91
+ ```
92
+
93
+ ### Executing Fixture Group through Artisan command
94
+ ---------------------------------------------------
95
+
96
+ ``` sh
97
+ php artisan doctrine:data-fixtures:import < group> [--purge-with-truncate] [--do-not-append]
98
+ ```
99
+
100
+ The ` <group> ` is required.
101
+
102
+ Append is the default option. This is inversed with --do-not-append
103
+
104
+ Options:
105
+
106
+ ` --purge-with-truncate ` if specified will purge the object manager's tables before
107
+ running fixtures for the ORMPurger only.
108
+
109
+ ` --do-not-append ` will delete all data in the database before running fixtures.
110
+
111
+
112
+ Executing Fixture Group from code
113
+ ---------------------------------
114
+
115
+ For unit testing or other times you must run your fixtures from within code,
116
+ follow this example:
117
+
118
+ ``` php
119
+ $config = $application['config']['doctrine-data-fixtures.' . $groupName];
120
+
121
+ $objectManager = $application->get($config['objectManager']);
122
+ $loader = $application->get($config['loader']);
123
+ $purger = $application->get($config['purger']);
124
+
125
+ foreach ($config['fixtures'] as $fixture) {
126
+ $loader->addFixture($fixture);
127
+ }
128
+
129
+ $executor->execute($loader->getFixtures());
130
+ ```
131
+
132
+
133
+ Doctrine data-fixtures
134
+ ----------------------
135
+
136
+ Be sure to read the documentation on the parent library
137
+ [ doctrine/data-fixtures] ( https://github.com/doctrine/data-fixtures )
0 commit comments