Skip to content

Commit

Permalink
Merge pull request #2 from TomHAnderson/feature/prep-for-version
Browse files Browse the repository at this point in the history
Feature/prep for version
  • Loading branch information
TomHAnderson authored Feb 5, 2022
2 parents cf5b6d0 + 1242d75 commit 32ef2b4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Static analysis"

on:
pull_request:
branches:
- "*.x"
- "main"
push:
branches:
- "*.x"
- "main"

jobs:
psalm:
name: "Static Analysis"
runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.0'
- uses: actions/checkout@v2
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/psalm
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Laravel Doctrine Data Fixtures
------------------------------
# Laravel Doctrine Data Fixtures

Laravel has built-in support for 'seed' data. In seed data, the classes
are not namespaced and many developers treat seed data as a one-time
Expand Down Expand Up @@ -90,8 +89,10 @@ List all groups or list all fixtures for a group.
php artisan doctrine:data-fixtures:list [<group>]
```

### Executing Fixture Group through Artisan command
---------------------------------------------------
The `<group>` is optional.


### Executing a Fixture Group through Artisan command

```sh
php artisan doctrine:data-fixtures:import <group> [--purge-with-truncate] [--do-not-append]
Expand All @@ -109,23 +110,27 @@ running fixtures for the ORMPurger only.
`--do-not-append` will delete all data in the database before running fixtures.


Executing Fixture Group from code
Executing a Fixture Group from code
---------------------------------

For unit testing or other times you must run your fixtures from within code,
follow this example:

```php
$config = $application['config']['doctrine-data-fixtures.' . $groupName];
use use Doctrine\Common\DataFixtures\Loader;

$config = config('doctrine-data-fixtures')[$groupName];

$objectManager = $application->get($config['objectManager']);
$loader = $application->get($config['loader']);
$purger = $application->get($config['purger']);
$objectManager = app($config['objectManager']);
$purger = app($config['purger']);
$executorClass = $config['executor'];
$loader = new Loader();

foreach ($config['fixtures'] as $fixture) {
$loader->addFixture($fixture);
}

$executor = new $executorClass($objectManager, $purger);
$executor->execute($loader->getFixtures());
```

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
"require": {
"php": "^8.0",
"doctrine/data-fixtures": "^1.5",
"laravel/framework": "^8.82"
"laravel/framework": "^8.82",
"vimeo/psalm": "^4.20"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"doctrine/coding-standard": "^9.0",
"doctrine/dbal": "^2.13",
"laravel-doctrine/orm": "^1.7",
"orchestra/testbench": "^6.24"
},
Expand Down
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
6 changes: 5 additions & 1 deletion src/Console/Commands/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class ImportCommand extends Command
*
* @var string
*/
protected $signature = 'doctrine:data-fixtures:import {group} {--purge-with-truncate} {--do-not-append}';
protected $signature = 'doctrine:data-fixtures:import
{group : The fixtures group name}
{--purge-with-truncate : if specified will purge the object manager tables before running fixtures for the ORMPurger only}
{--do-not-append : will delete ALL data in the database before running fixtures}
';

/**
* The console command description.
Expand Down

0 comments on commit 32ef2b4

Please sign in to comment.