@@ -82,6 +82,7 @@ public function test_it_should_load_metadata_for_mappings_passed_as_constructor_
8282 StubEntity::class,
8383 new ClassMetadataInfo (StubEntity::class)
8484 );
85+
8586 $ this ->assertInstanceOf (
8687 EntityMapper::class,
8788 $ driver ->getMappers ()->getMapperFor (StubEntity::class)
@@ -91,6 +92,7 @@ public function test_it_should_load_metadata_for_mappings_passed_as_constructor_
9192 StubEmbeddable::class,
9293 new ClassMetadataInfo (StubEmbeddable::class)
9394 );
95+
9496 $ this ->assertInstanceOf (
9597 EmbeddableMapper::class,
9698 $ driver ->getMappers ()->getMapperFor (StubEmbeddable::class)
@@ -100,6 +102,7 @@ public function test_it_should_load_metadata_for_mappings_passed_as_constructor_
100102 StubMappedSuperClass::class,
101103 new ClassMetadataInfo (StubMappedSuperClass::class)
102104 );
105+
103106 $ this ->assertInstanceOf (
104107 MappedSuperClassMapper::class,
105108 $ driver ->getMappers ()->getMapperFor (StubMappedSuperClass::class)
@@ -126,9 +129,96 @@ public function test_can_add_array_of_new_mappings()
126129 );
127130 }
128131
132+ public function test_can_load_mappings_through_file_path ()
133+ {
134+ $ driver = new FluentDriver ([], [__DIR__ . '/ ' . 'Stubs/Mappings ' ]);
135+
136+ $ this ->assertContains (
137+ StubEntity::class,
138+ $ driver ->getAllClassNames ()
139+ );
140+
141+ $ this ->assertContains (
142+ StubEmbeddable::class,
143+ $ driver ->getAllClassNames ()
144+ );
145+
146+ $ this ->assertContains (
147+ StubMappedSuperClass::class,
148+ $ driver ->getAllClassNames ()
149+ );
150+
151+ $ driver ->loadMetadataForClass (
152+ StubEntity::class,
153+ new ClassMetadataInfo (StubEntity::class)
154+ );
155+
156+ $ this ->assertInstanceOf (
157+ EntityMapper::class,
158+ $ driver ->getMappers ()->getMapperFor (StubEntity::class)
159+ );
160+
161+ $ driver ->loadMetadataForClass (
162+ StubEmbeddable::class,
163+ new ClassMetadataInfo (StubEmbeddable::class)
164+ );
165+
166+ $ this ->assertInstanceOf (
167+ EmbeddableMapper::class,
168+ $ driver ->getMappers ()->getMapperFor (StubEmbeddable::class)
169+ );
170+
171+ $ driver ->loadMetadataForClass (
172+ StubMappedSuperClass::class,
173+ new ClassMetadataInfo (StubMappedSuperClass::class)
174+ );
175+
176+ $ this ->assertInstanceOf (
177+ MappedSuperClassMapper::class,
178+ $ driver ->getMappers ()->getMapperFor (StubMappedSuperClass::class)
179+ );
180+ }
181+
182+ public function test_can_load_paths ()
183+ {
184+ $ driver = new FluentDriver ();
185+ $ driver ->loadPaths ([__DIR__ . '/ ' . 'Stubs/Mappings ' ]);
186+
187+ $ this ->assertContains (
188+ StubEntity::class,
189+ $ driver ->getAllClassNames ()
190+ );
191+
192+ $ this ->assertContains (
193+ StubEmbeddable::class,
194+ $ driver ->getAllClassNames ()
195+ );
196+
197+ $ this ->assertContains (
198+ StubMappedSuperClass::class,
199+ $ driver ->getAllClassNames ()
200+ );
201+ }
202+
203+ public function test_loading_by_paths_throws_exception_if_dir_not_exists ()
204+ {
205+ $ folder = __DIR__ . '/ ' . 'Stubs/non-existing-folder ' ;
206+
207+ $ this ->setExpectedException (
208+ MappingException::class,
209+ 'File mapping drivers must have a valid directory path, however the given path [ ' . $ folder . '] seems to be incorrect! '
210+ );
211+
212+ $ driver = new FluentDriver ();
213+ $ driver ->loadPaths ([$ folder ]);
214+
215+ $ driver ->getAllClassNames ();
216+ }
217+
129218 public function test_the_given_mapping_class_should_exist ()
130219 {
131- $ this ->setExpectedException (\InvalidArgumentException::class, 'Mapping class [Tests\DoesnExist] does not exist ' );
220+ $ this ->setExpectedException (\InvalidArgumentException::class,
221+ 'Mapping class [Tests\DoesnExist] does not exist ' );
132222
133223 $ driver = new FluentDriver ;
134224
@@ -139,7 +229,8 @@ public function test_the_given_mapping_class_should_exist()
139229
140230 public function test_the_given_mapping_class_should_implement_mapping ()
141231 {
142- $ this ->setExpectedException (\InvalidArgumentException::class, 'Mapping class [Tests\Stubs\Entities\StubEntity] should implement LaravelDoctrine\Fluent\Mapping ' );
232+ $ this ->setExpectedException (\InvalidArgumentException::class,
233+ 'Mapping class [Tests\Stubs\Entities\StubEntity] should implement LaravelDoctrine\Fluent\Mapping ' );
143234
144235 $ driver = new FluentDriver ;
145236
0 commit comments