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

Commit

Permalink
Incorporated feedback from #14
Browse files Browse the repository at this point in the history
This patch incorporates feedback from #14, specifically:

- Reverts the addition of zend-session to the requirements; it's not
  used anywhere.
- Reverts changes to `HttpTestMockAdapter`; they did not serve any
  noticeable purpose.
- Updates `AbstractAdapter` to cast the `$options` value to an array
  when scalar, ensuring it works with both v2 and v3 versions of
  zend-servicemanager.
- Updated FilterPluginManager to:
  - Move the `array_merge()` option before the call to the parent
    constructor; this ensures any configuration passed at instantation
    takes precedence.
  - Use short array notation for the array passed to `array_merge()`.
  - Document the constructor.
- Updated the `AbstractTest`
  - Reverted the change to `testAdapterShouldAllowPullingFiltersByFile`;
    it was changing the test to follow observed behavior instead of
    updating the code to retain existing behavior.
  - Fixed a number of CS issues with regards to multi-line arguments.
  • Loading branch information
weierophinney committed Feb 16, 2016
1 parent 12dca2f commit e69eb4d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"zendframework/zend-servicemanager": "~2.5",
"zendframework/zend-validator": "~2.5",
"zendframework/zend-progressbar": "~2.5",
"zendframework/zend-session": "~2.5",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/Transfer/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ public function hasErrors()
public function addFilter($filter, $options = null, $files = null)
{
if (is_string($filter)) {
$options = (null !== $options && is_scalar($options)) ? [$options] : $options;
$filter = $this->getFilterManager()->get($filter, $options);
}

Expand Down
25 changes: 16 additions & 9 deletions src/Transfer/Adapter/FilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@
*/
class FilterPluginManager extends BaseManager
{

public function __construct($configOrContainerInstance = null, array $v3config = [])
/**
* Constructor
*
* Merges default aliases pertinent to this plugin manager with those
* defined in the parent filter plugin manager.
*
* @param null|\Zend\ServiceManager\ConfigInterface|\Interop\Container\ContainerInterface $configOrContainerInstance
* @param array $v3config If $configOrContainerInstance is a container, this
* value will be passed to the parent constructor.
*/
public function __construct($configOrContainerInstance = null, array $v3config = [])
{
parent::__construct($configOrContainerInstance, $v3config);

$this->aliases = array_merge(array(
$this->aliases = array_merge([
'decrypt' => File\Decrypt::class,
'encrypt' => File\Encrypt::class,
'lowercase' => File\LowerCase::class,
'rename' => File\Rename::class,
'uppercase' => File\UpperCase::class
), $this->aliases);
}
'uppercase' => File\UpperCase::class,
], $this->aliases);

parent::__construct($configOrContainerInstance, $v3config);
}
}

54 changes: 25 additions & 29 deletions test/Transfer/Adapter/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function testGetFilterShouldReturnNullWhenNoMatchingIdentifierExists()

