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

Commit

Permalink
Added plugin manager compatibility test
Browse files Browse the repository at this point in the history
Per https://github.com/zendframework/maintainers/wiki/ZF3-ServiceManager-component-refactors,-phase-2

Adds FilterPluginManagerCompatibilityTest, which tests that the plugin manager
works against both v2 and v3 of zend-servicemanager. This implementation needed
to exclude:

- all plugins from zend-i18n, as that package is no longer required.
- the DataUnitFormatter, as it has required options.

Additionally, I updated the `File\Rename`, `File\RenameUpload`, and `Callback`
filters to make all arguments optional so that they can be listed as invokable
filters.

Finally, a number of plugins were listed in the FilterPluginManager that were
not actually filters, which the compatibility test caught. These included:

- All classes under `Zend\Filter\Encrypt`
- All classes under `Zend\Filter\Compress`

In each case, the classes were used as adapters consumed by other filters, and
were not filters themselves.
  • Loading branch information
weierophinney committed Feb 4, 2016
1 parent 10a9d1e commit 00cec47
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 48 deletions.
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
45 changes: 0 additions & 45 deletions src/FilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,6 @@ class FilterPluginManager extends AbstractPluginManager
'Callback' => Callback::class,
'compress' => Compress::class,
'Compress' => Compress::class,
'compressbz2' => Compress\Bz2::class,
'compressBz2' => Compress\Bz2::class,
'CompressBz2' => Compress\Bz2::class,
'compressgz' => Compress\Gz::class,
'compressGz' => Compress\Gz::class,
'CompressGz' => Compress\Gz::class,
'compresslzf' => Compress\Lzf::class,
'compressLzf' => Compress\Lzf::class,
'CompressLzf' => Compress\Lzf::class,
'compressrar' => Compress\Rar::class,
'compressRar' => Compress\Rar::class,
'CompressRar' => Compress\Rar::class,
'compresssnappy' => Compress\Snappy::class,
'compressSnappy' => Compress\Snappy::class,
'CompressSnappy' => Compress\Snappy::class,
'compresstar' => Compress\Tar::class,
'compressTar' => Compress\Tar::class,
'CompressTar' => Compress\Tar::class,
'compresszip' => Compress\Zip::class,
'compressZip' => Compress\Zip::class,
'CompressZip' => Compress\Zip::class,
'dataunitformatter' => DataUnitFormatter::class,
'dataUnitFormatter' => DataUnitFormatter::class,
'DataUnitFormatter' => DataUnitFormatter::class,
Expand All @@ -105,12 +84,6 @@ class FilterPluginManager extends AbstractPluginManager
'Dir' => Dir::class,
'encrypt' => Encrypt::class,
'Encrypt' => Encrypt::class,
'encryptblockcipher' => Encrypt\BlockCipher::class,
'encryptBlockCipher' => Encrypt\BlockCipher::class,
'EncryptBlockCipher' => Encrypt\BlockCipher::class,
'encryptopenssl' => Encrypt\Openssl::class,
'encryptOpenssl' => Encrypt\Openssl::class,
'EncryptOpenssl' => Encrypt\Openssl::class,
'filedecrypt' => File\Decrypt::class,
'fileDecrypt' => File\Decrypt::class,
'FileDecrypt' => File\Decrypt::class,
Expand Down Expand Up @@ -236,13 +209,6 @@ class FilterPluginManager extends AbstractPluginManager
Boolean::class => InvokableFactory::class,
Callback::class => InvokableFactory::class,
Compress::class => InvokableFactory::class,
Compress\Bz2::class => InvokableFactory::class,
Compress\Gz::class => InvokableFactory::class,
Compress\Lzf::class => InvokableFactory::class,
Compress\Rar::class => InvokableFactory::class,
Compress\Snappy::class => InvokableFactory::class,
Compress\Tar::class => InvokableFactory::class,
Compress\Zip::class => InvokableFactory::class,
DataUnitFormatter::class => InvokableFactory::class,
DateSelect::class => InvokableFactory::class,
DateTimeFormatter::class => InvokableFactory::class,
Expand All @@ -252,8 +218,6 @@ class FilterPluginManager extends AbstractPluginManager
Digits::class => InvokableFactory::class,
Dir::class => InvokableFactory::class,
Encrypt::class => InvokableFactory::class,
Encrypt\BlockCipher::class => InvokableFactory::class,
Encrypt\Openssl::class => InvokableFactory::class,
File\Decrypt::class => InvokableFactory::class,
File\Encrypt::class => InvokableFactory::class,
File\LowerCase::class => InvokableFactory::class,
Expand Down Expand Up @@ -303,13 +267,6 @@ class FilterPluginManager extends AbstractPluginManager
'zendfilterboolean' => InvokableFactory::class,
'zendfiltercallback' => InvokableFactory::class,
'zendfiltercompress' => InvokableFactory::class,
'zendfiltercompressbz' => InvokableFactory::class,
'zendfiltercompressgz' => InvokableFactory::class,
'zendfiltercompresslzf' => InvokableFactory::class,
'zendfiltercompressrar' => InvokableFactory::class,
'zendfiltercompresssnappy' => InvokableFactory::class,
'zendfiltercompresstar' => InvokableFactory::class,
'zendfiltercompresszip' => InvokableFactory::class,
'zendfilterdataunitformatter' => InvokableFactory::class,
'zendfilterdateselect' => InvokableFactory::class,
'zendfilterdatetimeformatter' => InvokableFactory::class,
Expand All @@ -319,8 +276,6 @@ class FilterPluginManager extends AbstractPluginManager
'zendfilterdigits' => InvokableFactory::class,
'zendfilterdir' => InvokableFactory::class,
'zendfilterencrypt' => InvokableFactory::class,
'zendfilterencryptblockcipher' => InvokableFactory::class,
'zendfilterencryptopenssl' => InvokableFactory::class,
'zendfilterfiledecrypt' => InvokableFactory::class,
'zendfilterfileencrypt' => InvokableFactory::class,
'zendfilterfilelowercase' => InvokableFactory::class,
Expand Down
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];
}
}
}

0 comments on commit 00cec47

Please sign in to comment.