File tree Expand file tree Collapse file tree 2 files changed +39
-9
lines changed
Expand file tree Collapse file tree 2 files changed +39
-9
lines changed Original file line number Diff line number Diff line change 233233
234234 });
235235
236+ it ('returns Expressive Middleware instance with create service first for mapped containers and config does not has "adapters" key ' , function () {
237+
238+ $ config = $ this ->config ;
239+ unset($ config ['db ' ]['adapters ' ]);
240+
241+ foreach ($ this ->mapCreateContainers as $ container ) {
242+ $ config ['log ' ]['ErrorHeroModuleLogger ' ]['writers ' ][0 ]['options ' ]['db ' ] = Adapter::class;
243+ allow ($ container )->toReceive ('get ' )->with ('config ' )
244+ ->andReturn ($ config );
245+
246+ allow ($ container )->toReceive ('has ' )->with (EntityManager::class)->andReturn (false );
247+
248+ $ logging = Double::instance (['extends ' => Logging::class, 'methods ' => '__construct ' ]);
249+ allow ($ container )->toReceive ('get ' )->with (Logging::class)
250+ ->andReturn ($ logging );
251+
252+ $ renderer = Double::instance (['implements ' => TemplateRendererInterface::class]);
253+ allow ($ container )->toReceive ('get ' )->with (TemplateRendererInterface::class)
254+ ->andReturn ($ renderer );
255+
256+ expect ($ container ->has ('ErrorHeroModuleLogger ' ))->toBeFalsy ();
257+ $ actual = $ this ->factory ($ container );
258+ expect ($ actual )->toBeAnInstanceOf (Expressive::class);
259+ expect ($ container ->has ('ErrorHeroModuleLogger ' ))->toBeTruthy ();
260+ }
261+
262+ });
263+
236264 it ('returns Expressive Middleware instance with create service first for mapped containers and db name found in adapters ' , function () {
237265
238266 foreach ($ this ->mapCreateContainers as $ container ) {
Original file line number Diff line number Diff line change @@ -16,23 +16,25 @@ private static function getWriterConfig(array $configuration) : array
1616
1717 protected static function getDbAdapterConfig (array $ configuration ) : array
1818 {
19- $ adapterName = Adapter::class;
20- $ writers = self ::getWriterConfig ($ configuration );
21- $ config = $ configuration ['db ' ];
19+ $ writers = self ::getWriterConfig ($ configuration );
20+ $ config = $ configuration ['db ' ];
21+
22+ if (! isset ($ config ['adapters ' ])) {
23+ return $ config ;
24+ }
2225
26+ $ adapterName = Adapter::class;
2327 foreach ($ writers as $ key => $ writer ) {
2428 if ($ writer ['name ' ] === 'db ' ) {
2529 $ adapterName = $ writer ['options ' ]['db ' ];
2630 break ;
2731 }
2832 }
2933
30- if (isset ($ config ['adapters ' ])) {
31- foreach ($ config ['adapters ' ] as $ key => $ adapterConfig ) {
32- if ($ adapterName === $ key ) {
33- $ config = $ adapterConfig ;
34- break ;
35- }
34+ foreach ($ config ['adapters ' ] as $ key => $ adapterConfig ) {
35+ if ($ adapterName === $ key ) {
36+ $ config = $ adapterConfig ;
37+ break ;
3638 }
3739 }
3840
You can’t perform that action at this time.
0 commit comments