22
33namespace RonasIT \Support \Tests ;
44
5+ use Illuminate \Support \Facades \Event ;
6+ use RonasIT \Support \Events \SuccessCreateMessage ;
7+ use RonasIT \Support \Events \WarningEvent ;
58use RonasIT \Support \Exceptions \ClassNotExistsException ;
69use RonasIT \Support \Generators \RepositoryGenerator ;
710use 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