@@ -7,7 +7,6 @@ use Doctrine\ORM\Mapping\Driver\AttributeDriver;
77use Doctrine \ORM \Mapping \Driver \SimplifiedXmlDriver ;
88use Doctrine \Persistence \Mapping \Driver \MappingDriverChain ;
99use Nette \DI \Compiler ;
10- use Nette \DI \InvalidConfigurationException ;
1110use Nettrine \DBAL \DI \DbalExtension ;
1211use Nettrine \ORM \DI \OrmExtension ;
1312use Tester \Assert ;
@@ -156,21 +155,20 @@ Toolkit::test(function (): void {
156155 Assert::equal ([DummyEntity::class], $ driver ->getAllClassNames ());
157156});
158157
159- // Empty mapping
158+ // Empty mapping (allowed for cases where mapping is defined in user's DI extension)
160159Toolkit::test (function (): void {
161- Assert::exception (function (): void {
162- ContainerBuilder::of ()
163- ->withCompiler (function (Compiler $ compiler ): void {
164- $ compiler ->addExtension ('nettrine.dbal ' , new DbalExtension ());
165- $ compiler ->addExtension ('nettrine.orm ' , new OrmExtension ());
166- $ compiler ->addConfig ([
167- 'parameters ' => [
168- 'tempDir ' => Tests::TEMP_PATH ,
169- 'fixturesDir ' => Tests::FIXTURES_PATH ,
170- ],
171- ]);
172- $ compiler ->addConfig (Neonkit::load (
173- <<<'NEON'
160+ $ container = ContainerBuilder::of ()
161+ ->withCompiler (function (Compiler $ compiler ): void {
162+ $ compiler ->addExtension ('nettrine.dbal ' , new DbalExtension ());
163+ $ compiler ->addExtension ('nettrine.orm ' , new OrmExtension ());
164+ $ compiler ->addConfig ([
165+ 'parameters ' => [
166+ 'tempDir ' => Tests::TEMP_PATH ,
167+ 'fixturesDir ' => Tests::FIXTURES_PATH ,
168+ ],
169+ ]);
170+ $ compiler ->addConfig (Neonkit::load (
171+ <<<'NEON'
174172 nettrine.dbal:
175173 connections:
176174 default:
@@ -184,8 +182,46 @@ Toolkit::test(function (): void {
184182 connection: default
185183 mapping: []
186184 NEON
187- ));
188- })
189- ->build ();
190- }, InvalidConfigurationException::class, "Failed assertion 'At least one mapping must be defined' for item 'nettrine.orm › managers › default › mapping' with value array. " );
185+ ));
186+ })
187+ ->build ();
188+
189+ /** @var MappingDriverChain $driver */
190+ $ driver = $ container ->getService ('nettrine.orm.managers.default.mappingDriver ' );
191+ Assert::count (0 , $ driver ->getDrivers ());
192+ });
193+
194+ // No mapping key at all (uses default empty array)
195+ Toolkit::test (function (): void {
196+ $ container = ContainerBuilder::of ()
197+ ->withCompiler (function (Compiler $ compiler ): void {
198+ $ compiler ->addExtension ('nettrine.dbal ' , new DbalExtension ());
199+ $ compiler ->addExtension ('nettrine.orm ' , new OrmExtension ());
200+ $ compiler ->addConfig ([
201+ 'parameters ' => [
202+ 'tempDir ' => Tests::TEMP_PATH ,
203+ 'fixturesDir ' => Tests::FIXTURES_PATH ,
204+ ],
205+ ]);
206+ $ compiler ->addConfig (Neonkit::load (
207+ <<<'NEON'
208+ nettrine.dbal:
209+ connections:
210+ default:
211+ driver: pdo_sqlite
212+ password: test
213+ user: test
214+ path: ":memory:"
215+ nettrine.orm:
216+ managers:
217+ default:
218+ connection: default
219+ NEON
220+ ));
221+ })
222+ ->build ();
223+
224+ /** @var MappingDriverChain $driver */
225+ $ driver = $ container ->getService ('nettrine.orm.managers.default.mappingDriver ' );
226+ Assert::count (0 , $ driver ->getDrivers ());
191227});
0 commit comments