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

Complete v2-v3 servicemanager compatibility #21

Merged
merged 8 commits into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ matrix:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- php: 5.5
env:
- SERVICE_MANAGER_VERSION="^2.7.3"
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- php: 5.6
env:
- SERVICE_MANAGER_VERSION="^2.7.3"
- php: 7
- php: 7
env:
- SERVICE_MANAGER_VERSION="^2.7.3"
- php: hhvm
- php: hhvm
env:
- SERVICE_MANAGER_VERSION="^2.7.3"
allow_failures:
- php: hhvm

Expand All @@ -33,6 +45,8 @@ before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs
Expand Down
22 changes: 10 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@
}
},
"require": {
"php": ">=5.5",
"zendframework/zend-stdlib": "~2.5"
"php": "^5.5 || ^7.0",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
"require-dev": {
"zendframework/zend-config": "~2.5",
"zendframework/zend-crypt": "dev-develop as 2.7",
"zendframework/zend-i18n": "~2.5",
"zendframework/zend-loader": "~2.5",
"zendframework/zend-servicemanager": "dev-develop as 2.7",
"zendframework/zend-uri": "~2.5",
"pear/archive_tar": "^1.4",
"zendframework/zend-crypt": "^2.6",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-uri": "^2.5",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
},
"suggest": {
"zendframework/zend-crypt": "Zend\\Crypt component",
"zendframework/zend-i18n": "Zend\\I18n component",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component",
"zendframework/zend-uri": "Zend\\Uri component for UriNormalize filter"
"zendframework/zend-crypt": "Zend\\Crypt component, for encryption filters",
"zendframework/zend-i18n": "Zend\\I18n component for filters depending on i18n functionality",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component, for using the filter chain functionality",
"zendframework/zend-uri": "Zend\\Uri component, for the UriNormalize filter"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
2 changes: 1 addition & 1 deletion src/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Callback extends AbstractFilter
* @param callable|array|Traversable $callbackOrOptions
* @param array $callbackParams
*/
public function __construct($callbackOrOptions, $callbackParams = [])
public function __construct($callbackOrOptions = [], $callbackParams = [])
{
if (is_callable($callbackOrOptions)) {
$this->setCallback($callbackOrOptions);
Expand Down
2 changes: 1 addition & 1 deletion src/File/Rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Rename extends Filter\AbstractFilter
* @param string|array|Traversable $options Target file or directory to be renamed
* @throws Exception\InvalidArgumentException
*/
public function __construct($options)
public function __construct($options = [])
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
Expand Down
2 changes: 1 addition & 1 deletion src/File/RenameUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RenameUpload extends AbstractFilter
*
* @param array|string $targetOrOptions The target file path or an options array
*/
public function __construct($targetOrOptions)
public function __construct($targetOrOptions = [])
{
if (is_array($targetOrOptions)) {
$this->setOptions($targetOrOptions);
Expand Down
252 changes: 153 additions & 99 deletions src/FilterPluginManager.php

Large diffs are not rendered by default.

42 changes: 41 additions & 1 deletion src/Word/Service/SeparatorToSeparatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,40 @@

use Interop\Container\ContainerInterface;
use Zend\Filter\Word\SeparatorToSeparator;
use Zend\ServiceManager\Factory\FactoryInterface;
use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class SeparatorToSeparatorFactory implements FactoryInterface
{
/**
* Options to pass to the constructor (when used in v2), if any.
*
* @param null|array
*/
private $creationOptions = [];

public function __construct($creationOptions = null)
{
if (null === $creationOptions) {
return;
}

if ($creationOptions instanceof Traversable) {
$creationOptions = iterator_to_array($creationOptions);
}

if (! is_array($creationOptions)) {
throw new InvalidServiceException(sprintf(
'%s cannot use non-array, non-traversable creation options; received %s',
__CLASS__,
(is_object($creationOptions) ? get_class($creationOptions) : gettype($creationOptions))
));
}

$this->creationOptions = $creationOptions;
}

/**
* {@inheritDoc}
*/
Expand All @@ -18,4 +48,14 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
isset($options['replacement_separator']) ? $options['replacement_separator'] : '-'
);
}

public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, self::class, $this->creationOptions);
}

public function setCreationOptions(array $options)
{
$this->creationOptions = $options;
}
}
9 changes: 0 additions & 9 deletions test/Compress/TarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace ZendTest\Filter\Compress;

use Zend\Filter\Compress\Tar as TarCompression;
use Zend\Loader\StandardAutoloader;

/**
* @group Zend_Filter
Expand All @@ -21,14 +20,6 @@ class TarTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
if (!class_exists('Archive_Tar')) {
$autoloader = new StandardAutoloader();
$autoloader->setFallbackAutoloader(true);
if (!$autoloader->autoload('Archive_Tar')) {
$this->markTestSkipped('This filter needs PEARs Archive_Tar');
}
}

$this->tmp = sprintf('%s/%s', sys_get_temp_dir(), uniqid('zfilter'));
mkdir($this->tmp, 0775, true);
}
Expand Down
50 changes: 16 additions & 34 deletions test/FilterChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ZendTest\Filter;

use Zend\Filter\AbstractFilter;
use ArrayIterator;
use Zend\Filter\FilterChain;
use Zend\Filter\PregReplace;
use Zend\Filter\StringToLower;
Expand All @@ -31,8 +31,8 @@ public function testEmptyFilterChainReturnsOriginalValue()
public function testFiltersAreExecutedInFifoOrder()
{
$chain = new FilterChain();
$chain->attach(new LowerCase())
->attach(new StripUpperCase());
$chain->attach(new TestAsset\LowerCase())
->attach(new TestAsset\StripUpperCase());
$value = 'AbC';
$valueExpected = 'abc';
$this->assertEquals($valueExpected, $chain->filter($value));
Expand All @@ -41,8 +41,8 @@ public function testFiltersAreExecutedInFifoOrder()
public function testFiltersAreExecutedAccordingToPriority()
{
$chain = new FilterChain();
$chain->attach(new StripUpperCase())
->attach(new LowerCase, 100);
$chain->attach(new TestAsset\StripUpperCase())
->attach(new TestAsset\LowerCase, 100);
$value = 'AbC';
$valueExpected = 'b';
$this->assertEquals($valueExpected, $chain->filter($value));
Expand Down Expand Up @@ -96,7 +96,7 @@ public function testAllowsConfiguringFiltersViaConstructor()
public function testConfigurationAllowsTraversableObjects()
{
$config = $this->getChainConfig();
$config = new \ArrayIterator($config);
$config = new ArrayIterator($config);
$chain = new FilterChain($config);
$value = '<a name="foo"> abc </a>';
$valueExpected = 'ABC';
Expand Down Expand Up @@ -180,8 +180,8 @@ public function testClone()
public function testCanSerializeFilterChain()
{
$chain = new FilterChain();
$chain->attach(new LowerCase())
->attach(new StripUpperCase());
$chain->attach(new TestAsset\LowerCase())
->attach(new TestAsset\StripUpperCase());
$serialized = serialize($chain);

$unserialized = unserialize($serialized);
Expand All @@ -198,47 +198,29 @@ public function testMergingTwoFilterChainsKeepFiltersPriority()
$valueExpected = 'abc';

$chain = new FilterChain();
$chain->attach(new StripUpperCase())
->attach(new LowerCase(), 1001);
$chain->attach(new TestAsset\StripUpperCase())
->attach(new TestAsset\LowerCase(), 1001);
$this->assertEquals($valueExpected, $chain->filter($value));

$chain = new FilterChain();
$chain->attach(new LowerCase(), 1001)
->attach(new StripUpperCase());
$chain->attach(new TestAsset\LowerCase(), 1001)
->attach(new TestAsset\StripUpperCase());
$this->assertEquals($valueExpected, $chain->filter($value));

$chain = new FilterChain();
$chain->attach(new LowerCase(), 1001);
$chain->attach(new TestAsset\LowerCase(), 1001);
$chainToMerge = new FilterChain();
$chainToMerge->attach(new StripUpperCase());
$chainToMerge->attach(new TestAsset\StripUpperCase());
$chain->merge($chainToMerge);
$this->assertEquals(2, $chain->count());
$this->assertEquals($valueExpected, $chain->filter($value));

$chain = new FilterChain();
$chain->attach(new StripUpperCase());
$chain->attach(new TestAsset\StripUpperCase());
$chainToMerge = new FilterChain();
$chainToMerge->attach(new LowerCase(), 1001);
$chainToMerge->attach(new TestAsset\LowerCase(), 1001);
$chain->merge($chainToMerge);
$this->assertEquals(2, $chain->count());
$this->assertEquals($valueExpected, $chain->filter($value));
}
}


class LowerCase extends AbstractFilter
{
public function filter($value)
{
return strtolower($value);
}
}


class StripUpperCase extends AbstractFilter
{
public function filter($value)
{
return preg_replace('/[A-Z]/', '', $value);
}
}
60 changes: 60 additions & 0 deletions test/FilterPluginManagerCompatibilityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 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\Filter;

use PHPUnit_Framework_TestCase as TestCase;
use ReflectionProperty;
use Zend\Filter\Exception\RuntimeException;
use Zend\Filter\FilterInterface;
use Zend\Filter\FilterPluginManager;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Test\CommonPluginManagerTrait;

class FilterPluginManagerCompatibilityTest extends TestCase
{
use CommonPluginManagerTrait;

protected function getPluginManager()
{
return new FilterPluginManager(new ServiceManager());
}

protected function getV2InvalidPluginException()
{
return RuntimeException::class;
}

protected function getInstanceOf()
{
return FilterInterface::class;
}

public function aliasProvider()
{
$pluginManager = $this->getPluginManager();
$r = new ReflectionProperty($pluginManager, 'aliases');
$r->setAccessible(true);
$aliases = $r->getValue($pluginManager);

foreach ($aliases as $alias => $target) {
// Skipping as zend-i18n is not required by this package
if (strpos($target, '\\I18n\\')) {
continue;
}

// Skipping as it has required options
if (strpos($target, 'DataUnitFormatter')) {
continue;
}

yield $alias => [$alias, $target];
}
}
}
16 changes: 13 additions & 3 deletions test/FilterPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\Filter;

use Zend\Filter\Exception\RuntimeException;
use Zend\Filter\FilterPluginManager;
use Zend\Filter\Word\SeparatorToSeparator;
use Zend\ServiceManager\Exception\InvalidServiceException;
Expand Down Expand Up @@ -37,15 +38,15 @@ public function testFilterSuccessfullyRetrieved()

public function testRegisteringInvalidFilterRaisesException()
{
$this->setExpectedException(InvalidServiceException::class);
$this->setExpectedException($this->getInvalidServiceException());
$this->filters->setService('test', $this);
$this->filters->get('test');
}

public function testLoadingInvalidFilterRaisesException()
{
$this->filters->setInvokableClass('test', get_class($this));
$this->setExpectedException(InvalidServiceException::class);
$this->setExpectedException($this->getInvalidServiceException());
$this->filters->get('test');
}

Expand All @@ -62,7 +63,7 @@ public function testFilterSuccessfullyConstructed()
'replacement_separator' => $replacementSeparator,
];

$filter = $this->filters->build('wordseparatortoseparator', $options);
$filter = $this->filters->get('wordseparatortoseparator', $options);

$this->assertInstanceOf(SeparatorToSeparator::class, $filter);
$this->assertEquals($searchSeparator, $filter->getSearchSeparator());
Expand Down Expand Up @@ -92,4 +93,13 @@ public function testFiltersConstructedAreDifferent()

$this->assertNotEquals($filterOne, $filterTwo);
}


protected function getInvalidServiceException()
{
if (method_exists($this->filters, 'configure')) {
return InvalidServiceException::class;
}
return RuntimeException::class;
}
}
Loading