Skip to content

Commit 1cddc1f

Browse files
authored
Merge pull request #23 from TomHAnderson/feature/fixtures2
Feature/fixtures2
2 parents f32748d + ee2a236 commit 1cddc1f

File tree

83 files changed

+1241
-948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1241
-948
lines changed

.github/workflows/ldog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ jobs:
8181
env:
8282
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
8383

84-
- name: Import Fixturess
85-
run: php artisan doctrine:data-fixtures:import default
84+
- name: Import Fixtures
85+
run: php artisan doctrine:data-fixtures:import faker
8686
env:
8787
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
8888

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Doctrine\ORM\DataFixtures\Faker;
6+
7+
use App\Doctrine\ORM\Entity\Artist as ArtistEntity;
8+
use DateTime;
9+
use Doctrine\Common\DataFixtures\FixtureInterface;
10+
use Doctrine\Laminas\Hydrator\DoctrineObject;
11+
use Doctrine\Persistence\ObjectManager;
12+
use Exception;
13+
14+
/**
15+
* DataFixtures MAY be used to "fake" data.
16+
* Sometimes unit tests are dependent on fake data.
17+
*/
18+
final class Faker implements
19+
FixtureInterface
20+
{
21+
public function load(ObjectManager $manager): void
22+
{
23+
$data = [
24+
[
25+
'name' => 'Grateful Dead',
26+
'recordings' => [
27+
[
28+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1995-02-21'),
29+
'venue' => 'Delta Center',
30+
'city' => 'Salt Lake City',
31+
'state' => 'UT',
32+
'recordings' => [
33+
[
34+
'source' => 'SBD> D> CD-R> EAC> SHN; via Jay Serafin, Brian '
35+
. 'Walker; see info file and pub comments for notes; '
36+
. 'possibly "click track" audible on a couple tracks',
37+
],
38+
['source' => 'DSBD > 1C > DAT; Seeded to etree by Dan Stephens'],
39+
],
40+
],
41+
[
42+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1969-11-08'),
43+
'venue' => 'Fillmore Auditorium',
44+
'city' => 'San Francisco',
45+
'state' => 'CA',
46+
],
47+
[
48+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1977-05-08'),
49+
'venue' => 'Barton Hall, Cornell University',
50+
'city' => 'Ithaca',
51+
'state' => 'NY',
52+
],
53+
[
54+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1995-07-09'),
55+
'venue' => 'Soldier Field',
56+
'city' => 'Chicago',
57+
'state' => 'IL',
58+
],
59+
[
60+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1995-08-09'),
61+
],
62+
],
63+
],
64+
[
65+
'name' => 'Phish',
66+
'performances' => [
67+
[
68+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1998-11-02'),
69+
'venue' => 'The E Centre',
70+
'city' => 'West Valley City',
71+
'state' => 'UT',
72+
'recordings' => [
73+
['source' => 'AKG480 > Aerco preamp > SBM-1'],
74+
],
75+
],
76+
[
77+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1999-12-31'),
78+
'city' => 'Big Cypress',
79+
'state' => 'FL',
80+
],
81+
],
82+
],
83+
[
84+
'name' => 'String Cheese Incident',
85+
'performances' => [
86+
[
87+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '2002-06-21'),
88+
'venue' => 'Bonnaroo',
89+
'city' => 'Manchester',
90+
'state' => 'TN',
91+
],
92+
],
93+
],
94+
[
95+
'name' => 'The Beatles',
96+
'performances' => [
97+
[
98+
'venue' => 'The Ed Sullivan Show',
99+
'city' => 'New York',
100+
'state' => 'NY',
101+
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1964-02-09'),
102+
],
103+
],
104+
],
105+
];
106+
107+
/**
108+
* Use the DoctrineObject hydrator to hydrate the entity.
109+
* This maintains a consistent pattern in all DataFixtures.
110+
*/
111+
$hydrator = new DoctrineObject($manager);
112+
113+
foreach ($data as $row) {
114+
$artist = $manager
115+
->getRepository(ArtistEntity::class)
116+
->findOneBy(['name' => $row['name']]);
117+
118+
if ($artist) {
119+
throw new Exception('Faker data already exists in the database. Aborting.');
120+
}
121+
122+
$artist = new ArtistEntity();
123+
124+
// Magic? No! The hydrator understands the entity and its associations.
125+
$hydrator->hydrate($row, $artist);
126+
$manager->persist($artist);
127+
128+
foreach ($artist->getPerformances() as $performance) {
129+
$manager->persist($performance);
130+
131+
foreach ($performance->getRecordings() as $recording) {
132+
$manager->persist($recording);
133+
}
134+
}
135+
}
136+
137+
$manager->flush();
138+
}
139+
}

app/Doctrine/ORM/Entity/Artist.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,23 @@ public function getPerformances(): Collection
8787
{
8888
return $this->performances;
8989
}
90+
91+
public function addPerformances(ArrayCollection $performances): self
92+
{
93+
foreach ($performances as $performance) {
94+
$performance->setArtist($this);
95+
$this->addPerformance($performance);
96+
}
97+
98+
return $this;
99+
}
100+
101+
public function removePerformances(ArrayCollection $performances): self
102+
{
103+
foreach ($performances as $performance) {
104+
$this->removePerformance($performance);
105+
}
106+
107+
return $this;
108+
}
90109
}

