Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/7672' into release-2.7
Browse files Browse the repository at this point in the history
Close #54
  • Loading branch information
weierophinney committed Feb 16, 2016
2 parents e0a88d2 + d782694 commit b894a85
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ matrix:
- php: 7
- php: hhvm
allow_failures:
- php: 7
- php: hhvm

notifications:
Expand All @@ -36,7 +35,7 @@ before_install:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs
- COMPOSER_ROOT_VERSION=2.7.99 travis_retry composer install --no-interaction --ignore-platform-reqs

script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.7.5 - 2016-02-16

### Added

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#54](https://github.com/zendframework/zend-stdlib/pull/54) updates the
`HelperPluginManager` implementation to return zend-stdlib-specific instances
(instead of zend-hydrator instances), to ensure backwards compatibility when
typehinting against the zend-stdlib types.

## 2.7.4 - 2015-10-15

### Added
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"require": {
"php": ">=5.5",
"php": "^5.5 || ^7.0",
"zendframework/zend-hydrator": "~1.0"
},
"require-dev": {
Expand All @@ -37,8 +37,9 @@
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "2.7-dev",
"dev-develop": "2.8-dev"
"dev-release-2.7": "2.7-dev",
"dev-master": "3.0-dev",
"dev-develop": "3.1-dev"
}
},
"autoload-dev": {
Expand Down
11 changes: 9 additions & 2 deletions src/Hydrator/DelegatingHydratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@

namespace Zend\Stdlib\Hydrator;

use Zend\Hydrator\DelegatingHydratorFactory as BaseDelegatingHydratorFactory;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @deprecated Use Zend\Hydrator\DelegatingHydratorFactory from zendframework/zend-hydrator instead.
*/
class DelegatingHydratorFactory extends BaseDelegatingHydratorFactory
class DelegatingHydratorFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
// Assume that this factory is registered with the HydratorManager,
// and just pass it directly on.
return new DelegatingHydrator($serviceLocator);
}
}
30 changes: 30 additions & 0 deletions src/Hydrator/HydratorPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,34 @@
*/
class HydratorPluginManager extends BaseHydratorPluginManager
{
/**
* Default aliases
*
* @var array
*/
protected $aliases = [
'delegatinghydrator' => 'Zend\Stdlib\Hydrator\DelegatingHydrator',
];

/**
* Default set of adapters
*
* @var array
*/
protected $invokableClasses = [
'arrayserializable' => 'Zend\Stdlib\Hydrator\ArraySerializable',
'classmethods' => 'Zend\Stdlib\Hydrator\ClassMethods',
'objectproperty' => 'Zend\Stdlib\Hydrator\ObjectProperty',
'reflection' => 'Zend\Stdlib\Hydrator\Reflection'
];

/**
* Default factory-based adapters
*
* @var array
*/
protected $factories = [
'Zend\Stdlib\Hydrator\DelegatingHydrator' => 'Zend\Stdlib\Hydrator\DelegatingHydratorFactory',
'zendstdlibhydratordelegatinghydrator' => 'Zend\Stdlib\Hydrator\DelegatingHydratorFactory',
];
}
113 changes: 113 additions & 0 deletions test/Hydrator/HydratorPluginManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-stdlib for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Stdlib\Hydrator;

use PHPUnit_Framework_TestCase as TestCase;
use ReflectionProperty;
use Zend\Hydrator\HydratorPluginManager as BasePluginManager;
use Zend\Stdlib\Hydrator\HydratorInterface;
use Zend\Stdlib\Hydrator\HydratorPluginManager;

class HydratorPluginManagerTest extends TestCase
{
public function setUp()
{
$this->hydrators = new HydratorPluginManager();
}

public function testExtendsZendHydratorPluginManager()
{
$this->assertInstanceOf(BasePluginManager::class, $this->hydrators);
}

public function aliases()
{
$hydrators = new HydratorPluginManager();
$r = new ReflectionProperty($hydrators, 'aliases');
$r->setAccessible(true);
foreach ($r->getValue($hydrators) as $alias => $target) {
yield $alias => [$alias, $target];
}
}

/**
* @dataProvider aliases
*/
public function testAllAliasesReturnStdlibEquivalents($alias, $expected)
{
$this->assertContains('\\Stdlib\\', $expected, 'Alias target is not a Stdlib class?');

$hydrator = $this->hydrators->get($alias);
$this->assertInstanceOf(
$expected,
$hydrator,
sprintf('Alias %s did not retrieve expected %s instance; got %s', $alias, $expected, get_class($hydrator))
);
$this->assertInstanceOf(
HydratorInterface::class,
$hydrator,
sprintf('Alias %s resolved to %s, which is not a HydratorInterface instance', $alias, get_class($hydrator))
);
}

public function invokables()
{
$hydrators = new HydratorPluginManager();
$r = new ReflectionProperty($hydrators, 'invokableClasses');
$r->setAccessible(true);
foreach ($r->getValue($hydrators) as $name => $target) {
yield $name => [$name, $target];
}
}

/**
* @dataProvider invokables
*/
public function testAllInvokablesReturnStdlibInstances($name, $expected)
{
$this->assertContains('\\Stdlib\\', $expected, 'Invokable target is not a Stdlib class?');

$hydrator = $this->hydrators->get($name);
$this->assertInstanceOf($expected, $hydrator, sprintf(
'Invokable %s did not retrieve expected %s instance; got %s',
$name,
$expected,
get_class($hydrator)
));
$this->assertInstanceOf(HydratorInterface::class, $hydrator, sprintf(
'Invokable %s resolved to %s, which is not a HydratorInterface instance',
$name,
get_class($hydrator)
));
}

public function factories()
{
$hydrators = new HydratorPluginManager();
$r = new ReflectionProperty($hydrators, 'factories');
$r->setAccessible(true);
foreach ($r->getValue($hydrators) as $name => $factory) {
yield $name => [$name, $factory];
}
}

/**
* @dataProvider factories
*/
public function testAllFactoriesReturnStdlibInstances($name, $factory)
{
$hydrator = $this->hydrators->get($name);
$this->assertInstanceOf(HydratorInterface::class, $hydrator, sprintf(
'Factory for %s resolved to %s, which is not a HydratorInterface instance',
$name,
get_class($hydrator)
));
}
}

0 comments on commit b894a85

Please sign in to comment.