77use Laminas \Db \Adapter \Driver \DriverInterface ;
88use Laminas \Db \Adapter \Adapter ;
99use Laminas \Db \Adapter \AdapterInterface ;
10- use Laminas \Db \Adapter \AdapterServiceFactory ;
11- use Laminas \Db \Adapter \Mysql \Container \AdapterManagerDelegator ;
10+ use Laminas \Db \Adapter \Mysql \ConfigProvider ;
1211use Laminas \Db \Adapter \Mysql \Driver \Mysqli \Mysqli ;
1312use Laminas \Db \Adapter \Mysql \Driver \Pdo \Pdo ;
1413use Laminas \Db \Container \AdapterManager ;
15- use Laminas \Db \Container \AdapterManagerFactory ;
14+ use Laminas \Db \Container \ConfigProvider as LaminasDbConfigProvider ;
1615use Laminas \ServiceManager \ServiceManager ;
1716use Laminas \Stdlib \ArrayUtils ;
1817
@@ -39,11 +38,12 @@ trait SetupTrait
3938 protected function setUp (): void
4039 {
4140 $ this ->getAdapter ();
41+ parent ::setUp ();
4242 }
4343
4444 protected function getAdapter (array $ config = []): AdapterInterface &Adapter
4545 {
46- $ baseConfig = [
46+ $ connectionConfig = [
4747 'db ' => [
4848 'driver ' => $ this ->driver ?? Pdo::class,
4949 'connection ' => [
@@ -61,28 +61,33 @@ protected function getAdapter(array $config = []): AdapterInterface&Adapter
6161 ],
6262 ];
6363
64+ // merge service config from both Laminas\Db and Laminas\Db\Adapter\Mysql
65+ $ serviceManagerConfig = ArrayUtils::merge (
66+ (new LaminasDbConfigProvider ())()['dependencies ' ],
67+ (new ConfigProvider ())()['dependencies ' ]
68+ );
69+
70+ $ serviceManagerConfig = ArrayUtils::merge (
71+ $ serviceManagerConfig ,
72+ $ connectionConfig
73+ );
74+
75+ // prefer passed config over environment variables
6476 if ($ config !== []) {
65- // If the config is not empty, merge it with the base config
66- // to allow for overriding or extending the default configuration.
67- $ baseConfig = ArrayUtils::merge ($ baseConfig , $ config );
77+ $ serviceManagerConfig = ArrayUtils::merge ($ serviceManagerConfig , $ config );
6878 }
69- $ this ->config = ArrayUtils::merge ($ this ->config , $ baseConfig );
7079
71- $ container = new ServiceManager ([
72- 'services ' => [
73- 'config ' => $ this ->config ,
74- ],
75- 'factories ' => [
76- AdapterInterface::class => AdapterServiceFactory::class,
77- AdapterManager::class => AdapterManagerFactory::class,
78- ],
79- 'delegators ' => [
80- AdapterManager::class => [
81- AdapterManagerDelegator::class,
80+ $ serviceManagerConfig = ArrayUtils::merge (
81+ $ serviceManagerConfig ,
82+ [
83+ 'services ' => [
84+ 'config ' => $ serviceManagerConfig ,
8285 ],
83- ],
84- ] );
86+ ]
87+ );
8588
89+ $ this ->config = $ serviceManagerConfig ;
90+ $ container = new ServiceManager ($ this ->config );
8691 $ this ->adapterManager = $ container ->get (AdapterManager::class);
8792 $ this ->adapter = $ this ->adapterManager ->get (AdapterInterface::class);
8893
0 commit comments