diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 5ffcdb81..c07df082 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -18,7 +18,6 @@ public function setUp(): void { parent::setUp(); - vfsStream::newDirectory('config')->at($this->rootDirectory); vfsStream::newDirectory('routes') ->at($this->rootDirectory) ->addChild(new vfsStreamFile('api.php')); diff --git a/tests/FactoryGeneratorTest.php b/tests/FactoryGeneratorTest.php index c2a9d2fd..0bd7bd17 100644 --- a/tests/FactoryGeneratorTest.php +++ b/tests/FactoryGeneratorTest.php @@ -2,12 +2,14 @@ namespace RonasIT\Support\Tests; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; use Illuminate\View\ViewException; use RonasIT\Support\Events\SuccessCreateMessage; use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; +use RonasIT\Support\Exceptions\IncorrectClassPathException; use RonasIT\Support\Generators\FactoryGenerator; use RonasIT\Support\Tests\Support\Factory\FactoryMockTrait; @@ -104,7 +106,7 @@ public function testCreateFactoryWithoutFactoryStub(): void config(['entity-generator.stubs.factory' => 'incorrect_stub']); - $result = app(FactoryGenerator::class) + app(FactoryGenerator::class) ->setFields([ 'integer-required' => ['author_id'], 'string' => ['title', 'iban', 'something'], @@ -125,4 +127,57 @@ className: WarningEvent::class, message: 'Generation of factory has been skipped cause the view incorrect_stub from the config entity-generator.stubs.factory is not exists. Please check that config has the correct view name value.', ); } + + public function testConfigFolderWithIncorrectCase(): void + { + $this->mockFilesystem(); + + Config::set('entity-generator.paths.factories', 'dAtaAbase/FactoorieesS'); + + $this->expectException(IncorrectClassPathException::class); + + $this->expectExceptionMessage('Incorrect path to factories, dAtaAbase folder must start with a capital letter, please specify the path according to the PSR.'); + + app(FactoryGenerator::class) + ->setFields([ + 'integer-required' => ['author_id'], + 'string' => ['title', 'iban', 'something'], + 'json' => ['json_text'], + ]) + ->setRelations([ + 'hasOne' => ['user'], + 'hasMany' => [], + 'belongsTo' => ['user'], + ]) + ->setModel('Post') + ->generate(); + } + + public function testConfigFolderWithExtension(): void + { + $this->mockFilesystem(); + + Config::set('entity-generator.paths.factories', 'database/factories/Factory.php'); + + app(FactoryGenerator::class) + ->setFields([ + 'integer-required' => ['author_id'], + 'string' => ['title', 'iban', 'something'], + 'json' => ['json_text'], + ]) + ->setRelations([ + 'hasOne' => ['user'], + 'hasMany' => [], + 'belongsTo' => ['user'], + ]) + ->setModel('Post') + ->generate(); + + $this->assertGeneratedFileEquals('post_factory.php', '/database/factories/PostFactory.php'); + + $this->assertEventPushed( + className: SuccessCreateMessage::class, + message: 'Created a new Factory: PostFactory', + ); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 1b4eac7f..3a232272 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -32,7 +32,9 @@ public function setUp(): void $this->rootDirectory = vfsStream::setup(); $this->generatedFileBasePath = vfsStream::url('root'); - + + vfsStream::newDirectory('config')->at($this->rootDirectory); + Event::fake(); $this->app->setBasePath($this->generatedFileBasePath);