|
89 | 89 |
|
90 | 90 | }); |
91 | 91 |
|
92 | | - it('has EntityManager service but already does not has db config', function () { |
| 92 | + it('has EntityManager service but already does not has db config not isset driverOptions', function () { |
93 | 93 |
|
94 | 94 | $moduleEvent = Double::instance(['extends' => ModuleEvent::class, 'methods' => '__construct']); |
95 | 95 | $serviceManager = Double::instance(['implements' => ServiceLocatorInterface::class]); |
|
106 | 106 | $driver = Double::instance(['extends' => Driver::class, 'methods' => '__construct']); |
107 | 107 | allow($driver)->toReceive('getName')->andReturn('pdo_mysql'); |
108 | 108 |
|
| 109 | + allow($connection)->toReceive('getParams')->andReturn([]); |
| 110 | + allow($connection)->toReceive('getUsername')->andReturn('root'); |
| 111 | + allow($connection)->toReceive('getPassword')->andReturn(''); |
| 112 | + allow($connection)->toReceive('getDriver')->andReturn($driver); |
| 113 | + allow($connection)->toReceive('getDatabase')->andReturn('mydb'); |
| 114 | + allow($connection)->toReceive('getHost')->andReturn('localhost'); |
| 115 | + allow($connection)->toReceive('getPort')->andReturn('3306'); |
| 116 | + |
| 117 | + allow($entityManager)->toReceive('getConnection')->andReturn($connection); |
| 118 | + allow($serviceManager)->toReceive('get')->with(EntityManager::class)->andReturn($entityManager); |
| 119 | + |
| 120 | + $this->module->convertDoctrineToZendDbConfig($moduleEvent); |
| 121 | + expect($serviceManager)->toReceive('get')->with(EntityManager::class); |
| 122 | + |
| 123 | + }); |
| 124 | + |
| 125 | + it('has EntityManager service but already does not has db config with isset driverOptions', function () { |
| 126 | + |
| 127 | + $moduleEvent = Double::instance(['extends' => ModuleEvent::class, 'methods' => '__construct']); |
| 128 | + $serviceManager = Double::instance(['implements' => ServiceLocatorInterface::class]); |
| 129 | + allow($moduleEvent)->toReceive('getParam')->with('ServiceManager')->andReturn($serviceManager); |
| 130 | + allow($serviceManager)->toReceive('has')->with(EntityManager::class)->andReturn(true); |
| 131 | + |
| 132 | + $configListener = Double::instance(['extends' => ConfigListener::class, 'methods' => '__construct']); |
| 133 | + allow($moduleEvent)->toReceive('getConfigListener')->andReturn($configListener); |
| 134 | + allow($configListener)->toReceive('getMergedConfig')->andReturn([]); |
| 135 | + |
| 136 | + $entityManager = Double::instance(['extends' => EntityManager::class, 'methods' => '__construct']); |
| 137 | + $connection = Double::instance(['extends' => Connection::class, 'methods' => '__construct']); |
| 138 | + |
| 139 | + $driver = Double::instance(['extends' => Driver::class, 'methods' => '__construct']); |
| 140 | + allow($driver)->toReceive('getName')->andReturn('pdo_mysql'); |
| 141 | + |
| 142 | + allow($connection)->toReceive('getParams')->andReturn([ |
| 143 | + 'driverOptions' => [ |
| 144 | + \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'', |
| 145 | + ], |
| 146 | + ]); |
109 | 147 | allow($connection)->toReceive('getUsername')->andReturn('root'); |
110 | 148 | allow($connection)->toReceive('getPassword')->andReturn(''); |
111 | 149 | allow($connection)->toReceive('getDriver')->andReturn($driver); |
|
0 commit comments