Skip to content

Commit

Permalink
fix: fix model mock for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Lapkovsky committed Nov 17, 2023
1 parent e6adec0 commit 82dbbd8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,6 @@ Since 1.3 version you need to add to your config/entity-generator.php following
'translation_not_found' => 'entity-generator::translation_not_found',
'validation' => 'entity-generator::validation',
'seeder' => 'entity-generator::seeder',
'database_empty_seeder' => 'entity-generator::database_seed_empty'
'database_empty_seeder' => 'entity-generator::database_empty_seeder'
]
```
10 changes: 6 additions & 4 deletions src/Generators/TestsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace RonasIT\Support\Generators;

use Illuminate\Database\Eloquent\Factory;
use Illuminate\Database\Eloquent\Factory as LegacyFactories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use RonasIT\Support\Exceptions\CircularRelationsFoundedException;
Expand Down Expand Up @@ -75,7 +76,7 @@ protected function getInserts()

protected function isFactoryExists($modelName)
{
$factory = app(Factory::class);
$factory = app(LegacyFactories::class);
$modelClass = $this->getModelClass($modelName);

$isNewStyleFactoryExists = $this->classExists('factory', "{$modelName}Factory") && method_exists($modelClass, 'factory');
Expand Down Expand Up @@ -160,8 +161,9 @@ protected function getModelFields($model)
protected function getMockModel($model)
{
$modelClass = $this->getModelClass($model);

$factory = (method_exists($modelClass, 'factory')) ? $modelClass::factory() : factory($modelClass);
$useModelClassFactory = method_exists($modelClass, 'factory')
&& class_exists(Factory::resolveFactoryName($modelClass));
$factory = ($useModelClassFactory) ? $modelClass::factory() : factory($modelClass);

return $factory
->make()
Expand Down

0 comments on commit 82dbbd8

Please sign in to comment.