Skip to content

Commit 967042e

Browse files
committed
Initial commit
0 parents  commit 967042e

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
/composer.lock

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Laravel Doctrine Data Fixtures
2+
------------------------------
3+
4+
Laravel has built-in support for 'seed' data. In seed data, the classes
5+
are not namespaced and many developers treat seed data as a one-time
6+
import. Seed data often uses auto-increment primary keys. Perhaps
7+
these notes are what differentiates seed data from Fixtures.
8+
9+
In my fixtures I want static primary keys and I want to be able to
10+
re-run my fixtures at any time. I want the data my fixtures populate
11+
to be stored with my fixtures and I want to reference fixture values
12+
though class constants within my code.
13+
14+
For instance, to validate a user has an ACL resource the code may
15+
read:
16+
17+
```php
18+
$acl->has($user, 'admin');
19+
```
20+
21+
but this use of strings in the code does not read well and may be
22+
error-prone. Instead of the above, I want my code to read
23+
24+
```php
25+
use App\ORM\Fixture\RoleFixture;
26+
27+
$acl->has($user, RoleFixture::admin);
28+
```
29+
30+
This pattern is not possible with seed data because seed data does
31+
not have namespaces. So, this repository exists not only as an
32+
alternative to Laravel seed data, but as an namespaced-integrated
33+
tool for static database data.

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "api-skeletons/laravel-doctrine-data-fixtures",
3+
"description": "Doctrine Data Fixtures for Laravel",
4+
"type": "library",
5+
"require": {
6+
"php": "^8.0",
7+
"doctrine/data-fixtures": "^1.5",
8+
"laravel/framework": "^8.82"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "^9.5"
12+
},
13+
"license": "MIT",
14+
"autoload": {
15+
"psr-4": {
16+
"ApiSkeletons\\LaravelDoctrineDataFixtures\\": "src/"
17+
}
18+
},
19+
"authors": [
20+
{
21+
"name": "Tom H Anderson",
22+
"email": "[email protected]"
23+
}
24+
]
25+
}

src/Command/ImportCommand.php

Whitespace-only changes.

src/Command/ListCommand.php

Whitespace-only changes.

test/TestCase.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace ApiSkeletonsTest\Laravel\Doctrine\DataFixture;
4+
5+
use ApiSkeletons\Laravel\HAL\Doctrine\ServiceProvider;
6+
use Doctrine\Laminas\Hydrator\DoctrineObject;
7+
use Doctrine\ORM\EntityManager;
8+
use Doctrine\ORM\Tools\SchemaTool;
9+
use Illuminate\Support\Facades\Route;
10+
use LaravelDoctrine\ORM\DoctrineServiceProvider;
11+
use Orchestra\Testbench\TestCase as OrchestraTestCase;
12+
13+
abstract class TestCase extends OrchestraTestCase
14+
{
15+
public function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
Route::get('address', function() {
20+
return true;
21+
})->name('api.address::fetchAll');
22+
Route::get('address/{id}', function() {
23+
return true;
24+
})->name('api.address::fetch');
25+
26+
Route::get('artist', function() {
27+
return true;
28+
})->name('api.artist::fetchAll');
29+
Route::get('artist/{id}', function() {
30+
return true;
31+
})->name('api.artist::fetch');
32+
33+
Route::get('performance', function() {
34+
return true;
35+
})->name('api.performance::fetchAll');
36+
Route::get('performance/{id}', function() {
37+
return true;
38+
})->name('api.performance::fetch');
39+
40+
Route::get('recording', function() {
41+
return true;
42+
})->name('api.recording::fetchAll');
43+
Route::get('recording/{id}', function() {
44+
return true;
45+
})->name('api.recording::fetch');
46+
47+
Route::get('user', function() {
48+
return true;
49+
})->name('api.user::fetchAll');
50+
Route::get('user/{id}', function() {
51+
return true;
52+
})->name('api.user::fetch');
53+
54+
}
55+
56+
protected function getPackageProviders($app)
57+
{
58+
return [
59+
DoctrineServiceProvider::class,
60+
ServiceProvider::class,
61+
];
62+
}
63+
64+
protected function getEnvironmentSetUp($app)
65+
{
66+
$app['config']['doctrine.managers.default.paths'] = [
67+
__DIR__ . '/config'
68+
];
69+
70+
$app['config']['doctrine.managers.default.namespaces'] = [
71+
'ApiSkeletonsTest\Laravel\HAL\Doctrine\Entity',
72+
];
73+
74+
$app['config']['doctrine.managers.default.meta'] = 'xml';
75+
76+
$app['config']['hal-doctrine'] = include(__DIR__ . '/config/hal-doctrine.php');
77+
78+
$app['config']['doctrine.custom_hydration_modes'] = [
79+
'hal-doctrine' => DoctrineObject::class,
80+
];
81+
}
82+
83+
protected function createDatabase(): EntityManager
84+
{
85+
$entityManager = app('em');
86+
$tool = new SchemaTool($entityManager);
87+
$tool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
88+
89+
return $entityManager;
90+
}
91+
}

0 commit comments

Comments
 (0)