Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
57 changes: 56 additions & 1 deletion tests/FactoryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'],
Expand All @@ -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 testConfigFolderWithIncorrect(): 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 testRemovePhpExtension(): 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',
);
}
}
4 changes: 3 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down