|
16 | 16 | use Laminas\Db\ResultSet\HydratingResultSet; |
17 | 17 | use Laminas\Db\TableGateway\TableGateway; |
18 | 18 | use Laminas\Hydrator\ClassMethods; |
| 19 | +use Laminas\Hydrator\ClassMethodsHydrator; |
19 | 20 | use Laminas\Hydrator\HydratorPluginManager; |
20 | 21 | use PHPUnit\Framework\TestCase; |
21 | 22 |
|
@@ -149,7 +150,8 @@ public function validConfig() |
149 | 150 | */ |
150 | 151 | public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration($adapterServiceName) |
151 | 152 | { |
152 | | - $hydrator = $this->prophesize(ClassMethods::class)->reveal(); |
| 153 | + $hydrator = $this->prophesize($this->getClassMethodsHydratorClassName())->reveal(); |
| 154 | + |
153 | 155 | $hydrators = $this->prophesize(HydratorPluginManager::class); |
154 | 156 | $hydrators->get('ClassMethods')->willReturn($hydrator); |
155 | 157 | $this->services->get('HydratorManager')->willReturn($hydrators->reveal()); |
@@ -199,7 +201,8 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration($adap |
199 | 201 | */ |
200 | 202 | public function testFactoryReturnsTableGatewayInstanceBasedOnConfigurationWithoutLaminasRest($adapterServiceName) |
201 | 203 | { |
202 | | - $hydrator = $this->prophesize(ClassMethods::class)->reveal(); |
| 204 | + $hydrator = $this->prophesize($this->getClassMethodsHydratorClassName())->reveal(); |
| 205 | + |
203 | 206 | $hydrators = $this->prophesize(HydratorPluginManager::class); |
204 | 207 | $hydrators->get('ClassMethods')->willReturn($hydrator); |
205 | 208 | $this->services->get('HydratorManager')->willReturn($hydrators->reveal()); |
@@ -236,7 +239,22 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfigurationWithou |
236 | 239 | $this->assertSame($adapter->reveal(), $gateway->getAdapter()); |
237 | 240 | $resultSet = $gateway->getResultSetPrototype(); |
238 | 241 | $this->assertInstanceOf(HydratingResultSet::class, $resultSet); |
239 | | - $this->assertInstanceOf(ClassMethods::class, $resultSet->getHydrator()); |
| 242 | + $this->assertInstanceOf($this->getClassMethodsHydratorClassName(), $resultSet->getHydrator()); |
240 | 243 | $this->assertAttributeInstanceOf(TestAsset\Bar::class, 'objectPrototype', $resultSet); |
241 | 244 | } |
| 245 | + |
| 246 | + /** |
| 247 | + * Simple check whether we should use ClassMethodsHydrator from laminas-hydrator 3 |
| 248 | + * as ClassMethods from < 3.0.0 is deprecated and triggers an E_USER_DEPRECATED error |
| 249 | + * |
| 250 | + * @return string |
| 251 | + */ |
| 252 | + private function getClassMethodsHydratorClassName() |
| 253 | + { |
| 254 | + if (class_exists(ClassMethodsHydrator::class)) { |
| 255 | + return ClassMethodsHydrator::class; |
| 256 | + } |
| 257 | + |
| 258 | + return ClassMethods::class; |
| 259 | + } |
242 | 260 | } |
0 commit comments