22
33namespace RonasIT \Support \Tests ;
44
5+ use Illuminate \Support \Facades \Config ;
56use Illuminate \Support \Facades \Event ;
67use Illuminate \View \ViewException ;
78use RonasIT \Support \Events \SuccessCreateMessage ;
89use RonasIT \Support \Events \WarningEvent ;
910use RonasIT \Support \Exceptions \ClassAlreadyExistsException ;
1011use RonasIT \Support \Exceptions \ClassNotExistsException ;
12+ use RonasIT \Support \Exceptions \IncorrectClassPathException ;
1113use RonasIT \Support \Generators \FactoryGenerator ;
1214use 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}
0 commit comments