app/Doctrine/ORM/Entity/Performance.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,27 @@ public function removeRecording(Recording $recording): bool
145145
return $this->recordings->removeElement($recording);
146146
}
147147

148+
/** @param mixed[] $recordings */
149+
public function addRecordings(Collection $recordings): self
150+
{
151+
foreach ($recordings as $recording) {
152+
$recording->setPerformance($this);
153+
$this->addRecording($recording);
154+
}
155+
156+
return $this;
157+
}
158+
159+
/** @param mixed[] $recordings */
160+
public function removeRecordings(Collection $recordings): self
161+
{
162+
foreach ($recordings as $recording) {
163+
$this->removeRecording($recording);
164+
}
165+
166+
return $this;
167+
}
168+
148169
/**
149170
* Get recordings.
150171
*

app/Doctrine/ORM/Entity/User.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
#[GraphQL\Entity(description: 'User', typeName: 'user')]
1414
class User
1515
{
16-
#[GraphQL\Field(description: 'User name')]
16+
#[GraphQL\Field(description: 'Name')]
1717
private string $name;
1818

19-
#[GraphQL\Field(description: 'User email')]
19+
#[GraphQL\Field(description: 'Email')]
2020
private string $email;
2121

22-
#[GraphQL\Field(description: 'User password')]
2322
private string $password;
2423

24+
#[GraphQL\Field(description: 'Role')]
25+
private string $role;
26+
2527
#[GraphQL\Field(description: 'Primary key')]
2628
private int $id;
2729

@@ -90,6 +92,18 @@ public function getPassword(): string
9092
return $this->password;
9193
}
9294

95+
public function setRole(string $role): self
96+
{
97+
$this->role = $role;
98+
99+
return $this;
100+
}
101+
102+
public function getRole(): string
103+
{
104+
return $this->role;
105+
}
106+
93107
/**
94108
* Get id.
95109
*/

config/doctrine-data-fixtures.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
declare(strict_types=1);
44

5+
use App\Doctrine\ORM\DataFixtures\Faker;
56
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
67
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
8+
use Doctrine\ORM\EntityManager;
79

810
/**
911
* In the default values listed below, ORM fixtures are configured. You may
@@ -16,16 +18,17 @@
1618
// The order of fixtures in the fixtures array is not the order in which
1719
// they will be executed. See
1820
// https://github.com/doctrine/data-fixtures#fixture-ordering
19-
/**
20-
Fixture1::class,
21-
Fixture2::class,
22-
*/
23-
2421
return [
2522
'default' => [ // Group name
26-
'objectManager' => 'Doctrine\ORM\EntityManager',
23+
'objectManager' => EntityManager::class,
2724
'executor' => ORMExecutor::class,
2825
'purger' => ORMPurger::class,
2926
'fixtures' => [],
3027
],
28+
'faker' => [ // Group name
29+
'objectManager' => EntityManager::class,
30+
'executor' => ORMExecutor::class,
31+
'purger' => ORMPurger::class,
32+
'fixtures' => [Faker\Faker::class],
33+
],
3134
];

config/doctrine-orm-metadata/App.Doctrine.ORM.Entity.User.dcm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<field name="name" type="string" nullable="false"/>
88
<field name="email" type="string" unique="true" nullable="false"/>
99
<field name="password" type="string" nullable="false"/>
10+
<field name="role" type="string" nullable="false"/>
1011
<many-to-many field="recordings" target-entity="App\Doctrine\ORM\Entity\Recording" inversed-by="users">
1112
<join-table name="RecordingToUser">
1213
<join-columns>

database/database.sqlite

100755100644
-80 KB
Binary file not shown.