public function testAdapterShouldAllowPullingFiltersByFile()
{
$this->adapter->addFilter('Boolean', [1], 'foo');
$this->adapter->addFilter('Boolean', 1, 'foo');
$filters = $this->adapter->getFilters('foo');
$this->assertEquals(1, count($filters));
$filter = array_shift($filters);
Expand Down Expand Up @@ -412,34 +412,31 @@ public function testAdapterShouldAllowRetrievingDestinationsForAnArrayOfSpecifie

public function testSettingAndRetrievingOptions()
{
$this->assertEquals(
[
'bar' => ['ignoreNoFile' => false, 'useByteString' => true],
'baz' => ['ignoreNoFile' => false, 'useByteString' => true],
'foo' => ['ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true],
'file_0_' => ['ignoreNoFile' => false, 'useByteString' => true],
'file_1_' => ['ignoreNoFile' => false, 'useByteString' => true],
], $this->adapter->getOptions());
$this->assertEquals([
'bar' => ['ignoreNoFile' => false, 'useByteString' => true],
'baz' => ['ignoreNoFile' => false, 'useByteString' => true],
'foo' => ['ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true],
'file_0_' => ['ignoreNoFile' => false, 'useByteString' => true],
'file_1_' => ['ignoreNoFile' => false, 'useByteString' => true],
], $this->adapter->getOptions());

$this->adapter->setOptions(['ignoreNoFile' => true]);
$this->assertEquals(
[
'bar' => ['ignoreNoFile' => true, 'useByteString' => true],
'baz' => ['ignoreNoFile' => true, 'useByteString' => true],
'foo' => ['ignoreNoFile' => true, 'useByteString' => true, 'detectInfos' => true],
'file_0_' => ['ignoreNoFile' => true, 'useByteString' => true],
'file_1_' => ['ignoreNoFile' => true, 'useByteString' => true],
], $this->adapter->getOptions());
$this->assertEquals([
'bar' => ['ignoreNoFile' => true, 'useByteString' => true],
'baz' => ['ignoreNoFile' => true, 'useByteString' => true],
'foo' => ['ignoreNoFile' => true, 'useByteString' => true, 'detectInfos' => true],
'file_0_' => ['ignoreNoFile' => true, 'useByteString' => true],
'file_1_' => ['ignoreNoFile' => true, 'useByteString' => true],
], $this->adapter->getOptions());

$this->adapter->setOptions(['ignoreNoFile' => false], 'foo');
$this->assertEquals(
[
'bar' => ['ignoreNoFile' => true, 'useByteString' => true],
'baz' => ['ignoreNoFile' => true, 'useByteString' => true],
'foo' => ['ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true],
'file_0_' => ['ignoreNoFile' => true, 'useByteString' => true],
'file_1_' => ['ignoreNoFile' => true, 'useByteString' => true],
], $this->adapter->getOptions());
$this->assertEquals([
'bar' => ['ignoreNoFile' => true, 'useByteString' => true],
'baz' => ['ignoreNoFile' => true, 'useByteString' => true],
'foo' => ['ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true],
'file_0_' => ['ignoreNoFile' => true, 'useByteString' => true],
'file_1_' => ['ignoreNoFile' => true, 'useByteString' => true],
], $this->adapter->getOptions());
}

public function testGetAllAdditionalFileInfos()
Expand Down Expand Up @@ -601,10 +598,9 @@ public function testTransferDestinationAtNonExistingElement()
public function testSettingMagicFile()
{
$this->adapter->setOptions(['magicFile' => 'test/file']);
$this->assertEquals(
[
'bar' => ['magicFile' => 'test/file', 'ignoreNoFile' => false, 'useByteString' => true],
], $this->adapter->getOptions('bar'));
$this->assertEquals([
'bar' => ['magicFile' => 'test/file', 'ignoreNoFile' => false, 'useByteString' => true],
], $this->adapter->getOptions('bar'));
}

/**
Expand Down
19 changes: 13 additions & 6 deletions test/Transfer/Adapter/HttpTestMockAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
class HttpTestMockAdapter extends Adapter\Http
{
static $aa = true;

public function __construct()
{
self::$callbackApc = ['ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'apcTest'];
Expand All @@ -38,21 +36,30 @@ public function isValidParent($files = null)

public static function isApcAvailable()
{
return static::$aa;
return true;
}

public static function apcTest($id)
{
return ['total' => 100, 'current' => 100, 'rate' => 10];
return [
'total' => 100,
'current' => 100,
'rate' => 10,
];
}

public static function uPTest($id)
{
return ['bytes_total' => 100, 'bytes_uploaded' => 100, 'speed_average' => 10, 'cancel_upload' => true];
return [
'bytes_total' => 100,
'bytes_uploaded' => 100,
'speed_average' => 10,
'cancel_upload' => true,
];
}

public function switchApcToUP()
{ static::$aa = false;
{
self::$callbackApc = null;
self::$callbackUploadProgress = ['ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'uPTest'];
}
Expand Down

0 comments on commit e69eb4d

Please sign in to comment.