Skip to content

Commit

Permalink
Merge branch 'hotfix/76' into develop
Browse files Browse the repository at this point in the history
Forward port #76
  • Loading branch information
michalbundyra committed Apr 9, 2020
2 parents 990a67a + a265695 commit d332988
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions test/TableGatewayAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Laminas\Db\ResultSet\HydratingResultSet;
use Laminas\Db\TableGateway\TableGateway;
use Laminas\Hydrator\ClassMethods;
use Laminas\Hydrator\ClassMethodsHydrator;
use Laminas\Hydrator\HydratorPluginManager;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -149,7 +150,8 @@ public function validConfig()
*/
public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration($adapterServiceName)
{
$hydrator = $this->prophesize(ClassMethods::class)->reveal();
$hydrator = $this->prophesize($this->getClassMethodsHydratorClassName())->reveal();

$hydrators = $this->prophesize(HydratorPluginManager::class);
$hydrators->get('ClassMethods')->willReturn($hydrator);
$this->services->get('HydratorManager')->willReturn($hydrators->reveal());
Expand Down Expand Up @@ -199,7 +201,8 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration($adap
*/
public function testFactoryReturnsTableGatewayInstanceBasedOnConfigurationWithoutLaminasRest($adapterServiceName)
{
$hydrator = $this->prophesize(ClassMethods::class)->reveal();
$hydrator = $this->prophesize($this->getClassMethodsHydratorClassName())->reveal();

$hydrators = $this->prophesize(HydratorPluginManager::class);
$hydrators->get('ClassMethods')->willReturn($hydrator);
$this->services->get('HydratorManager')->willReturn($hydrators->reveal());
Expand Down Expand Up @@ -236,7 +239,22 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfigurationWithou
$this->assertSame($adapter->reveal(), $gateway->getAdapter());
$resultSet = $gateway->getResultSetPrototype();
$this->assertInstanceOf(HydratingResultSet::class, $resultSet);
$this->assertInstanceOf(ClassMethods::class, $resultSet->getHydrator());
$this->assertInstanceOf($this->getClassMethodsHydratorClassName(), $resultSet->getHydrator());
$this->assertAttributeInstanceOf(TestAsset\Bar::class, 'objectPrototype', $resultSet);
}

/**
* Simple check whether we should use ClassMethodsHydrator from laminas-hydrator 3
* as ClassMethods from < 3.0.0 is deprecated and triggers an E_USER_DEPRECATED error
*
* @return string
*/
private function getClassMethodsHydratorClassName()
{
if (class_exists(ClassMethodsHydrator::class)) {
return ClassMethodsHydrator::class;
}

return ClassMethods::class;
}
}

0 comments on commit d332988

Please sign in to comment.