Skip to content

Commit

Permalink
fix: load entity factories
Browse files Browse the repository at this point in the history
  • Loading branch information
sstutz authored and Stefan Stutz committed Nov 27, 2024
1 parent 04915c1 commit b650efc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
22 changes: 22 additions & 0 deletions src/DoctrineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -68,6 +71,7 @@ public function register(): void
$this->registerExtensions();
$this->registerConsoleCommands();
$this->registerCustomTypes();
$this->registerEntityFactory();
$this->registerProxyAutoloader();

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

/**
* Register the Entity factory instance in the container.
*/
protected function registerEntityFactory(): void
{
$this->app->singleton(FakerGenerator::class, static function ($app) {
return FakerFactory::create($app['config']->get('app.faker_locale', 'en_US'));

Check warning on line 283 in src/DoctrineServiceProvider.php

View check run for this annotation

Codecov / codecov/patch

src/DoctrineServiceProvider.php#L283

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

$this->app->singleton(EntityFactory::class, static function ($app) {
return EntityFactory::construct(
$app->make(FakerGenerator::class),
$app->make('registry'),
database_path('factories'),

Check failure on line 290 in src/DoctrineServiceProvider.php

View workflow job for this annotation

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 warning on line 291 in src/DoctrineServiceProvider.php

View check run for this annotation

Codecov / codecov/patch

src/DoctrineServiceProvider.php#L287-L291

Added lines #L287 - L291 were not covered by tests
});
}

/**
* Register proxy autoloader
*/
Expand Down

0 comments on commit b650efc

Please sign in to comment.