diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..c2f179d --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -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 diff --git a/README.md b/README.md index eef2bb7..f7ad315 100644 --- a/README.md +++ b/README.md @@ -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 @@ -90,8 +89,10 @@ List all groups or list all fixtures for a group. php artisan doctrine:data-fixtures:list [] ``` -### Executing Fixture Group through Artisan command ---------------------------------------------------- +The `` is optional. + + +### Executing a Fixture Group through Artisan command ```sh php artisan doctrine:data-fixtures:import [--purge-with-truncate] [--do-not-append] @@ -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()); ``` diff --git a/composer.json b/composer.json index 715bfb5..6562b52 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..8dc065a --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/src/Console/Commands/ImportCommand.php b/src/Console/Commands/ImportCommand.php index 4dfea5b..d31da83 100644 --- a/src/Console/Commands/ImportCommand.php +++ b/src/Console/Commands/ImportCommand.php @@ -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.