44
55use Illuminate \Contracts \Filesystem \FileNotFoundException ;
66use Illuminate \Support \Facades \Event ;
7- use org \bovigo \vfs \vfsStream ;
87use RonasIT \Support \Events \SuccessCreateMessage ;
98use RonasIT \Support \Exceptions \ClassAlreadyExistsException ;
109use RonasIT \Support \Exceptions \ClassNotExistsException ;
@@ -19,57 +18,45 @@ public function setUp(): void
1918 {
2019 parent ::setUp ();
2120
22- vfsStream::setup ();
23-
24- $ this ->generatedFileBasePath = vfsStream::url ('root ' );
25-
26- $ this ->app ->setBasePath ($ this ->generatedFileBasePath );
21+ Event::fake ();
2722 }
2823
2924 public function testControllerAlreadyExists ()
3025 {
31- Event::fake ();
32-
33- $ this ->expectException (ClassAlreadyExistsException::class);
34- $ this ->expectExceptionMessage ('Cannot create PostController cause PostController already exists. Remove PostController. ' );
35-
3626 $ this ->mockClass (ControllerGenerator::class, [
3727 $ this ->classExistsMethodCall (['controllers ' , 'PostController ' ])
3828 ]);
3929
30+ $ this ->expectException (ClassAlreadyExistsException::class);
31+ $ this ->expectExceptionMessage ('Cannot create PostController cause PostController already exists. Remove PostController. ' );
32+
4033 app (ControllerGenerator::class)
4134 ->setModel ('Post ' )
4235 ->generate ();
43-
44- Event::assertDispatched (SuccessCreateMessage::class);
4536 }
4637
4738 public function testModelServiceNotExists ()
4839 {
49- Event::fake ();
50-
51- $ this ->expectException (ClassNotExistsException::class);
52- $ this ->expectExceptionMessage ('Cannot create PostService cause PostService does not exists. Create a PostService by himself. ' );
53-
5440 $ this ->mockClass (ControllerGenerator::class, [
5541 $ this ->classExistsMethodCall (['controllers ' , 'PostController ' ], false ),
5642 $ this ->classExistsMethodCall (['services ' , 'PostService ' ], false )
5743 ]);
5844
45+ $ this ->expectException (ClassNotExistsException::class);
46+ $ this ->expectExceptionMessage ('Cannot create PostService cause PostService does not exists. Create a PostService by himself. ' );
47+
5948 app (ControllerGenerator::class)
6049 ->setModel ('Post ' )
6150 ->generate ();
62-
63- Event::assertDispatched (SuccessCreateMessage::class);
6451 }
6552
6653 public function testRouteFileNotExists ()
6754 {
55+ $ this ->mockFilesystemWithoutRoutesFile ();
56+
6857 $ this ->expectException (FileNotFoundException::class);
6958 $ this ->expectExceptionMessage ("Not found file with routes. Create a routes file on path: 'vfs://root/routes/api.php' " );
7059
71- $ this ->mockFilesystemWithoutRoutesFile ();
72-
7360 app (ControllerGenerator::class)
7461 ->setModel ('Post ' )
7562 ->setCrudOptions (['C ' , 'R ' , 'U ' , 'D ' ])
@@ -78,8 +65,6 @@ public function testRouteFileNotExists()
7865
7966 public function testCreate ()
8067 {
81- Event::fake ();
82-
8368 $ this ->mockFilesystem ();
8469
8570 app (ControllerGenerator::class)
@@ -92,6 +77,16 @@ public function testCreate()
9277 $ this ->assertGeneratedFileEquals ('created_controller.php ' , 'app/Http/Controllers/PostController.php ' );
9378 $ this ->assertGeneratedFileEquals ('api.php ' , 'routes/api.php ' );
9479
95- Event::assertDispatched (SuccessCreateMessage::class);
80+ Event::assertDispatchedTimes (SuccessCreateMessage::class, 6 );
81+ Event::assertDispatched (SuccessCreateMessage::class, function ($ event ) {
82+ return in_array ($ event ->message , [
83+ "Created a new Route: Route::post('posts', [PostController::class, 'create']); " ,
84+ "Created a new Route: Route::put('posts/{id}', [PostController::class, 'update']); " ,
85+ "Created a new Route: Route::delete('posts/{id}', [PostController::class, 'delete']); " ,
86+ "Created a new Route: Route::get('posts/{id}', [PostController::class, 'get']); " ,
87+ "Created a new Route: Route::get('posts', [PostController::class, 'search']); " ,
88+ "Created a new Controller: PostController " ,
89+ ]);
90+ });
9691 }
9792}
0 commit comments