Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: load entity factories
Browse files Browse the repository at this point in the history
sstutz committed Nov 27, 2024
1 parent 04915c1 commit 70ff8e2
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
"doctrine/dbal": "^3.0 || ^4.0",
"doctrine/orm": "^3.1",
"doctrine/persistence": "^3.3",
"fakerphp/faker": "^1.23",
"illuminate/auth": "^10.0|^11.0",
"illuminate/console": "^10.0|^11.0",
"illuminate/container": "^10.0|^11.0",
@@ -45,7 +46,6 @@
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpunit/phpunit": "^11.4",
"fakerphp/faker": "^1.23",
"laravel/framework": "^10.0 || ^11.0",
"orchestra/testbench": "^9.5"
},
24 changes: 24 additions & 0 deletions src/DoctrineServiceProvider.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Proxy\Autoloader;
use Doctrine\Persistence\ManagerRegistry;
use Faker\Factory as FakerFactory;
use Faker\Generator as FakerGenerator;
use Illuminate\Contracts\Container\Container;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\ServiceProvider;
@@ -31,6 +33,7 @@
use LaravelDoctrine\ORM\Exceptions\ExtensionNotFound;
use LaravelDoctrine\ORM\Extensions\ExtensionManager;
use LaravelDoctrine\ORM\Notifications\DoctrineChannel;
use LaravelDoctrine\ORM\Testing\Factory as EntityFactory;
use LaravelDoctrine\ORM\Validation\PresenceVerifierProvider;

use function assert;
@@ -68,6 +71,7 @@ public function register(): void
$this->registerExtensions();
$this->registerConsoleCommands();
$this->registerCustomTypes();
$this->registerEntityFactory();
$this->registerProxyAutoloader();

if (! $this->shouldRegisterDoctrinePresenceValidator()) {
@@ -270,6 +274,26 @@ public function extendNotificationChannel(): void
});
}

/**
* Register the Entity factory instance in the container.
*
* @return void

Check failure on line 280 in src/DoctrineServiceProvider.php

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.2)

Method \LaravelDoctrine\ORM\DoctrineServiceProvider::registerEntityFactory() has useless @return annotation.
*/
protected function registerEntityFactory(): void
{
$this->app->singleton(FakerGenerator::class, function ($app) {

Check failure on line 284 in src/DoctrineServiceProvider.php

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.2)

Closure not using "$this" should be declared static.
return FakerFactory::create($app['config']->get('app.faker_locale', 'en_US'));

Check warning on line 285 in src/DoctrineServiceProvider.php

Codecov / codecov/patch

src/DoctrineServiceProvider.php#L285

Added line #L285 was not covered by tests
});

$this->app->singleton(EntityFactory::class, function ($app) {

Check failure on line 288 in src/DoctrineServiceProvider.php

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.2)

Closure not using "$this" should be declared static.
return EntityFactory::construct(
$app->make(FakerGenerator::class),
$app->make('registry'),
database_path('factories')

Check failure on line 292 in src/DoctrineServiceProvider.php

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.2)

Function database_path() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 292 in src/DoctrineServiceProvider.php

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.2)

Multi-line function calls must have a trailing comma after the last parameter.
);

Check warning on line 293 in src/DoctrineServiceProvider.php

Codecov / codecov/patch

src/DoctrineServiceProvider.php#L289-L293

Added lines #L289 - L293 were not covered by tests
});
}

/**
* Register proxy autoloader
*/

0 comments on commit 70ff8e2

Please sign in to comment.