22
33namespace RonasIT \Support \Tests ;
44
5- use RonasIT \ Support \ EntityGeneratorServiceProvider ;
5+ use Carbon \ Carbon ;
66use RonasIT \Support \Exceptions \ClassNotExistsException ;
77use RonasIT \Support \Tests \Support \Command \CommandMockTrait ;
88use UnexpectedValueException ;
@@ -11,47 +11,101 @@ class CommandTest extends TestCase
1111{
1212 use CommandMockTrait;
1313
14- public function setUp (): void
15- {
16- parent ::setUp ();
17-
18- $ provider = new EntityGeneratorServiceProvider ($ this ->app );
19- $ provider ->boot ();
20- }
21-
2214 public function testCallWithInvalidCrudOption ()
2315 {
24- $ this ->expectException (UnexpectedValueException::class);
25- $ this ->expectErrorMessage ('Invalid method T ' );
16+ $ this ->assertExceptionThrew (
17+ className: UnexpectedValueException::class,
18+ message: 'Invalid method T ' ,
19+ );
2620
2721 $ this ->artisan ('make:entity Post --methods=T ' );
2822 }
2923
3024 public function testCallWithMissingModelService ()
3125 {
32- $ this ->mockConfigurations ();;
33-
34- $ this -> expectException (ClassNotExistsException::class);
35- $ this -> expectErrorMessage ( ' Cannot create API without entity. ' );
26+ $ this ->assertExceptionThrew (
27+ className: ClassNotExistsException::class,
28+ message: ' Cannot create API without entity. ' ,
29+ );
3630
3731 $ this ->artisan ('make:entity Post --only-api ' );
3832 }
3933
4034 public function testCallCommand ()
4135 {
42- $ this ->mockConfigurations ();
36+ Carbon::setTestNow ('2016-10-20 11:05:00 ' );
37+
4338 $ this ->mockFilesystem ();
39+ $ this ->mockGenerator ();
40+ $ this ->mockGettingModelInstance ();
4441
45- $ this ->artisan ('make:entity Post --methods=CRUD ' )
42+ $ this
43+ ->artisan ('make:entity Post --methods=CRUD ' )
4644 ->assertSuccessful ();
45+
46+ $ this ->assertGeneratedFileEquals ('migration.php ' , 'database/migrations/2016_10_20_110500_posts_create_table.php ' );
47+ $ this ->assertGeneratedFileEquals ('factory.php ' , 'database/factories/PostFactory.php ' );
48+ $ this ->assertGeneratedFileEquals ('seeder.php ' , 'database/seeders/PostSeeder.php ' );
49+ $ this ->assertGeneratedFileEquals ('model.php ' , 'app/Models/Post.php ' );
50+ $ this ->assertGeneratedFileEquals ('repository.php ' , 'app/Repositories/PostRepository.php ' );
51+ $ this ->assertGeneratedFileEquals ('service.php ' , 'app/Services/PostService.php ' );
52+ $ this ->assertGeneratedFileEquals ('create_request.php ' , 'app/Http/Requests/Post/CreatePostRequest.php ' );
53+ $ this ->assertGeneratedFileEquals ('get_request.php ' , 'app/Http/Requests/Post/GetPostRequest.php ' );
54+ $ this ->assertGeneratedFileEquals ('search_request.php ' , 'app/Http/Requests/Post/SearchPostsRequest.php ' );
55+ $ this ->assertGeneratedFileEquals ('update_request.php ' , 'app/Http/Requests/Post/UpdatePostRequest.php ' );
56+ $ this ->assertGeneratedFileEquals ('delete_request.php ' , 'app/Http/Requests/Post/DeletePostRequest.php ' );
57+ $ this ->assertGeneratedFileEquals ('controller.php ' , 'app/Http/Controllers/PostController.php ' );
58+ $ this ->assertGeneratedFileEquals ('resource.php ' , 'app/Http/Resources/Post/PostResource.php ' );
59+ $ this ->assertGeneratedFileEquals ('resource_collection.php ' , 'app/Http/Resources/Post/PostsCollectionResource.php ' );
60+ $ this ->assertGeneratedFileEquals ('routes.php ' , 'routes/api.php ' );
61+ $ this ->assertGeneratedFileEquals ('test.php ' , 'tests/PostTest.php ' );
62+ $ this ->assertGeneratedFileEquals ('dump.sql ' , 'tests/fixtures/PostTest/dump.sql ' );
63+ $ this ->assertGeneratedFileEquals ('create_request.json ' , 'tests/fixtures/PostTest/create_post_request.json ' );
64+ $ this ->assertGeneratedFileEquals ('create_response.json ' , 'tests/fixtures/PostTest/create_post_response.json ' );
65+ $ this ->assertGeneratedFileEquals ('update_request.json ' , 'tests/fixtures/PostTest/update_post_request.json ' );
66+ $ this ->assertGeneratedFileEquals ('validation.php ' , 'lang/en/validation.php ' );
67+ $ this ->assertGeneratedFileEquals ('nova_resource.php ' , 'app/Nova/PostResource.php ' );
68+ $ this ->assertGeneratedFileEquals ('nova_test.php ' , 'tests/NovaPostTest.php ' );
69+ $ this ->assertGeneratedFileEquals ('nova_dump.php ' , 'tests/fixtures/NovaPostTest/nova_post_dump.sql ' );
70+ $ this ->assertGeneratedFileEquals ('create_request.json ' , 'tests/fixtures/NovaPostTest/create_post_request.json ' );
71+ $ this ->assertGeneratedFileEquals ('create_response.json ' , 'tests/fixtures/NovaPostTest/create_post_response.json ' );
72+ $ this ->assertGeneratedFileEquals ('update_request.json ' , 'tests/fixtures/NovaPostTest/update_post_request.json ' );
4773 }
4874
4975 public function testMakeOnly ()
5076 {
51- $ this ->mockConfigurations ();
52- $ this ->mockFilesystem ();
77+ $ this ->mockFilesystemPostModelExists ();
5378
54- $ this ->artisan ('make:entity Post --methods=CRUD --only-repository ' )
79+ $ this
80+ ->artisan ('make:entity Post --methods=CRUD --only-repository ' )
5581 ->assertSuccessful ();
82+
83+ $ this ->assertGeneratedFileEquals ('repository.php ' , 'app/Repositories/PostRepository.php ' );
84+ $ this ->assertFileDoesNotExist ('database/migrations/2016_10_20_110500_posts_create_table.php ' );
85+ $ this ->assertFileDoesNotExist ('database/factories/PostFactory.php ' );
86+ $ this ->assertFileDoesNotExist ('database/seeders/PostSeeder.php ' );
87+ $ this ->assertFileDoesNotExist ('app/Models/Post.php ' );
88+ $ this ->assertFileDoesNotExist ('app/Services/PostService.php ' );
89+ $ this ->assertFileDoesNotExist ('app/Http/Requests/Post/CreatePostRequest.php ' );
90+ $ this ->assertFileDoesNotExist ('app/Http/Requests/Post/GetPostRequest.php ' );
91+ $ this ->assertFileDoesNotExist ('app/Http/Requests/Post/SearchPostsRequest.php ' );
92+ $ this ->assertFileDoesNotExist ('app/Http/Requests/Post/UpdatePostRequest.php ' );
93+ $ this ->assertFileDoesNotExist ('app/Http/Requests/Post/DeletePostRequest.php ' );
94+ $ this ->assertFileDoesNotExist ('app/Http/Controllers/PostController.php ' );
95+ $ this ->assertFileDoesNotExist ('app/Http/Resources/Post/PostResource.php ' );
96+ $ this ->assertFileDoesNotExist ('app/Http/Resources/Post/PostsCollectionResource.php ' );
97+ $ this ->assertFileDoesNotExist ('routes/api.php ' );
98+ $ this ->assertFileDoesNotExist ('tests/PostTest.php ' );
99+ $ this ->assertFileDoesNotExist ('tests/fixtures/PostTest/dump.sql ' );
100+ $ this ->assertFileDoesNotExist ('tests/fixtures/PostTest/create_post_request.json ' );
101+ $ this ->assertFileDoesNotExist ('tests/fixtures/PostTest/create_post_response.json ' );
102+ $ this ->assertFileDoesNotExist ('tests/fixtures/PostTest/update_post_request.json ' );
103+ $ this ->assertFileDoesNotExist ('lang/en/validation.php ' );
104+ $ this ->assertFileDoesNotExist ('app/Nova/PostResource.php ' );
105+ $ this ->assertFileDoesNotExist ('tests/NovaPostTest.php ' );
106+ $ this ->assertFileDoesNotExist ('tests/fixtures/NovaPostTest/nova_post_dump.sql ' );
107+ $ this ->assertFileDoesNotExist ('tests/fixtures/NovaPostTest/create_post_request.json ' );
108+ $ this ->assertFileDoesNotExist ('tests/fixtures/NovaPostTest/create_post_response.json ' );
109+ $ this ->assertFileDoesNotExist ('tests/fixtures/NovaPostTest/update_post_request.json ' );
56110 }
57111}
0 commit comments