Skip to content

Commit 9b74a94

Browse files
authored
Merge pull request #148 from RonasIT/49-cover-entity-generator-with-tests
49 cover entity generator with tests
2 parents 6e80bef + 5eea910 commit 9b74a94

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

tests/CommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public function setUp(): void
1818
{
1919
parent::setUp();
2020

21-
vfsStream::newDirectory('config')->at($this->rootDirectory);
2221
vfsStream::newDirectory('routes')
2322
->at($this->rootDirectory)
2423
->addChild(new vfsStreamFile('api.php'));

tests/FactoryGeneratorTest.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace RonasIT\Support\Tests;
44

5+
use Illuminate\Support\Facades\Config;
56
use Illuminate\Support\Facades\Event;
67
use Illuminate\View\ViewException;
78
use RonasIT\Support\Events\SuccessCreateMessage;
89
use RonasIT\Support\Events\WarningEvent;
910
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
1011
use RonasIT\Support\Exceptions\ClassNotExistsException;
12+
use RonasIT\Support\Exceptions\IncorrectClassPathException;
1113
use RonasIT\Support\Generators\FactoryGenerator;
1214
use RonasIT\Support\Tests\Support\Factory\FactoryMockTrait;
1315

@@ -104,7 +106,7 @@ public function testCreateFactoryWithoutFactoryStub(): void
104106

105107
config(['entity-generator.stubs.factory' => 'incorrect_stub']);
106108

107-
$result = app(FactoryGenerator::class)
109+
app(FactoryGenerator::class)
108110
->setFields([
109111
'integer-required' => ['author_id'],
110112
'string' => ['title', 'iban', 'something'],
@@ -125,4 +127,57 @@ className: WarningEvent::class,
125127
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.',
126128
);
127129
}
130+
131+
public function testConfigFolderWithIncorrectCase(): void
132+
{
133+
$this->mockFilesystem();
134+
135+
Config::set('entity-generator.paths.factories', 'dAtaAbase/FactoorieesS');
136+
137+
$this->expectException(IncorrectClassPathException::class);
138+
139+
$this->expectExceptionMessage('Incorrect path to factories, dAtaAbase folder must start with a capital letter, please specify the path according to the PSR.');
140+
141+
app(FactoryGenerator::class)
142+
->setFields([
143+
'integer-required' => ['author_id'],
144+
'string' => ['title', 'iban', 'something'],
145+
'json' => ['json_text'],
146+
])
147+
->setRelations([
148+
'hasOne' => ['user'],
149+
'hasMany' => [],
150+
'belongsTo' => ['user'],
151+
])
152+
->setModel('Post')
153+
->generate();
154+
}
155+
156+
public function testConfigFolderWithExtension(): void
157+
{
158+
$this->mockFilesystem();
159+
160+
Config::set('entity-generator.paths.factories', 'database/factories/Factory.php');
161+
162+
app(FactoryGenerator::class)
163+
->setFields([
164+
'integer-required' => ['author_id'],
165+
'string' => ['title', 'iban', 'something'],
166+
'json' => ['json_text'],
167+
])
168+
->setRelations([
169+
'hasOne' => ['user'],
170+
'hasMany' => [],
171+
'belongsTo' => ['user'],
172+
])
173+
->setModel('Post')
174+
->generate();
175+
176+
$this->assertGeneratedFileEquals('post_factory.php', '/database/factories/PostFactory.php');
177+
178+
$this->assertEventPushed(
179+
className: SuccessCreateMessage::class,
180+
message: 'Created a new Factory: PostFactory',
181+
);
182+
}
128183
}

tests/TestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public function setUp(): void
3232
$this->rootDirectory = vfsStream::setup();
3333

3434
$this->generatedFileBasePath = vfsStream::url('root');
35-
35+
36+
vfsStream::newDirectory('config')->at($this->rootDirectory);
37+
3638
Event::fake();
3739

3840
$this->app->setBasePath($this->generatedFileBasePath);

0 commit comments

Comments
 (0)