-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from TomHAnderson/feature/fixtures2
Feature/fixtures2
- Loading branch information
Showing
83 changed files
with
1,241 additions
and
948 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Doctrine\ORM\DataFixtures\Faker; | ||
|
||
use App\Doctrine\ORM\Entity\Artist as ArtistEntity; | ||
use DateTime; | ||
use Doctrine\Common\DataFixtures\FixtureInterface; | ||
use Doctrine\Laminas\Hydrator\DoctrineObject; | ||
use Doctrine\Persistence\ObjectManager; | ||
use Exception; | ||
|
||
/** | ||
* DataFixtures MAY be used to "fake" data. | ||
* Sometimes unit tests are dependent on fake data. | ||
*/ | ||
final class Faker implements | ||
FixtureInterface | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
$data = [ | ||
[ | ||
'name' => 'Grateful Dead', | ||
'recordings' => [ | ||
[ | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1995-02-21'), | ||
'venue' => 'Delta Center', | ||
'city' => 'Salt Lake City', | ||
'state' => 'UT', | ||
'recordings' => [ | ||
[ | ||
'source' => 'SBD> D> CD-R> EAC> SHN; via Jay Serafin, Brian ' | ||
. 'Walker; see info file and pub comments for notes; ' | ||
. 'possibly "click track" audible on a couple tracks', | ||
], | ||
['source' => 'DSBD > 1C > DAT; Seeded to etree by Dan Stephens'], | ||
], | ||
], | ||
[ | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1969-11-08'), | ||
'venue' => 'Fillmore Auditorium', | ||
'city' => 'San Francisco', | ||
'state' => 'CA', | ||
], | ||
[ | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1977-05-08'), | ||
'venue' => 'Barton Hall, Cornell University', | ||
'city' => 'Ithaca', | ||
'state' => 'NY', | ||
], | ||
[ | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1995-07-09'), | ||
'venue' => 'Soldier Field', | ||
'city' => 'Chicago', | ||
'state' => 'IL', | ||
], | ||
[ | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1995-08-09'), | ||
], | ||
], | ||
], | ||
[ | ||
'name' => 'Phish', | ||
'performances' => [ | ||
[ | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1998-11-02'), | ||
'venue' => 'The E Centre', | ||
'city' => 'West Valley City', | ||
'state' => 'UT', | ||
'recordings' => [ | ||
['source' => 'AKG480 > Aerco preamp > SBM-1'], | ||
], | ||
], | ||
[ | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1999-12-31'), | ||
'city' => 'Big Cypress', | ||
'state' => 'FL', | ||
], | ||
], | ||
], | ||
[ | ||
'name' => 'String Cheese Incident', | ||
'performances' => [ | ||
[ | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '2002-06-21'), | ||
'venue' => 'Bonnaroo', | ||
'city' => 'Manchester', | ||
'state' => 'TN', | ||
], | ||
], | ||
], | ||
[ | ||
'name' => 'The Beatles', | ||
'performances' => [ | ||
[ | ||
'venue' => 'The Ed Sullivan Show', | ||
'city' => 'New York', | ||
'state' => 'NY', | ||
'performanceDate' => DateTime::createFromFormat('Y-m-d', '1964-02-09'), | ||
], | ||
], | ||
], | ||
]; | ||
|
||
/** | ||
* Use the DoctrineObject hydrator to hydrate the entity. | ||
* This maintains a consistent pattern in all DataFixtures. | ||
*/ | ||
$hydrator = new DoctrineObject($manager); | ||
|
||
foreach ($data as $row) { | ||
$artist = $manager | ||
->getRepository(ArtistEntity::class) | ||
->findOneBy(['name' => $row['name']]); | ||
|
||
if ($artist) { | ||
throw new Exception('Faker data already exists in the database. Aborting.'); | ||
} | ||
|
||
$artist = new ArtistEntity(); | ||
|
||
// Magic? No! The hydrator understands the entity and its associations. | ||
$hydrator->hydrate($row, $artist); | ||
$manager->persist($artist); | ||
|
||
foreach ($artist->getPerformances() as $performance) { | ||
$manager->persist($performance); | ||
|
||
foreach ($performance->getRecordings() as $recording) { | ||
$manager->persist($recording); | ||
} | ||
} | ||
} | ||
|
||
$manager->flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,21 +8,21 @@ export default { | |
output: './public/docs', | ||
options: { | ||
siteRoot: `/docs`, | ||
appTitle: 'ldog Stack', | ||
appTitle: 'LDOG Stack', | ||
appLogo: 'https://raw.githubusercontent.com/API-Skeletons/ldog/main/public/ldog.svg', | ||
appFavicon: 'https://apiskeletons.com/images/favicon.ico', | ||
pages: [ | ||
{ | ||
title: 'Welcome', | ||
content: ` | ||
ldog Stack | ||
LDOG Stack | ||
========== | ||
Laravel, Doctrine ORM, and GraphQL | ||
---------------------------------- | ||
This is a template application for building GraphQL applications in | ||
Laravel with Doctrine ORM. **Known as the ldog (el-dog) Stack.** | ||
Laravel with Doctrine ORM. **Known as the LDOG (el-dog) Stack.** | ||
To create a new project run | ||
\`\`\` | ||
|
@@ -173,6 +173,27 @@ To ensure code quality, run \`composer test\` to run the following: | |
--- | ||
A project of [API Skeletons](mailto:[email protected]) | ||
* https://github.com/api-skeletons/ldog | ||
` | ||
}, | ||
{ | ||
title: 'Fixtures', | ||
content: ` | ||
Fixtures | ||
-------- | ||
Included with LDOG is a Doctrine fixture library. There are two included fixtures. To rebuild the | ||
SQLite database, copy \`.env.dev\` to \`.env\`, delete the \`~/database/database.sqlite\` file, and run | ||
\`\`\` | ||
rm database/database.sqlite | ||
php artisan doctrine:schema:create | ||
php artisan doctrine:data-fixture:import faker | ||
\`\`\` | ||
--- | ||
A project of [API Skeletons](mailto:[email protected]) | ||
* https://github.com/api-skeletons/ldog | ||
` | ||
|
Oops, something went wrong.