Skip to content

Commit 973d294

Browse files
committed
Merge branch 'hotfix/76'
Close #76
2 parents 95c5e80 + a265695 commit 973d294

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/TableGatewayAbstractFactoryTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Laminas\Db\ResultSet\HydratingResultSet;
1717
use Laminas\Db\TableGateway\TableGateway;
1818
use Laminas\Hydrator\ClassMethods;
19+
use Laminas\Hydrator\ClassMethodsHydrator;
1920
use Laminas\Hydrator\HydratorPluginManager;
2021
use PHPUnit\Framework\TestCase;
2122

@@ -149,7 +150,8 @@ public function validConfig()
149150
*/
150151
public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration($adapterServiceName)
151152
{
152-
$hydrator = $this->prophesize(ClassMethods::class)->reveal();
153+
$hydrator = $this->prophesize($this->getClassMethodsHydratorClassName())->reveal();
154+
153155
$hydrators = $this->prophesize(HydratorPluginManager::class);
154156
$hydrators->get('ClassMethods')->willReturn($hydrator);
155157
$this->services->get('HydratorManager')->willReturn($hydrators->reveal());
@@ -199,7 +201,8 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration($adap
199201
*/
200202
public function testFactoryReturnsTableGatewayInstanceBasedOnConfigurationWithoutLaminasRest($adapterServiceName)
201203
{
202-
$hydrator = $this->prophesize(ClassMethods::class)->reveal();
204+
$hydrator = $this->prophesize($this->getClassMethodsHydratorClassName())->reveal();
205+
203206
$hydrators = $this->prophesize(HydratorPluginManager::class);
204207
$hydrators->get('ClassMethods')->willReturn($hydrator);
205208
$this->services->get('HydratorManager')->willReturn($hydrators->reveal());
@@ -236,7 +239,22 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfigurationWithou
236239
$this->assertSame($adapter->reveal(), $gateway->getAdapter());
237240
$resultSet = $gateway->getResultSetPrototype();
238241
$this->assertInstanceOf(HydratingResultSet::class, $resultSet);
239-
$this->assertInstanceOf(ClassMethods::class, $resultSet->getHydrator());
242+
$this->assertInstanceOf($this->getClassMethodsHydratorClassName(), $resultSet->getHydrator());
240243
$this->assertAttributeInstanceOf(TestAsset\Bar::class, 'objectPrototype', $resultSet);
241244
}
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+
}
242260
}

0 commit comments

Comments
 (0)