ldog.skipper

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<field name="name" type="string" required="true" uuid="7f1988fe-14c8-4d3b-87c8-56ca5ed86385"/>
3030
<field name="email" type="string" required="true" unique="true" uuid="b7e9c340-9589-4400-8f97-1c2a8d95a758"/>
3131
<field name="password" type="string" required="true" uuid="a249742e-2404-4844-994e-a7ceaf35705d"/>
32+
<field name="role" type="string" enum-values="" required="true" uuid="e8d8604b-bc69-4dd4-a9ba-19514fb79623"/>
3233
</entity>
3334
<entity name="\App\Doctrine\ORM\Entity\RecordingToUser" local-name="RecordingToUser" namespace="\App\Doctrine\ORM\Entity" uuid="e5603f71-6798-480b-bcf8-0d185a08e653">
3435
<field name="user_id" type="integer" required="true" primary="true" uuid="6e73b00a-d350-44aa-9c5c-df5e8bd1b767"/>
@@ -51,14 +52,14 @@
5152
<visual-data>
5253
<association uuid="4f0247e2-6d76-42f9-b56b-52306c2fa201" caption1-position-x="0" caption1-position-y="0" center-position-x="0" center-position-y="0" color="#969696"/>
5354
<association uuid="ab34ba86-e61e-458a-87e7-9dfa2aa1f391" caption1-position-x="0" caption1-position-y="0" center-position-x="0" center-position-y="0" color="#969696"/>
54-
<comment uuid="0e4ff410-5025-42fd-89ae-0d05319ab49b" bg-color="#FFFFE0" position-x="283" position-y="253" size-x="6" size-x2="128" size-y="-3" size-y2="63" txt-color="#000000"/>
55+
<comment uuid="0e4ff410-5025-42fd-89ae-0d05319ab49b" bg-color="#FFFFE0" position-x="403" position-y="293" size-x="6" size-x2="128" size-y="-3" size-y2="63" txt-color="#000000"/>
5556
<entity uuid="10de66e4-a8b3-44a9-a6d0-a9fd28338fe2" bg-color="#FFFFFF" hdr-color="#D2D2D2" position-x="-23" position-y="-44" size-x="0" size-x2="77" size-y="0" size-y2="45"/>
5657
<entity uuid="568a03b7-3dd5-435a-9bc8-869bc673923c" bg-color="#FFFFFF" hdr-color="#D2D2D2" position-x="-23" position-y="136" size-x="0" size-x2="93" size-y="0" size-y2="73"/>
5758
<entity uuid="8a04b312-72bb-4723-baac-75502524ae38" bg-color="#FFFFFF" hdr-color="#D2D2D2" position-x="177" position-y="-44" size-x="0" size-x2="136" size-y="0" size-y2="101"/>
5859
<entity uuid="ad470906-9e63-41e7-9558-979789bc2d28" bg-color="#FFFFFF" hdr-color="#D2D2D2" position-x="177" position-y="136" size-x="0" size-x2="122" size-y="0" size-y2="59"/>
5960
<entity uuid="e5603f71-6798-480b-bcf8-0d185a08e653" bg-color="#FFFFFF" hdr-color="#D2D2D2" position-x="77" position-y="256" size-x="0" size-x2="109" size-y="0" size-y2="60"/>
6061
<many-to-many-association uuid="e4936d0d-1d1f-4fb8-af31-fa1d0665ccf7" color="#969696"/>
61-
<module uuid="d5f257f8-d854-4bae-a05d-1ed8673c7eb5" bg-color="#E1EDF0" position-x="43" position-y="84" size-x="43" size-x2="437" size-y="84" size-y2="376"/>
62-
<project uuid="25d2b513-c6b7-4071-9ada-7c48f127f426" size-x="50" size-x2="520" size-y="50" size-y2="500"/>
62+
<module uuid="d5f257f8-d854-4bae-a05d-1ed8673c7eb5" bg-color="#E1EDF0" position-x="43" position-y="84" size-x="43" size-x2="577" size-y="84" size-y2="376"/>
63+
<project uuid="25d2b513-c6b7-4071-9ada-7c48f127f426" size-x="50" size-x2="660" size-y="50" size-y2="500"/>
6364
</visual-data>
6465
</skipper>

magidoc.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ export default {
88
output: './public/docs',
99
options: {
1010
siteRoot: `/docs`,
11-
appTitle: 'ldog Stack',
11+
appTitle: 'LDOG Stack',
1212
appLogo: 'https://raw.githubusercontent.com/API-Skeletons/ldog/main/public/ldog.svg',
1313
appFavicon: 'https://apiskeletons.com/images/favicon.ico',
1414
pages: [
1515
{
1616
title: 'Welcome',
1717
content: `
18-
ldog Stack
18+
LDOG Stack
1919
==========
2020
2121
Laravel, Doctrine ORM, and GraphQL
2222
----------------------------------
2323
2424
This is a template application for building GraphQL applications in
25-
Laravel with Doctrine ORM. **Known as the ldog (el-dog) Stack.**
25+
Laravel with Doctrine ORM. **Known as the LDOG (el-dog) Stack.**
2626
2727
To create a new project run
2828
\`\`\`
@@ -173,6 +173,27 @@ To ensure code quality, run \`composer test\` to run the following:
173173
174174
---
175175
176+
A project of [API Skeletons](mailto:contact@apiskeletons.com)
177+
* https://github.com/api-skeletons/ldog
178+
`
179+
},
180+
{
181+
title: 'Fixtures',
182+
content: `
183+
Fixtures
184+
--------
185+
186+
Included with LDOG is a Doctrine fixture library. There are two included fixtures. To rebuild the
187+
SQLite database, copy \`.env.dev\` to \`.env\`, delete the \`~/database/database.sqlite\` file, and run
188+
189+
\`\`\`
190+
rm database/database.sqlite
191+
php artisan doctrine:schema:create
192+
php artisan doctrine:data-fixture:import faker
193+
\`\`\`
194+
195+
---
196+
176197
A project of [API Skeletons](mailto:contact@apiskeletons.com)
177198
* https://github.com/api-skeletons/ldog
178199
`

0 commit comments

Comments
 (0)