From b6da9c6b0d7069059b4f8838238dee57f7ea092e Mon Sep 17 00:00:00 2001 From: Maks3w Date: Fri, 5 Jun 2015 11:16:39 +0200 Subject: [PATCH] [cs] Use PHP short array syntax Since PHP 5.4 arrays can be defined with brackets ([]) instead the function --- .php_cs | 1 + src/PhpClassFile.php | 4 +- src/Transfer/Adapter/AbstractAdapter.php | 68 +++++------ src/Transfer/Adapter/FilterPluginManager.php | 4 +- src/Transfer/Adapter/Http.php | 12 +- src/Transfer/Adapter/ValidatorPluginManager.php | 4 +- src/Transfer/Transfer.php | 8 +- test/ClassFileLocatorTest.php | 2 +- .../Adapter/AbstractAdapterTestMockAdapter.php | 50 ++++---- test/Transfer/Adapter/AbstractTest.php | 136 ++++++++++----------- test/Transfer/Adapter/HttpTest.php | 72 +++++------ test/Transfer/Adapter/HttpTestMockAdapter.php | 8 +- 12 files changed, 185 insertions(+), 184 deletions(-) diff --git a/.php_cs b/.php_cs index 6b3d68b..8f4dd5a 100644 --- a/.php_cs +++ b/.php_cs @@ -32,6 +32,7 @@ $config->fixers( 'object_operator', 'php_closing_tag', 'remove_lines_between_uses', + 'short_array_syntax', 'short_tag', 'standardize_not_equal', 'trailing_spaces', diff --git a/src/PhpClassFile.php b/src/PhpClassFile.php index 800c859..fcaaf7a 100644 --- a/src/PhpClassFile.php +++ b/src/PhpClassFile.php @@ -19,12 +19,12 @@ class PhpClassFile extends SplFileInfo /** * @var array */ - protected $classes = array(); + protected $classes = []; /** * @var array */ - protected $namespaces = array(); + protected $namespaces = []; /** * Get classes diff --git a/src/Transfer/Adapter/AbstractAdapter.php b/src/Transfer/Adapter/AbstractAdapter.php index 7be8c58..04e09c2 100644 --- a/src/Transfer/Adapter/AbstractAdapter.php +++ b/src/Transfer/Adapter/AbstractAdapter.php @@ -44,7 +44,7 @@ * * @var array */ - protected $break = array(); + protected $break = []; /** * @var FilterPluginManager @@ -56,21 +56,21 @@ * * @var array */ - protected $filters = array(); + protected $filters = []; /** * Plugin loaders for filter and validation chains * * @var array */ - protected $loaders = array(); + protected $loaders = []; /** * Internal list of messages * * @var array */ - protected $messages = array(); + protected $messages = []; /** * @var Translator @@ -100,7 +100,7 @@ * Internal list of validators * @var array */ - protected $validators = array(); + protected $validators = []; /** * Internal list of files @@ -118,7 +118,7 @@ * * @var array */ - protected $files = array(); + protected $files = []; /** * TMP directory @@ -129,12 +129,12 @@ /** * Available options for file transfers */ - protected $options = array( + protected $options = [ 'ignoreNoFile' => false, 'useByteString' => true, 'magicFile' => null, 'detectInfos' => true, - ); + ]; /** * Send file @@ -311,7 +311,7 @@ public function addValidator($validator, $breakChainOnFailure = false, $options foreach ($files as $file) { if ($name == 'NotEmpty') { $temp = $this->files[$file]['validators']; - $this->files[$file]['validators'] = array($name); + $this->files[$file]['validators'] = [$name]; $this->files[$file]['validators'] += $temp; } else { $this->files[$file]['validators'][] = $name; @@ -345,7 +345,7 @@ public function addValidators(array $validators, $files = null) } elseif (is_array($validatorInfo)) { $argc = count($validatorInfo); $breakChainOnFailure = false; - $options = array(); + $options = []; if (isset($validatorInfo['validator'])) { $validator = $validatorInfo['validator']; if (isset($validatorInfo['breakChainOnFailure'])) { @@ -446,7 +446,7 @@ public function getValidators($files = null) } $files = $this->getFiles($files, true, true); - $validators = array(); + $validators = []; foreach ($files as $file) { if (!empty($this->files[$file]['validators'])) { $validators += $this->files[$file]['validators']; @@ -454,7 +454,7 @@ public function getValidators($files = null) } $validators = array_unique($validators); - $result = array(); + $result = []; foreach ($validators as $validator) { $result[$validator] = $this->validators[$validator]; } @@ -499,9 +499,9 @@ public function removeValidator($name) */ public function clearValidators() { - $this->validators = array(); + $this->validators = []; foreach (array_keys($this->files) as $file) { - $this->files[$file]['validators'] = array(); + $this->files[$file]['validators'] = []; $this->files[$file]['validated'] = false; } @@ -515,7 +515,7 @@ public function clearValidators() * @param array $files (Optional) Files to set the options for * @return AbstractAdapter */ - public function setOptions($options = array(), $files = null) + public function setOptions($options = [], $files = null) { $file = $this->getFiles($files, false, true); @@ -561,7 +561,7 @@ public function getOptions($files = null) if (isset($this->files[$key]['options'])) { $options[$key] = $this->files[$key]['options']; } else { - $options[$key] = array(); + $options[$key] = []; } } @@ -582,7 +582,7 @@ public function isValid($files = null) } $translator = $this->getTranslator(); - $this->messages = array(); + $this->messages = []; $break = false; foreach ($check as $content) { if (array_key_exists('validators', $content) && @@ -611,7 +611,7 @@ public function isValid($files = null) } foreach ($check as $key => $content) { - $fileerrors = array(); + $fileerrors = []; if (array_key_exists('validators', $content) && $content['validated']) { continue; } @@ -824,7 +824,7 @@ public function getFilters($files = null) } $files = $this->getFiles($files, true, true); - $filters = array(); + $filters = []; foreach ($files as $file) { if (!empty($this->files[$file]['filters'])) { $filters += $this->files[$file]['filters']; @@ -832,7 +832,7 @@ public function getFilters($files = null) } $filters = array_unique($filters); - $result = array(); + $result = []; foreach ($filters as $filter) { $result[] = $this->filters[$filter]; } @@ -875,9 +875,9 @@ public function removeFilter($name) */ public function clearFilters() { - $this->filters = array(); + $this->filters = []; foreach (array_keys($this->files) as $file) { - $this->files[$file]['filters'] = array(); + $this->files[$file]['filters'] = []; } return $this; @@ -893,7 +893,7 @@ public function clearFilters() public function getFileName($file = null, $path = true) { $files = $this->getFiles($file, true, true); - $result = array(); + $result = []; $directory = ""; foreach ($files as $file) { if (empty($this->files[$file]['name'])) { @@ -975,7 +975,7 @@ public function getDestination($files = null) { $orig = $files; $files = $this->getFiles($files, false, true); - $destinations = array(); + $destinations = []; if (empty($files) and is_string($orig)) { if (isset($this->files[$orig]['destination'])) { $destinations[$orig] = $this->files[$orig]['destination']; @@ -1106,7 +1106,7 @@ public function getHash($hash = 'crc32', $files = null) } $files = $this->getFiles($files); - $result = array(); + $result = []; foreach ($files as $key => $value) { if (file_exists($value['name'])) { $result[$key] = hash_file($hash, $value['name']); @@ -1134,7 +1134,7 @@ public function getHash($hash = 'crc32', $files = null) public function getFileSize($files = null) { $files = $this->getFiles($files); - $result = array(); + $result = []; foreach ($files as $key => $value) { if (file_exists($value['name']) || file_exists($value['tmp_name'])) { if ($value['options']['useByteString']) { @@ -1193,7 +1193,7 @@ protected function detectFileSize($value) public function getMimeType($files = null) { $files = $this->getFiles($files); - $result = array(); + $result = []; foreach ($files as $key => $value) { if (file_exists($value['name']) || file_exists($value['tmp_name'])) { $result[$key] = $value['type']; @@ -1267,7 +1267,7 @@ protected function detectMimeType($value) */ protected static function toByteString($size) { - $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); + $sizes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; for ($i=0; $size >= 1024 && $i < 9; $i++) { $size /= 1024; } @@ -1294,7 +1294,7 @@ protected function filter($files = null) $this->files[$name]['destination'] = dirname($result); $this->files[$name]['name'] = basename($result); } catch (FilterException\ExceptionInterface $e) { - $this->messages += array($e->getMessage()); + $this->messages += [$e->getMessage()]; } } } @@ -1316,7 +1316,7 @@ protected function filter($files = null) protected function getTmpDir() { if (null === $this->tmpDir) { - $tmpdir = array(); + $tmpdir = []; if (function_exists('sys_get_temp_dir')) { $tmpdir[] = sys_get_temp_dir(); } @@ -1401,15 +1401,15 @@ protected function isPathWriteable($path) */ protected function getFiles($files, $names = false, $noexception = false) { - $check = array(); + $check = []; if (is_string($files)) { - $files = array($files); + $files = [$files]; } if (is_array($files)) { foreach ($files as $find) { - $found = array(); + $found = []; foreach ($this->files as $file => $content) { if (!isset($content['name'])) { continue; @@ -1435,7 +1435,7 @@ protected function getFiles($files, $names = false, $noexception = false) if (empty($found)) { if ($noexception !== false) { - return array(); + return []; } throw new Exception\RuntimeException(sprintf('The file transfer adapter can not find "%s"', $find)); diff --git a/src/Transfer/Adapter/FilterPluginManager.php b/src/Transfer/Adapter/FilterPluginManager.php index 8179eef..3fa9456 100644 --- a/src/Transfer/Adapter/FilterPluginManager.php +++ b/src/Transfer/Adapter/FilterPluginManager.php @@ -25,11 +25,11 @@ class FilterPluginManager extends BaseManager * * @var array */ - protected $aliases = array( + protected $aliases = [ 'decrypt' => 'filedecrypt', 'encrypt' => 'fileencrypt', 'lowercase' => 'filelowercase', 'rename' => 'filerename', 'uppercase' => 'fileuppercase', - ); + ]; } diff --git a/src/Transfer/Adapter/Http.php b/src/Transfer/Adapter/Http.php index b7c2908..c6abfa9 100644 --- a/src/Transfer/Adapter/Http.php +++ b/src/Transfer/Adapter/Http.php @@ -29,7 +29,7 @@ class Http extends AbstractAdapter * @param array $options OPTIONAL Options to set * @throws Exception\PhpEnvironmentException if file uploads are not allowed */ - public function __construct($options = array()) + public function __construct($options = []) { if (ini_get('file_uploads') == false) { throw new Exception\PhpEnvironmentException('File uploads are not allowed in your php config!'); @@ -115,9 +115,9 @@ public function isValid($files = null) $files = current($files); } - $temp = array($files => array( + $temp = [$files => [ 'name' => $files, - 'error' => 1)); + 'error' => 1]]; $validator = $this->validators['Zend\Validator\File\Upload']; $validator->setTranslator($this->getTranslator()) ->setFiles($temp) @@ -293,13 +293,13 @@ public static function getProgress($id = null) } $session = 'Zend\File\Transfer\Adapter\Http\ProgressBar'; - $status = array( + $status = [ 'total' => 0, 'current' => 0, 'rate' => 0, 'message' => '', 'done' => false - ); + ]; if (is_array($id)) { if (isset($id['progress'])) { @@ -411,7 +411,7 @@ public static function isUploadProgressAvailable() */ protected function prepareFiles() { - $this->files = array(); + $this->files = []; foreach ($_FILES as $form => $content) { if (is_array($content['name'])) { foreach ($content as $param => $file) { diff --git a/src/Transfer/Adapter/ValidatorPluginManager.php b/src/Transfer/Adapter/ValidatorPluginManager.php index c6912c0..8555f41 100644 --- a/src/Transfer/Adapter/ValidatorPluginManager.php +++ b/src/Transfer/Adapter/ValidatorPluginManager.php @@ -13,7 +13,7 @@ class ValidatorPluginManager extends BaseManager { - protected $aliases = array( + protected $aliases = [ 'count' => 'filecount', 'crc32' => 'filecrc32', 'excludeextension' => 'fileexcludeextension', @@ -32,5 +32,5 @@ class ValidatorPluginManager extends BaseManager 'size' => 'filesize', 'upload' => 'fileupload', 'wordcount' => 'filewordcount', - ); + ]; } diff --git a/src/Transfer/Transfer.php b/src/Transfer/Transfer.php index 2835001..3e89056 100644 --- a/src/Transfer/Transfer.php +++ b/src/Transfer/Transfer.php @@ -20,7 +20,7 @@ class Transfer * * @var array */ - protected $adapter = array(); + protected $adapter = []; /** * Creates a file processing handler @@ -30,7 +30,7 @@ class Transfer * @param array $options OPTIONAL Options to set for this adapter * @throws Exception\InvalidArgumentException */ - public function __construct($adapter = 'Http', $direction = false, $options = array()) + public function __construct($adapter = 'Http', $direction = false, $options = []) { $this->setAdapter($adapter, $direction, $options); } @@ -44,7 +44,7 @@ public function __construct($adapter = 'Http', $direction = false, $options = ar * @return Transfer * @throws Exception\InvalidArgumentException */ - public function setAdapter($adapter, $direction = false, $options = array()) + public function setAdapter($adapter, $direction = false, $options = []) { if (!is_string($adapter)) { throw new Exception\InvalidArgumentException('Adapter must be a string'); @@ -100,7 +100,7 @@ public function __call($method, array $options) } if (method_exists($this->adapter[$direction], $method)) { - return call_user_func_array(array($this->adapter[$direction], $method), $options); + return call_user_func_array([$this->adapter[$direction], $method], $options); } throw new Exception\BadMethodCallException("Unknown method '" . $method . "' called!"); diff --git a/test/ClassFileLocatorTest.php b/test/ClassFileLocatorTest.php index a887813..671d1df 100644 --- a/test/ClassFileLocatorTest.php +++ b/test/ClassFileLocatorTest.php @@ -26,7 +26,7 @@ public function testConstructorThrowsInvalidArgumentExceptionForInvalidStringDir public function testConstructorThrowsInvalidArgumentExceptionForNonDirectoryIteratorArgument() { - $iterator = new \ArrayIterator(array()); + $iterator = new \ArrayIterator([]); $this->setExpectedException('Zend\File\Exception\InvalidArgumentException'); $locator = new ClassFileLocator($iterator); } diff --git a/test/Transfer/Adapter/AbstractAdapterTestMockAdapter.php b/test/Transfer/Adapter/AbstractAdapterTestMockAdapter.php index 0285089..453cb73 100644 --- a/test/Transfer/Adapter/AbstractAdapterTestMockAdapter.php +++ b/test/Transfer/Adapter/AbstractAdapterTestMockAdapter.php @@ -25,62 +25,62 @@ class AbstractAdapterTestMockAdapter extends Adapter\AbstractAdapter public function __construct() { $testfile = __DIR__ . '/_files/test.txt'; - $this->files = array( - 'foo' => array( + $this->files = [ + 'foo' => [ 'name' => 'foo.jpg', 'type' => 'image/jpeg', 'size' => 126976, 'tmp_name' => '/tmp/489127ba5c89c', - 'options' => array('ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true), + 'options' => ['ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true], 'validated' => false, 'received' => false, 'filtered' => false, - ), - 'bar' => array( + ], + 'bar' => [ 'name' => 'bar.png', 'type' => 'image/png', 'size' => 91136, 'tmp_name' => '/tmp/489128284b51f', - 'options' => array('ignoreNoFile' => false, 'useByteString' => true), + 'options' => ['ignoreNoFile' => false, 'useByteString' => true], 'validated' => false, 'received' => false, 'filtered' => false, - ), - 'baz' => array( + ], + 'baz' => [ 'name' => 'baz.text', 'type' => 'text/plain', 'size' => 1172, 'tmp_name' => $testfile, - 'options' => array('ignoreNoFile' => false, 'useByteString' => true), + 'options' => ['ignoreNoFile' => false, 'useByteString' => true], 'validated' => false, 'received' => false, 'filtered' => false, - ), - 'file_0_' => array( + ], + 'file_0_' => [ 'name' => 'foo.jpg', 'type' => 'image/jpeg', 'size' => 126976, 'tmp_name' => '/tmp/489127ba5c89c', - 'options' => array('ignoreNoFile' => false, 'useByteString' => true), + 'options' => ['ignoreNoFile' => false, 'useByteString' => true], 'validated' => false, 'received' => false, 'filtered' => false, - ), - 'file_1_' => array( + ], + 'file_1_' => [ 'name' => 'baz.text', 'type' => 'text/plain', 'size' => 1172, 'tmp_name' => $testfile, - 'options' => array('ignoreNoFile' => false, 'useByteString' => true), + 'options' => ['ignoreNoFile' => false, 'useByteString' => true], 'validated' => false, 'received' => false, 'filtered' => false, - ), - 'file' => array( + ], + 'file' => [ 'name' => 'foo.jpg', - 'multifiles' => array(0 => 'file_0_', 1 => 'file_1_') - ), - ); + 'multifiles' => [0 => 'file_0_', 1 => 'file_1_'] + ], + ]; } public function send($options = null) @@ -131,17 +131,17 @@ public function isPathWriteable($path) public function addInvalidFile() { - $this->files += array( - 'test' => array( + $this->files += [ + 'test' => [ 'name' => 'test.txt', 'type' => 'image/jpeg', 'size' => 0, 'tmp_name' => '', - 'options' => array('ignoreNoFile' => true, 'useByteString' => true), + 'options' => ['ignoreNoFile' => true, 'useByteString' => true], 'validated' => false, 'received' => false, 'filtered' => false, - ) - ); + ] + ]; } } diff --git a/test/Transfer/Adapter/AbstractTest.php b/test/Transfer/Adapter/AbstractTest.php index e6077cc..294323b 100644 --- a/test/Transfer/Adapter/AbstractTest.php +++ b/test/Transfer/Adapter/AbstractTest.php @@ -58,7 +58,7 @@ public function testAdapterShouldAllowSettingFilterPluginManagerInstance() public function testAdapterShouldAllowAddingValidatorInstance() { - $validator = new FileValidator\Count(array('min' => 1, 'max' => 1)); + $validator = new FileValidator\Count(['min' => 1, 'max' => 1]); $this->adapter->addValidator($validator); $test = $this->adapter->getValidator('Zend\Validator\File\Count'); $this->assertSame($validator, $test); @@ -66,7 +66,7 @@ public function testAdapterShouldAllowAddingValidatorInstance() public function testAdapterShouldAllowAddingValidatorViaPluginManager() { - $this->adapter->addValidator('Count', false, array('min' => 1, 'max' => 1)); + $this->adapter->addValidator('Count', false, ['min' => 1, 'max' => 1]); $test = $this->adapter->getValidator('Count'); $this->assertInstanceOf('Zend\Validator\File\Count', $test); } @@ -79,15 +79,15 @@ public function testAdapterhShouldRaiseExceptionWhenAddingInvalidValidatorType() public function testAdapterShouldAllowAddingMultipleValidatorsAtOnceUsingBothInstancesAndPluginLoader() { - $validators = array( - 'count' => array('min' => 1, 'max' => 1), + $validators = [ + 'count' => ['min' => 1, 'max' => 1], 'Exists' => 'C:\temp', - array( + [ 'validator' => 'Upload', - 'options' => array(realpath(__FILE__)) - ), + 'options' => [realpath(__FILE__)] + ], new FileValidator\Extension('jpg'), - ); + ]; $this->adapter->addValidators($validators); $test = $this->adapter->getValidators(); $this->assertInternalType('array', $test); @@ -111,7 +111,7 @@ public function testGetValidatorShouldReturnNullWhenNoMatchingIdentifierExists() public function testAdapterShouldAllowPullingValidatorsByFile() { - $this->adapter->addValidator('Between', false, array('min' => 1, 'max' => 5), 'foo'); + $this->adapter->addValidator('Between', false, ['min' => 1, 'max' => 5], 'foo'); $validators = $this->adapter->getValidators('foo'); $this->assertEquals(1, count($validators)); $validator = array_shift($validators); @@ -121,10 +121,10 @@ public function testAdapterShouldAllowPullingValidatorsByFile() public function testCallingSetValidatorsOnAdapterShouldOverwriteExistingValidators() { $this->testAdapterShouldAllowAddingMultipleValidatorsAtOnceUsingBothInstancesAndPluginLoader(); - $validators = array( + $validators = [ new FileValidator\Count(1), new FileValidator\Extension('jpg'), - ); + ]; $this->adapter->setValidators($validators); $test = $this->adapter->getValidators(); $this->assertSame($validators, array_values($test)); @@ -193,7 +193,7 @@ public function testAdapterShouldAllowRemovingAllValidatorsAtOnce() public function testValidationShouldReturnTrueForValidTransfer() { - $this->adapter->addValidator('Count', false, array(1, 3), 'foo'); + $this->adapter->addValidator('Count', false, [1, 3], 'foo'); $this->assertTrue($this->adapter->isValid('foo')); } @@ -273,14 +273,14 @@ public function testAdapterhShouldRaiseExceptionWhenAddingInvalidFilterType() public function testAdapterShouldAllowAddingMultipleFiltersAtOnceUsingBothInstancesAndPluginLoader() { - $filters = array( - 'Word\SeparatorToCamelCase' => array('separator' => ' '), - array( + $filters = [ + 'Word\SeparatorToCamelCase' => ['separator' => ' '], + [ 'filter' => 'Boolean', 'casting' => true - ), + ], new Filter\BaseName(), - ); + ]; $this->adapter->addFilters($filters); $test = $this->adapter->getFilters(); $this->assertInternalType('array', $test); @@ -311,10 +311,10 @@ public function testAdapterShouldAllowPullingFiltersByFile() public function testCallingSetFiltersOnAdapterShouldOverwriteExistingFilters() { $this->testAdapterShouldAllowAddingMultipleFiltersAtOnceUsingBothInstancesAndPluginLoader(); - $filters = array( + $filters = [ new Filter\StringToUpper(), new Filter\Boolean(), - ); + ]; $this->adapter->setFilters($filters); $test = $this->adapter->getFilters(); $this->assertSame($filters, array_values($test)); @@ -401,11 +401,11 @@ public function testTransferDestinationShouldBeMutable() public function testAdapterShouldAllowRetrievingDestinationsForAnArrayOfSpecifiedFiles() { $this->adapter->setDestination(__DIR__); - $destinations = $this->adapter->getDestination(array('bar', 'baz')); + $destinations = $this->adapter->getDestination(['bar', 'baz']); $this->assertInternalType('array', $destinations); $directory = __DIR__; foreach ($destinations as $file => $destination) { - $this->assertContains($file, array('bar', 'baz')); + $this->assertContains($file, ['bar', 'baz']); $this->assertEquals($directory, $destination); } } @@ -413,33 +413,33 @@ public function testAdapterShouldAllowRetrievingDestinationsForAnArrayOfSpecifie public function testSettingAndRetrievingOptions() { $this->assertEquals( - array( - 'bar' => array('ignoreNoFile' => false, 'useByteString' => true), - 'baz' => array('ignoreNoFile' => false, 'useByteString' => true), - 'foo' => array('ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true), - 'file_0_' => array('ignoreNoFile' => false, 'useByteString' => true), - 'file_1_' => array('ignoreNoFile' => false, 'useByteString' => true), - ), $this->adapter->getOptions()); - - $this->adapter->setOptions(array('ignoreNoFile' => true)); + [ + '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( - array( - 'bar' => array('ignoreNoFile' => true, 'useByteString' => true), - 'baz' => array('ignoreNoFile' => true, 'useByteString' => true), - 'foo' => array('ignoreNoFile' => true, 'useByteString' => true, 'detectInfos' => true), - 'file_0_' => array('ignoreNoFile' => true, 'useByteString' => true), - 'file_1_' => array('ignoreNoFile' => true, 'useByteString' => true), - ), $this->adapter->getOptions()); - - $this->adapter->setOptions(array('ignoreNoFile' => false), 'foo'); + [ + '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( - array( - 'bar' => array('ignoreNoFile' => true, 'useByteString' => true), - 'baz' => array('ignoreNoFile' => true, 'useByteString' => true), - 'foo' => array('ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true), - 'file_0_' => array('ignoreNoFile' => true, 'useByteString' => true), - 'file_1_' => array('ignoreNoFile' => true, 'useByteString' => true), - ), $this->adapter->getOptions()); + [ + '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() @@ -508,7 +508,7 @@ public function testIgnoreHashValue() { $this->adapter->addInvalidFile(); $return = $this->adapter->getHash('crc32', 'test'); - $this->assertEquals(array(), $return); + $this->assertEquals([], $return); } public function testEmptyTempDirectoryDetection() @@ -541,7 +541,7 @@ public function testIgnoreFileSize() { $this->adapter->addInvalidFile(); $return = $this->adapter->getFileSize('test'); - $this->assertEquals(array(), $return); + $this->assertEquals([], $return); } public function testFileSizeByTmpName() @@ -550,7 +550,7 @@ public function testFileSizeByTmpName() $options = $this->adapter->getOptions(); $this->assertTrue($options['baz']['useByteString']); $this->assertEquals($expectedSize, $this->adapter->getFileSize('baz.text')); - $this->adapter->setOptions(array('useByteString' => false)); + $this->adapter->setOptions(['useByteString' => false]); $options = $this->adapter->getOptions(); $this->assertFalse($options['baz']['useByteString']); $this->assertEquals(1172, $this->adapter->getFileSize('baz.text')); @@ -566,7 +566,7 @@ public function testIgnoreMimeType() { $this->adapter->addInvalidFile(); $return = $this->adapter->getMimeType('test'); - $this->assertEquals(array(), $return); + $this->assertEquals([], $return); } public function testMimeTypeByTmpName() @@ -576,7 +576,7 @@ public function testMimeTypeByTmpName() public function testSetOwnErrorMessage() { - $this->adapter->addValidator('Count', false, array('min' => 5, 'max' => 5, 'messages' => array(FileValidator\Count::TOO_FEW => 'Zu wenige'))); + $this->adapter->addValidator('Count', false, ['min' => 5, 'max' => 5, 'messages' => [FileValidator\Count::TOO_FEW => 'Zu wenige']]); $this->assertFalse($this->adapter->isValid('foo')); $message = $this->adapter->getMessages(); $this->assertContains('Zu wenige', $message); @@ -600,11 +600,11 @@ public function testTransferDestinationAtNonExistingElement() */ public function testSettingMagicFile() { - $this->adapter->setOptions(array('magicFile' => 'test/file')); + $this->adapter->setOptions(['magicFile' => 'test/file']); $this->assertEquals( - array( - 'bar' => array('magicFile' => 'test/file', 'ignoreNoFile' => false, 'useByteString' => true), - ), $this->adapter->getOptions('bar')); + [ + 'bar' => ['magicFile' => 'test/file', 'ignoreNoFile' => false, 'useByteString' => true], + ], $this->adapter->getOptions('bar')); } /** @@ -612,12 +612,12 @@ public function testSettingMagicFile() */ public function testAdapterShouldAllowAddingMultipleValidatorsAtOnceUsingBothInstancesAndPluginLoaderForDifferentFiles() { - $validators = array( - array('MimeType', true, array('image/jpeg')), // no files - array('FilesSize', true, array('max' => '1MB', 'message' => 'файл больше 1MБ')), // no files - array('Count', true, array('min' => 1, 'max' => '1', 'message' => 'файл не 1'), 'bar'), // 'bar' from config - array('MimeType', true, array('image/jpeg'), 'bar'), // 'bar' from config - ); + $validators = [ + ['MimeType', true, ['image/jpeg']], // no files + ['FilesSize', true, ['max' => '1MB', 'message' => 'файл больше 1MБ']], // no files + ['Count', true, ['min' => 1, 'max' => '1', 'message' => 'файл не 1'], 'bar'], // 'bar' from config + ['MimeType', true, ['image/jpeg'], 'bar'], // 'bar' from config + ]; $this->adapter->addValidators($validators, 'foo'); // set validators to 'foo' @@ -648,16 +648,16 @@ public function testAdapterShouldAllowAddingMultipleValidatorsAtOnceUsingBothIns */ public function testSettingAndRetrievingDetectInfosOption() { - $this->assertEquals(array( - 'foo' => array( + $this->assertEquals([ + 'foo' => [ 'ignoreNoFile' => false, 'useByteString' => true, - 'detectInfos' => true)), $this->adapter->getOptions('foo')); - $this->adapter->setOptions(array('detectInfos' => false)); - $this->assertEquals(array( - 'foo' => array( + 'detectInfos' => true]], $this->adapter->getOptions('foo')); + $this->adapter->setOptions(['detectInfos' => false]); + $this->assertEquals([ + 'foo' => [ 'ignoreNoFile' => false, 'useByteString' => true, - 'detectInfos' => false)), $this->adapter->getOptions('foo')); + 'detectInfos' => false]], $this->adapter->getOptions('foo')); } } diff --git a/test/Transfer/Adapter/HttpTest.php b/test/Transfer/Adapter/HttpTest.php index 8741f05..fea4a13 100644 --- a/test/Transfer/Adapter/HttpTest.php +++ b/test/Transfer/Adapter/HttpTest.php @@ -29,13 +29,13 @@ class HttpTest extends \PHPUnit_Framework_TestCase */ public function setUp() { - $_FILES = array( - 'txt' => array( + $_FILES = [ + 'txt' => [ 'name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt', 'type' => 'plain/text', 'size' => 8, 'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt', - 'error' => 0)); + 'error' => 0]]; $this->adapter = new HttpTestMockAdapter(); } @@ -57,10 +57,10 @@ public function testEmptyAdapter() public function testAutoSetUploadValidator() { - $validators = array( + $validators = [ new FileValidator\Count(1), new FileValidator\Extension('jpg'), - ); + ]; $this->adapter->setValidators($validators); $test = $this->adapter->getValidator('Upload'); $this->assertInstanceOf('Zend\Validator\File\Upload', $test); @@ -111,69 +111,69 @@ public function testReceiveUnknownFile() public function testReceiveValidatedFile() { - $_FILES = array( - 'txt' => array( + $_FILES = [ + 'txt' => [ 'name' => 'unknown.txt', 'type' => 'plain/text', 'size' => 8, 'tmp_name' => 'unknown.txt', - 'error' => 0)); + 'error' => 0]]; $adapter = new HttpTestMockAdapter(); $this->assertFalse($adapter->receive()); } public function testReceiveIgnoredFile() { - $this->adapter->setOptions(array('ignoreNoFile' => true)); + $this->adapter->setOptions(['ignoreNoFile' => true]); $this->assertTrue($this->adapter->receive()); } public function testReceiveWithRenameFilter() { - $this->adapter->addFilter('Rename', array('target' => '/testdir')); - $this->adapter->setOptions(array('ignoreNoFile' => true)); + $this->adapter->addFilter('Rename', ['target' => '/testdir']); + $this->adapter->setOptions(['ignoreNoFile' => true]); $this->assertTrue($this->adapter->receive()); } public function testReceiveWithRenameFilterButWithoutDirectory() { $this->adapter->setDestination(__DIR__); - $this->adapter->addFilter('Rename', array('overwrite' => false)); - $this->adapter->setOptions(array('ignoreNoFile' => true)); + $this->adapter->addFilter('Rename', ['overwrite' => false]); + $this->adapter->setOptions(['ignoreNoFile' => true]); $this->assertTrue($this->adapter->receive()); } public function testMultiFiles() { - $_FILES = array( - 'txt' => array( + $_FILES = [ + 'txt' => [ 'name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt', 'type' => 'plain/text', 'size' => 8, 'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt', - 'error' => 0), - 'exe' => array( - 'name' => array( + 'error' => 0], + 'exe' => [ + 'name' => [ 0 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt', - 1 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'), - 'type' => array( + 1 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'], + 'type' => [ 0 => 'plain/text', - 1 => 'plain/text'), - 'size' => array( + 1 => 'plain/text'], + 'size' => [ 0 => 8, - 1 => 8), - 'tmp_name' => array( + 1 => 8], + 'tmp_name' => [ 0 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt', - 1 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'), - 'error' => array( + 1 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'], + 'error' => [ 0 => 0, - 1 => 0))); + 1 => 0]]]; $adapter = new HttpTestMockAdapter(); - $adapter->setOptions(array('ignoreNoFile' => true)); + $adapter->setOptions(['ignoreNoFile' => true]); $this->assertTrue($adapter->receive('exe')); $this->assertEquals( - array('exe_0_' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt', - 'exe_1_' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'), + ['exe_0_' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt', + 'exe_1_' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'], $adapter->getFileName('exe', false)); } @@ -195,18 +195,18 @@ public function testUploadProgressFailure() $_GET['progress_key'] = 'mykey'; $status = HttpTestMockAdapter::getProgress(); - $this->assertEquals(array( + $this->assertEquals([ 'total' => 100, 'current' => 100, 'rate' => 10, 'id' => 'mykey', 'done' => false, 'message' => '100B - 100B' - ), $status); + ], $status); $this->adapter->switchApcToUP(); $status = HttpTestMockAdapter::getProgress($status); - $this->assertEquals(array( + $this->assertEquals([ 'total' => 100, 'bytes_total' => 100, 'current' => 100, @@ -217,7 +217,7 @@ public function testUploadProgressFailure() 'message' => 'The upload has been canceled', 'done' => true, 'id' => 'mykey' - ), $status); + ], $status); } public function testUploadProgressAdapter() @@ -228,7 +228,7 @@ public function testUploadProgressAdapter() $_GET['progress_key'] = 'mykey'; $adapter = new AdapterProgressBar\Console(); - $status = array('progress' => $adapter, 'session' => 'upload'); + $status = ['progress' => $adapter, 'session' => 'upload']; $status = HttpTestMockAdapter::getProgress($status); $this->assertArrayHasKey('total', $status); $this->assertArrayHasKey('current', $status); @@ -253,7 +253,7 @@ public function testValidationOfPhpExtendsFormError() { $_SERVER['CONTENT_LENGTH'] = 10; - $_FILES = array(); + $_FILES = []; $adapter = new HttpTestMockAdapter(); $this->assertFalse($adapter->isValidParent()); $this->assertContains('exceeds the defined ini size', current($adapter->getMessages())); diff --git a/test/Transfer/Adapter/HttpTestMockAdapter.php b/test/Transfer/Adapter/HttpTestMockAdapter.php index b24dba2..ba0aa63 100644 --- a/test/Transfer/Adapter/HttpTestMockAdapter.php +++ b/test/Transfer/Adapter/HttpTestMockAdapter.php @@ -20,7 +20,7 @@ class HttpTestMockAdapter extends Adapter\Http { public function __construct() { - self::$callbackApc = array('ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'apcTest'); + self::$callbackApc = ['ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'apcTest']; parent::__construct(); } @@ -41,17 +41,17 @@ public static function isApcAvailable() public static function apcTest($id) { - return array('total' => 100, 'current' => 100, 'rate' => 10); + return ['total' => 100, 'current' => 100, 'rate' => 10]; } public static function uPTest($id) { - return array('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() { self::$callbackApc = null; - self::$callbackUploadProgress = array('ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'uPTest'); + self::$callbackUploadProgress = ['ZendTest\File\Transfer\Adapter\HttpTestMockAdapter', 'uPTest']; } }