Skip to content

Commit 97931b2

Browse files
committed
feat: add tests
refs: #49
1 parent adff8ab commit 97931b2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/RepositoryGeneratorTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace RonasIT\Support\Tests;
44

5+
use Illuminate\Support\Facades\Event;
6+
use RonasIT\Support\Events\SuccessCreateMessage;
7+
use RonasIT\Support\Events\WarningEvent;
58
use RonasIT\Support\Exceptions\ClassNotExistsException;
69
use RonasIT\Support\Generators\RepositoryGenerator;
710
use RonasIT\Support\Tests\Support\Repository\RepositoryMockTrait;
@@ -10,6 +13,13 @@ class RepositoryGeneratorTest extends TestCase
1013
{
1114
use RepositoryMockTrait;
1215

16+
public function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
Event::fake();
21+
}
22+
1323
public function testModelDoesntExists()
1424
{
1525
$this->mockGeneratorForMissingModel();
@@ -23,6 +33,8 @@ className: ClassNotExistsException::class,
2333
app(RepositoryGenerator::class)
2434
->setModel('Post')
2535
->generate();
36+
37+
$this->assertFileDoesNotExist('repository.php', 'app/Repositories/PostRepository.php');
2638
}
2739

2840
public function testCreateRepository()
@@ -34,5 +46,28 @@ public function testCreateRepository()
3446
->generate();
3547

3648
$this->assertGeneratedFileEquals('repository.php', 'app/Repositories/PostRepository.php');
49+
50+
$this->assertEventPushed(
51+
className: SuccessCreateMessage::class,
52+
message: 'Created a new Repository: PostRepository',
53+
);
54+
}
55+
56+
public function testCreateRepositoryStubNotExist()
57+
{
58+
config(['entity-generator.stubs.repository' => 'incorrect_stub']);
59+
60+
$this->mockFilesystem();
61+
62+
app(RepositoryGenerator::class)
63+
->setModel('Post')
64+
->generate();
65+
66+
$this->assertFileDoesNotExist('repository.php', 'app/Repositories/PostRepository.php');
67+
68+
$this->assertEventPushed(
69+
className: WarningEvent::class,
70+
message: 'Generation of repository has been skipped cause the view incorrect_stub from the config entity-generator.stubs.repository is not exists. Please check that config has the correct view name value.',
71+
);
3772
}
3873
}

0 commit comments

Comments
 (0)