From 7a6b3b4155e63b6bc5f305bef95f076777aa3c19 Mon Sep 17 00:00:00 2001 From: Tinsh Date: Sat, 24 Nov 2018 15:13:24 +0800 Subject: [PATCH] style(*): start using short array syntax --- system/tests/kohana/ArrTest.php | 685 ++++++----- .../tests/kohana/Config/File/ReaderTest.php | 22 +- system/tests/kohana/Config/GroupTest.php | 29 +- system/tests/kohana/ConfigTest.php | 66 +- system/tests/kohana/CookieTest.php | 106 +- system/tests/kohana/CoreTest.php | 133 +- system/tests/kohana/DateTest.php | 449 +++---- system/tests/kohana/DebugTest.php | 82 +- system/tests/kohana/ExceptionTest.php | 32 +- system/tests/kohana/FeedTest.php | 70 +- system/tests/kohana/FileTest.php | 15 +- system/tests/kohana/FormTest.php | 240 ++-- system/tests/kohana/HTMLTest.php | 218 ++-- system/tests/kohana/HTTPTest.php | 52 +- system/tests/kohana/Http/HeaderTest.php | 1071 ++++++++--------- system/tests/kohana/I18nTest.php | 24 +- system/tests/kohana/InflectorTest.php | 114 +- system/tests/kohana/LogTest.php | 21 +- system/tests/kohana/NumTest.php | 102 +- system/tests/kohana/RequestTest.php | 364 +++--- system/tests/kohana/ResponseTest.php | 61 +- system/tests/kohana/RouteTest.php | 371 +++--- system/tests/kohana/SecurityTest.php | 19 +- system/tests/kohana/SessionTest.php | 100 +- system/tests/kohana/TextTest.php | 516 ++++---- system/tests/kohana/URLTest.php | 423 +++++-- system/tests/kohana/UTF8Test.php | 270 ++--- system/tests/kohana/UploadTest.php | 147 +-- system/tests/kohana/ValidTest.php | 593 ++++----- system/tests/kohana/ValidationTest.php | 314 +++-- system/tests/kohana/ViewTest.php | 26 +- system/tests/kohana/request/ClientTest.php | 234 ++-- .../kohana/request/client/ExternalTest.php | 102 +- .../kohana/request/client/InternalTest.php | 28 +- system/tests/test_data/callback_routes.php | 16 +- .../messages/kohana_core_message_tests.php | 4 +- .../messages/kohana_core_message_tests.php | 4 +- 37 files changed, 3836 insertions(+), 3287 deletions(-) diff --git a/system/tests/kohana/ArrTest.php b/system/tests/kohana/ArrTest.php index fe690fe..37edae1 100644 --- a/system/tests/kohana/ArrTest.php +++ b/system/tests/kohana/ArrTest.php @@ -25,20 +25,35 @@ class Kohana_ArrTest extends Unittest_TestCase */ public function provider_callback() { - return array( + return [ // Tests.... // That no parameters returns null - array('function', array('function', NULL)), + [ + 'function', + ['function', NULL] + ], // That we can get an array of parameters values - array('function(1,2,3)', array('function', array('1', '2', '3'))), + [ + 'function(1,2,3)', + ['function', ['1', '2', '3']] + ], // That it's not just using the callback "function" - array('different_name(harry,jerry)', array('different_name', array('harry', 'jerry'))), + [ + 'different_name(harry,jerry)', + ['different_name', ['harry', 'jerry']] + ], // That static callbacks are parsed into arrays - array('kohana::appify(this)', array(array('kohana', 'appify'), array('this'))), + [ + 'kohana::appify(this)', + [['kohana', 'appify'], ['this']] + ], // Spaces are preserved in parameters - array('deal::make(me, my mate )', array(array('deal', 'make'), array('me', ' my mate '))) + [ + 'deal::make(me, my mate )', + [['deal', 'make'], ['me', ' my mate ']] + ], // TODO: add more cases - ); + ]; } /** @@ -64,52 +79,83 @@ public function test_callback($str, $expected) */ public function provider_extract() { - return array( - array( - array('kohana' => 'awesome', 'blueflame' => 'was'), - array('kohana', 'cakephp', 'symfony'), + return [ + [ + [ + 'kohana' => 'awesome', + 'blueflame' => 'was' + ], + ['kohana', 'cakephp', 'symfony'], NULL, - array('kohana' => 'awesome', 'cakephp' => NULL, 'symfony' => NULL) - ), + [ + 'kohana' => 'awesome', + 'cakephp' => NULL, + 'symfony' => NULL + ] + ], // I realise noone should EVER code like this in real life, // but unit testing is very very very very boring - array( - array('chocolate cake' => 'in stock', 'carrot cake' => 'in stock'), - array('carrot cake', 'humble pie'), + [ + [ + 'chocolate cake' => 'in stock', + 'carrot cake' => 'in stock' + ], + ['carrot cake', 'humble pie'], 'not in stock', - array('carrot cake' => 'in stock', 'humble pie' => 'not in stock'), - ), - array( + [ + 'carrot cake' => 'in stock', + 'humble pie' => 'not in stock' + ] + ], + [ // Source Array - array('level1' => array('level2a' => 'value 1', 'level2b' => 'value 2')), + [ + 'level1' => ['level2a' => 'value 1', 'level2b' => 'value 2'] + ], // Paths to extract - array('level1.level2a', 'level1.level2b'), + ['level1.level2a', 'level1.level2b'], // Default NULL, // Expected Result - array('level1' => array('level2a' => 'value 1', 'level2b' => 'value 2')), - ), - array( + [ + 'level1' => ['level2a' => 'value 1', 'level2b' => 'value 2'] + ] + ], + [ // Source Array - array('level1a' => array('level2a' => 'value 1'), 'level1b' => array('level2b' => 'value 2')), + [ + 'level1a' => ['level2a' => 'value 1'], + 'level1b' => ['level2b' => 'value 2'] + ], // Paths to extract - array('level1a', 'level1b.level2b'), + ['level1a', 'level1b.level2b'], // Default NULL, // Expected Result - array('level1a' => array('level2a' => 'value 1'), 'level1b' => array('level2b' => 'value 2')), - ), - array( + [ + 'level1a' => ['level2a' => 'value 1'], + 'level1b' => ['level2b' => 'value 2'] + ] + ], + [ // Source Array - array('level1a' => array('level2a' => 'value 1'), 'level1b' => array('level2b' => 'value 2')), + [ + 'level1a' => ['level2a' => 'value 1'], + 'level1b' => ['level2b' => 'value 2'] + ], // Paths to extract - array('level1a', 'level1b.level2b', 'level1c', 'level1d.notfound'), + ['level1a', 'level1b.level2b', 'level1c', 'level1d.notfound'], // Default 'default', // Expected Result - array('level1a' => array('level2a' => 'value 1'), 'level1b' => array('level2b' => 'value 2'), 'level1c' => 'default', 'level1d' => array('notfound' => 'default')), - ), - ); + [ + 'level1a' => ['level2a' => 'value 1'], + 'level1b' => ['level2b' => 'value 2'], + 'level1c' => 'default', + 'level1d' => ['notfound' => 'default'] + ] + ], + ]; } /** @@ -137,17 +183,17 @@ public function test_extract(array $array, array $paths, $default, $expected) */ public function provider_pluck() { - return array( - array( - array( - array('id' => 20, 'name' => 'John Smith'), - array('name' => 'Linda'), - array('id' => 25, 'name' => 'Fred'), - ), + return [ + [ + [ + ['id' => 20, 'name' => 'John Smith'], + ['name' => 'Linda'], + ['id' => 25, 'name' => 'Fred'], + ], 'id', - array(20, 25) - ), - ); + [20, 25] + ], + ]; } /** @@ -174,14 +220,14 @@ public function test_pluck(array $array, $key, $expected) */ public function provider_get() { - return array( - array(array('uno', 'dos', 'tress'), 1, NULL, 'dos'), - array(array('we' => 'can', 'make' => 'change'), 'we', NULL, 'can'), - array(array('uno', 'dos', 'tress'), 10, NULL, NULL), - array(array('we' => 'can', 'make' => 'change'), 'he', NULL, NULL), - array(array('we' => 'can', 'make' => 'change'), 'he', 'who', 'who'), - array(array('we' => 'can', 'make' => 'change'), 'he', array('arrays'), array('arrays')), - ); + return [ + [['uno', 'dos', 'tress'], 1, NULL, 'dos'], + [['we' => 'can', 'make' => 'change'], 'we', NULL, 'can'], + [['uno', 'dos', 'tress'], 10, NULL, NULL], + [['we' => 'can', 'make' => 'change'], 'he', NULL, NULL], + [['we' => 'can', 'make' => 'change'], 'he', 'who', 'who'], + [['we' => 'can', 'make' => 'change'], 'he', ['arrays'], ['arrays']], + ]; } /** @@ -208,10 +254,16 @@ public function test_get(array $array, $key, $default, $expected) */ public function provider_is_assoc() { - return array( - array(array('one', 'two', 'three'), FALSE), - array(array('one' => 'o clock', 'two' => 'o clock', 'three' => 'o clock'), TRUE), - ); + return [ + [ + ['one', 'two', 'three'], + FALSE + ], + [ + ['one' => 'o clock', 'two' => 'o clock', 'three' => 'o clock'], + TRUE + ], + ]; } /** @@ -236,13 +288,13 @@ public function test_is_assoc(array $array, $expected) */ public function provider_is_array() { - return array( - array($a = array('one', 'two', 'three'), TRUE), - array(new ArrayObject($a), TRUE), - array(new ArrayIterator($a), TRUE), - array('not an array', FALSE), - array(new stdClass, FALSE), - ); + return [ + [$a = ['one', 'two', 'three'], TRUE], + [new ArrayObject($a), TRUE], + [new ArrayIterator($a), TRUE], + ['not an array', FALSE], + [new stdClass, FALSE], + ]; } /** @@ -262,121 +314,121 @@ public function test_is_array($array, $expected) public function provider_merge() { - return array( + return [ // Test how it merges arrays and sub arrays with assoc keys - array( - array('name' => 'mary', 'children' => array('fred', 'paul', 'sally', 'jane')), - array('name' => 'john', 'children' => array('fred', 'paul', 'sally', 'jane')), - array('name' => 'mary', 'children' => array('jane')), - ), + [ + ['name' => 'mary', 'children' => ['fred', 'paul', 'sally', 'jane']], + ['name' => 'john', 'children' => ['fred', 'paul', 'sally', 'jane']], + ['name' => 'mary', 'children' => ['jane']] + ], // See how it merges sub-arrays with numerical indexes - array( - array(array('test1'), array('test2'), array('test3')), - array(array('test1'), array('test2')), - array(array('test2'), array('test3')), - ), - array( - array(array(array('test1')), array(array('test2')), array(array('test3'))), - array(array(array('test1')), array(array('test2'))), - array(array(array('test2')), array(array('test3'))), - ), - array( - array('a' => array('test1', 'test2'), 'b' => array('test2', 'test3')), - array('a' => array('test1'), 'b' => array('test2')), - array('a' => array('test2'), 'b' => array('test3')), - ), - array( - array('digits' => array(0, 1, 2, 3)), - array('digits' => array(0, 1)), - array('digits' => array(2, 3)), - ), + [ + [['test1'], ['test2'], ['test3']], + [['test1'], ['test2']], + [['test2'], ['test3']] + ], + [ + [[['test1']], [['test2']], [['test3']]], + [[['test1']], [['test2']]], + [[['test2']], [['test3']]] + ], + [ + ['a' => ['test1', 'test2'], 'b' => ['test2', 'test3']], + ['a' => ['test1'], 'b' => ['test2']], + ['a' => ['test2'], 'b' => ['test3']] + ], + [ + ['digits' => [0, 1, 2, 3]], + ['digits' => [0, 1]], + ['digits' => [2, 3]] + ], // See how it manages merging items with numerical indexes - array( - array(0, 1, 2, 3), - array(0, 1), - array(2, 3), - ), + [ + [0, 1, 2, 3], + [0, 1], + [2, 3] + ], // Try and get it to merge assoc. arrays recursively - array( - array('foo' => 'bar', array('temp' => 'life')), - array('foo' => 'bin', array('temp' => 'name')), - array('foo' => 'bar', array('temp' => 'life')), - ), + [ + ['foo' => 'bar', ['temp' => 'life']], + ['foo' => 'bin', ['temp' => 'name']], + ['foo' => 'bar', ['temp' => 'life']] + ], // Bug #3139 - array( - array('foo' => array('bar')), - array('foo' => 'bar'), - array('foo' => array('bar')), - ), - array( - array('foo' => 'bar'), - array('foo' => array('bar')), - array('foo' => 'bar'), - ), + [ + ['foo' => ['bar']], + ['foo' => 'bar'], + ['foo' => ['bar']] + ], + [ + ['foo' => 'bar'], + ['foo' => ['bar']], + ['foo' => 'bar'] + ], // data set #9 // Associative, Associative - array( - array('a' => 'K', 'b' => 'K', 'c' => 'L'), - array('a' => 'J', 'b' => 'K'), - array('a' => 'K', 'c' => 'L'), - ), + [ + ['a' => 'K', 'b' => 'K', 'c' => 'L'], + ['a' => 'J', 'b' => 'K'], + ['a' => 'K', 'c' => 'L'] + ], // Associative, Indexed - array( - array('a' => 'J', 'b' => 'K', 'L'), - array('a' => 'J', 'b' => 'K'), - array('K', 'L'), - ), + [ + ['a' => 'J', 'b' => 'K', 'L'], + ['a' => 'J', 'b' => 'K'], + ['K', 'L'] + ], // Associative, Mixed - array( - array('a' => 'J', 'b' => 'K', 'K', 'c' => 'L'), - array('a' => 'J', 'b' => 'K'), - array('K', 'c' => 'L'), - ), + [ + ['a' => 'J', 'b' => 'K', 'K', 'c' => 'L'], + ['a' => 'J', 'b' => 'K'], + ['K', 'c' => 'L'] + ], // data set #12 // Indexed, Associative - array( - array('J', 'K', 'a' => 'K', 'c' => 'L'), - array('J', 'K'), - array('a' => 'K', 'c' => 'L'), - ), + [ + ['J', 'K', 'a' => 'K', 'c' => 'L'], + ['J', 'K'], + ['a' => 'K', 'c' => 'L'] + ], // Indexed, Indexed - array( - array('J', 'K', 'L'), - array('J', 'K'), - array('K', 'L'), - ), + [ + ['J', 'K', 'L'], + ['J', 'K'], + ['K', 'L'] + ], // Indexed, Mixed - array( - array('K', 'K', 'c' => 'L'), - array('J', 'K'), - array('K', 'c' => 'L'), - ), + [ + ['K', 'K', 'c' => 'L'], + ['J', 'K'], + ['K', 'c' => 'L'] + ], // data set #15 // Mixed, Associative - array( - array('a' => 'K', 'K', 'c' => 'L'), - array('a' => 'J', 'K'), - array('a' => 'K', 'c' => 'L'), - ), + [ + ['a' => 'K', 'K', 'c' => 'L'], + ['a' => 'J', 'K'], + ['a' => 'K', 'c' => 'L'] + ], // Mixed, Indexed - array( - array('a' => 'J', 'K', 'L'), - array('a' => 'J', 'K'), - array('J', 'L'), - ), + [ + ['a' => 'J', 'K', 'L'], + ['a' => 'J', 'K'], + ['J', 'L'] + ], // Mixed, Mixed - array( - array('a' => 'K', 'L'), - array('a' => 'J', 'K'), - array('a' => 'K', 'L'), - ), + [ + ['a' => 'K', 'L'], + ['a' => 'J', 'K'], + ['a' => 'K', 'L'] + ], // Bug #3141 - array( - array('servers' => array(array('1.1.1.1', 4730), array('2.2.2.2', 4730))), - array('servers' => array(array('1.1.1.1', 4730))), - array('servers' => array(array('2.2.2.2', 4730))), - ), - ); + [ + ['servers' => [['1.1.1.1', 4730], ['2.2.2.2', 4730]]], + ['servers' => [['1.1.1.1', 4730]]], + ['servers' => [['2.2.2.2', 4730]]] + ], + ]; } /** @@ -398,45 +450,118 @@ public function test_merge($expected, $array1, $array2) */ public function provider_path() { - $array = array( - 'foobar' => array('definition' => 'lost'), + $array = [ + 'foobar' => ['definition' => 'lost'], 'kohana' => 'awesome', - 'users' => array( - 1 => array('name' => 'matt'), - 2 => array('name' => 'john', 'interests' => array('hocky' => array('length' => 2), 'football' => array())), + 'users' => [ + 1 => ['name' => 'matt'], + 2 => [ + 'name' => 'john', + 'interests' => [ + 'hocky' => ['length' => 2], + 'football' => [] + ] + ], 3 => 'frank', // Issue #3194 - ), - 'object' => new ArrayObject(array('iterator' => TRUE)), // Iterable object should work exactly the same - ); + ], + // Iterable object should work exactly the same + 'object' => new ArrayObject(['iterator' => TRUE]), + ]; - return array( + return [ // Tests returns normal values - array($array['foobar'], $array, 'foobar'), - array($array['kohana'], $array, 'kohana'), - array($array['foobar']['definition'], $array, 'foobar.definition'), + [ + $array['foobar'], + $array, + 'foobar' + ], + [ + $array['kohana'], + $array, + 'kohana' + ], + [ + $array['foobar']['definition'], + $array, + 'foobar.definition' + ], // Custom delimiters - array($array['foobar']['definition'], $array, 'foobar/definition', NULL, '/'), + [ + $array['foobar']['definition'], + $array, + 'foobar/definition', + NULL, + '/' + ], // We should be able to use NULL as a default, returned if the key DNX - array(NULL, $array, 'foobar.alternatives', NULL), - array(NULL, $array, 'kohana.alternatives', NULL), + [ + NULL, + $array, + 'foobar.alternatives', + NULL + ], + [ + NULL, + $array, + 'kohana.alternatives', + NULL + ], // Try using a string as a default - array('nothing', $array, 'kohana.alternatives', 'nothing'), + [ + 'nothing', + $array, + 'kohana.alternatives', + 'nothing' + ], // Make sure you can use arrays as defaults - array(array('far', 'wide'), $array, 'cheese.origins', array('far', 'wide')), + [ + ['far', 'wide'], + $array, + 'cheese.origins', + ['far', 'wide'] + ], // Ensures path() casts ints to actual integers for keys - array($array['users'][1]['name'], $array, 'users.1.name'), + [ + $array['users'][1]['name'], + $array, + 'users.1.name' + ], // Test that a wildcard returns the entire array at that "level" - array($array['users'], $array, 'users.*'), + [ + $array['users'], + $array, + 'users.*' + ], // Now we check that keys after a wilcard will be processed - array(array(0 => array(0 => 2)), $array, 'users.*.interests.*.length'), + [ + [0 => [0 => 2]], + $array, + 'users.*.interests.*.length' + ], // See what happens when it can't dig any deeper from a wildcard - array(NULL, $array, 'users.*.fans'), + [ + NULL, + $array, + 'users.*.fans' + ], // Starting wildcards, issue #3269 - array(array('matt', 'john'), $array['users'], '*.name'), + [ + ['matt', 'john'], + $array['users'], + '*.name' + ], // Path as array, issue #3260 - array($array['users'][2]['name'], $array, array('users', 2, 'name')), - array($array['object']['iterator'], $array, 'object.iterator'), - ); + [ + $array['users'][2]['name'], + $array, + ['users', 2, 'name'] + ], + [ + $array['object']['iterator'], + $array, + 'object.iterator' + ], + ]; } /** @@ -463,19 +588,49 @@ public function test_path($expected, $array, $path, $default = NULL, $delimiter */ public function provider_set_path() { - return array( + return [ // Tests returns normal values - array(array('foo' => 'bar'), array(), 'foo', 'bar'), - array(array('kohana' => array('is' => 'awesome')), array(), 'kohana.is', 'awesome'), - array(array('kohana' => array('is' => 'cool', 'and' => 'slow')), - array('kohana' => array('is' => 'cool')), 'kohana.and', 'slow'), + [ + ['foo' => 'bar'], + [], + 'foo', + 'bar' + ], + [ + ['kohana' => ['is' => 'awesome']], + [], + 'kohana.is', + 'awesome' + ], + [ + ['kohana' => ['is' => 'cool', 'and' => 'slow']], + ['kohana' => ['is' => 'cool']], + 'kohana.and', + 'slow' + ], // Custom delimiters - array(array('kohana' => array('is' => 'awesome')), array(), 'kohana/is', 'awesome', '/'), + [ + ['kohana' => ['is' => 'awesome']], + [], + 'kohana/is', + 'awesome', + '/' + ], // Ensures set_path() casts ints to actual integers for keys - array(array('foo' => array('bar')), array('foo' => array('test')), 'foo.0', 'bar'), + [ + ['foo' => ['bar']], + ['foo' => ['test']], + 'foo.0', + 'bar' + ], // Tests if it allows arrays - array(array('kohana' => array('is' => 'awesome')), array(), array('kohana', 'is'), 'awesome'), - ); + [ + ['kohana' => ['is' => 'awesome']], + [], + ['kohana', 'is'], + 'awesome' + ], + ]; } /** @@ -501,11 +656,11 @@ public function test_set_path($expected, $array, $path, $value, $delimiter = NUL */ public function provider_range() { - return array( - array(1, 2), - array(1, 100), - array(25, 10), - ); + return [ + [1, 2], + [1, 100], + [25, 10], + ]; } /** @@ -538,10 +693,10 @@ public function test_range($step, $max) */ public function provider_unshift() { - return array( - array(array('one' => '1', 'two' => '2',), 'zero', '0'), - array(array('step 1', 'step 2', 'step 3'), 'step 0', 'wow') - ); + return [ + [['one' => '1', 'two' => '2'], 'zero', '0'], + [['step 1', 'step 2', 'step 3'], 'step 0', 'wow'], + ]; } /** @@ -574,14 +729,24 @@ public function test_unshift(array $array, $key, $value) */ public function provider_overwrite() { - return array( - array( - array('name' => 'Henry', 'mood' => 'tired', 'food' => 'waffles', 'sport' => 'checkers'), - array('name' => 'John', 'mood' => 'bored', 'food' => 'bacon', 'sport' => 'checkers'), - array('name' => 'Matt', 'mood' => 'tired', 'food' => 'waffles'), - array('name' => 'Henry', 'age' => 18,), - ), - ); + return [ + [ + [ + 'name' => 'Henry', + 'mood' => 'tired', + 'food' => 'waffles', + 'sport' => 'checkers' + ], + [ + 'name' => 'John', + 'mood' => 'bored', + 'food' => 'bacon', + 'sport' => 'checkers' + ], + ['name' => 'Matt', 'mood' => 'tired', 'food' => 'waffles'], + ['name' => 'Henry', 'age' => 18] + ], + ]; } /** @@ -589,7 +754,7 @@ public function provider_overwrite() * @test * @dataProvider provider_overwrite */ - public function test_overwrite($expected, $arr1, $arr2, $arr3 = array(), $arr4 = array()) + public function test_overwrite($expected, $arr1, $arr2, $arr3 = [], $arr4 = []) { $this->assertSame( $expected, Arr::overwrite($arr1, $arr2, $arr3, $arr4) @@ -603,65 +768,44 @@ public function test_overwrite($expected, $arr1, $arr2, $arr3 = array(), $arr4 = */ public function provider_map() { - return array( - array('strip_tags', array('

foobar

'), NULL, array('foobar')), - array('strip_tags', array(array('

foobar

'), array('

foobar

')), NULL, array(array('foobar'), array('foobar'))), - array( + return [ + [ 'strip_tags', - array( - 'foo' => '

foobar

', - 'bar' => '

foobar

', - ), + ['

foobar

'], NULL, - array( - 'foo' => 'foobar', - 'bar' => 'foobar', - ), - ), - array( + ['foobar'] + ], + [ 'strip_tags', - array( - 'foo' => '

foobar

', - 'bar' => '

foobar

', - ), - array('foo'), - array( - 'foo' => 'foobar', - 'bar' => '

foobar

', - ), - ), - array( - array( - 'strip_tags', - 'trim', - ), - array( - 'foo' => '

foobar

', - 'bar' => '

foobar

', - ), + [['

foobar

'], ['

foobar

']], NULL, - array( - 'foo' => 'foobar', - 'bar' => 'foobar', - ), - ), - array( + [['foobar'], ['foobar']] + ], + [ 'strip_tags', - array( - array( - 'foo' => '

foobar

', - 'bar' => '

foobar

', - ), - ), - array('foo'), - array( - array( - 'foo' => 'foobar', - 'bar' => '

foobar

', - ), - ), - ), - ); + ['foo' => '

foobar

', 'bar' => '

foobar

'], + NULL, + ['foo' => 'foobar', 'bar' => 'foobar'] + ], + [ + 'strip_tags', + ['foo' => '

foobar

', 'bar' => '

foobar

'], + ['foo'], + ['foo' => 'foobar', 'bar' => '

foobar

'] + ], + [ + ['strip_tags', 'trim',], + ['foo' => '

foobar

', 'bar' => '

foobar

'], + NULL, + ['foo' => 'foobar', 'bar' => 'foobar'] + ], + [ + 'strip_tags', + [['foo' => '

foobar

', 'bar' => '

foobar

']], + ['foo'], + [['foo' => 'foobar', 'bar' => '

foobar

']] + ], + ]; } /** @@ -683,9 +827,12 @@ public function test_map($method, $source, $keys, $expected) */ public function provider_flatten() { - return array( - array(array('set' => array('one' => 'something'), 'two' => 'other'), array('one' => 'something', 'two' => 'other')), - ); + return [ + [ + ['set' => ['one' => 'something'], 'two' => 'other'], + ['one' => 'something', 'two' => 'other'] + ], + ]; } /** diff --git a/system/tests/kohana/Config/File/ReaderTest.php b/system/tests/kohana/Config/File/ReaderTest.php index 7da84cc..122bfcb 100644 --- a/system/tests/kohana/Config/File/ReaderTest.php +++ b/system/tests/kohana/Config/File/ReaderTest.php @@ -18,7 +18,7 @@ class Kohana_Config_File_ReaderTest extends Kohana_Unittest_TestCase { /** - * If we don't pass a directory to the reader then it should assume + * If we don't pass a directory to the reader then it should assume * that we want to search the dir 'config' by default * * @test @@ -32,7 +32,7 @@ public function test_default_search_dir_is_config() } /** - * If we pass a directory to the constructor of the file reader it + * If we pass a directory to the constructor of the file reader it * should change the search directory * * @test @@ -46,7 +46,7 @@ public function test_constructor_sets_search_dir_from_param() } /** - * If the config dir does not exist then the function should just + * If the config dir does not exist then the function should just * return an empty array * * @test @@ -56,11 +56,11 @@ public function test_load_returns_empty_array_if_conf_dir_dnx() { $config = new Kohana_Config_File_Reader('gafloogle'); - $this->assertSame(array(), $config->load('values')); + $this->assertSame([], $config->load('values')); } /** - * If the requested config group does not exist then the reader + * If the requested config group does not exist then the reader * should return an empty array * * @test @@ -70,11 +70,11 @@ public function test_load_returns_empty_array_if_conf_dnx() { $config = new Kohana_Config_File_Reader; - $this->assertSame(array(), $config->load('gafloogle')); + $this->assertSame([], $config->load('gafloogle')); } /** - * Test that the load() function is actually loading the + * Test that the load() function is actually loading the * configuration from the files. * * @test @@ -86,11 +86,11 @@ public function test_loads_config_from_files() $values = $config->load('inflector'); - // Due to the way the cascading filesystem works there could be - // any number of modifications to the system config in the - // actual output. Therefore to increase compatability we just + // Due to the way the cascading filesystem works there could be + // any number of modifications to the system config in the + // actual output. Therefore to increase compatability we just // check that we've got an array and that it's not empty - $this->assertNotSame(array(), $values); + $this->assertNotSame([], $values); $this->assertInternalType('array', $values); } diff --git a/system/tests/kohana/Config/GroupTest.php b/system/tests/kohana/Config/GroupTest.php index a67a6de..637cdc7 100644 --- a/system/tests/kohana/Config/GroupTest.php +++ b/system/tests/kohana/Config/GroupTest.php @@ -35,7 +35,7 @@ public function get_mock_config() * @param Kohana_Config $instance Instance of Kohana_Config * @return Kohana_Config_Group */ - public function get_mock_group($group, $config = array(), $instance = NULL) + public function get_mock_group($group, $config = [], $instance = NULL) { if ($instance === NULL) { $instance = $this->get_mock_config(); @@ -54,7 +54,7 @@ public function get_mock_group($group, $config = array(), $instance = NULL) public function test_loads_group_name_and_values_in_constructor() { $group_name = 'information'; - $group_values = array('var' => 'value'); + $group_values = ['var' => 'value']; $group = $this->get_mock_group($group_name, $group_values); @@ -77,7 +77,7 @@ public function test_allows_empty_group_values() { $group = $this->get_mock_group('informatica'); - $this->assertSame(array(), $group->getArrayCopy()); + $this->assertSame([], $group->getArrayCopy()); } /** @@ -88,7 +88,7 @@ public function test_allows_empty_group_values() */ public function test_get_fetches_config_value() { - $group = $this->get_mock_group('kohana', array('status' => 'awesome')); + $group = $this->get_mock_group('kohana', ['status' => 'awesome']); $this->assertSame('awesome', $group->get('status')); } @@ -116,7 +116,7 @@ public function test_get_returns_default_value_if_config_option_dnx() */ public function test_set_modifies_existing_config() { - $group = $this->get_mock_group('kohana', array('status' => 'pre-awesome')); + $group = $this->get_mock_group('kohana', ['status' => 'pre-awesome']); $group->set('status', 'awesome'); @@ -126,7 +126,7 @@ public function test_set_modifies_existing_config() /** * If we modify the config via set() [$var] or ->$var then the change should be passed to * the parent config instance so that the config writers can be notified. - * + * * The modification to the config should also stick * * @test @@ -142,7 +142,7 @@ public function test_writes_changes_to_config() ->method('_write_config') ->with('kohana', 'status', $this->LogicalOr('totally', 'maybe', 'not')); - $group = $this->get_mock_group('kohana', array('status' => 'kool'), $mock); + $group = $this->get_mock_group('kohana', ['status' => 'kool'], $mock); $group['status'] = 'totally'; @@ -159,21 +159,22 @@ public function test_writes_changes_to_config() */ public function test_as_array_returns_full_array() { - $config = $this->get_mock_group('something', array('var' => 'value')); + $config = $this->get_mock_group('something', ['var' => 'value']); - $this->assertSame(array('var' => 'value'), $config->as_array()); + $this->assertSame(['var' => 'value'], $config->as_array()); // Now change some vars **ahem** $config->var = 'LOLCAT'; $config->lolcat = 'IN UR CODE'; - $this->assertSame( - array('var' => 'LOLCAT', 'lolcat' => 'IN UR CODE'), $config->as_array() - ); + $this->assertSame([ + 'var' => 'LOLCAT', + 'lolcat' => 'IN UR CODE' + ], $config->as_array()); // And if we remove an item it should be removed from the exported array unset($config['lolcat']); - $this->assertSame(array('var' => 'LOLCAT'), $config->as_array()); + $this->assertSame(['var' => 'LOLCAT'], $config->as_array()); } /** @@ -184,7 +185,7 @@ public function test_as_array_returns_full_array() */ public function test_to_string_serializes_array_output() { - $vars = array('kohana' => 'cool', 'unit_tests' => 'boring'); + $vars = ['kohana' => 'cool', 'unit_tests' => 'boring']; $config = $this->get_mock_group('hehehe', $vars); $this->assertSame(serialize($vars), (string) $config); diff --git a/system/tests/kohana/ConfigTest.php b/system/tests/kohana/ConfigTest.php index ae87358..f3601f2 100644 --- a/system/tests/kohana/ConfigTest.php +++ b/system/tests/kohana/ConfigTest.php @@ -30,7 +30,7 @@ public function test_initially_there_are_no_sources() { $config = new Config; - $this->assertAttributeSame(array(), '_sources', $config); + $this->assertAttributeSame([], '_sources', $config); } /** @@ -69,7 +69,7 @@ public function test_attach_adds_reader_to_front_of_queue() // Rather than do two assertContains we'll do an assertSame to assert // the order of the readers - $this->assertAttributeSame(array($reader2, $reader1), '_sources', $config); + $this->assertAttributeSame([$reader2, $reader1], '_sources', $config); // Now we test using the second parameter $config = new Config; @@ -77,7 +77,7 @@ public function test_attach_adds_reader_to_front_of_queue() $config->attach($reader1); $config->attach($reader2, TRUE); - $this->assertAttributeSame(array($reader2, $reader1), '_sources', $config); + $this->assertAttributeSame([$reader2, $reader1], '_sources', $config); } /** @@ -96,7 +96,7 @@ public function test_attach_can_add_reader_to_end_of_queue() $config->attach($reader1); $config->attach($reader2, FALSE); - $this->assertAttributeSame(array($reader1, $reader2), '_sources', $config); + $this->assertAttributeSame([$reader1, $reader2], '_sources', $config); } /** @@ -163,7 +163,7 @@ public function test_load_can_get_var_from_dot_path() ->expects($this->once()) ->method('load') ->with('beer') - ->will($this->returnValue(array('stout' => 'Guinness'))); + ->will($this->returnValue(['stout' => 'Guinness'])); $config->attach($reader); @@ -172,7 +172,7 @@ public function test_load_can_get_var_from_dot_path() /** * If we've already loaded a config group then the correct variable - * should be returned if we use the dot path notation to to request + * should be returned if we use the dot path notation to to request * a var * * @test @@ -189,7 +189,7 @@ public function test_load_can_get_var_from_dot_path_for_loaded_group() $reader->expects($this->once()) ->method('load') ->with('beer') - ->will($this->returnValue(array('stout' => 'Guinness'))); + ->will($this->returnValue(['stout' => 'Guinness'])); $config->attach($reader); @@ -222,13 +222,13 @@ public function test_load_throws_exception_if_there_are_no_sources() */ public function provider_load_throws_exception_if_no_group_is_given() { - return array( - array(NULL), - array(''), - array(array()), - array(array('foo' => 'bar')), - array(new StdClass), - ); + return [ + [NULL], + [''], + [[]], + [['foo' => 'bar']], + [new StdClass], + ]; } /** @@ -253,7 +253,7 @@ public function test_load_throws_exception_if_invalid_group($value) } /** - * Make sure that _write_config() passes the changed configuration to all + * Make sure that _write_config() passes the changed configuration to all * writers in the queue * * @test @@ -307,31 +307,32 @@ public function test_config_is_loaded_from_top_to_bottom_of_stack() $reader1->expects($this->once()) ->method('load') ->with($group_name) - ->will($this->returnValue(array('foo' => 'bar', 'kohana' => 'awesome', 'life' => array('normal', 'fated')))); + ->will($this->returnValue([ + 'foo' => 'bar', + 'kohana' => 'awesome', + 'life' => ['normal', 'fated'] + ])); $reader2->expects($this->once()) ->method('load') ->with($group_name) - ->will($this->returnValue(array('kohana' => 'sweet', 'music' => 'tasteful', 'life' => array('extraordinary', 'destined')))); + ->will($this->returnValue([ + 'kohana' => 'sweet', + 'music' => 'tasteful', + 'life' => ['extraordinary', 'destined'] + ])); $config = new Kohana_Config; // Attach $reader1 at the "top" and reader2 at the "bottom" $config->attach($reader1)->attach($reader2, FALSE); - $this->assertSame( - array( + $this->assertSame([ 'kohana' => 'awesome', 'music' => 'tasteful', - 'life' => array( - 'extraordinary', - 'destined', - 'normal', - 'fated', - ), + 'life' => ['extraordinary', 'destined', 'normal', 'fated'], 'foo' => 'bar', - ), $config->load($group_name)->as_array() - ); + ], $config->load($group_name)->as_array()); } /** @@ -350,7 +351,7 @@ public function test_load_reuses_config_groups() $reader->expects($this->once()) ->method('load') ->with('something') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); $config = new Kohana_Config; @@ -382,12 +383,15 @@ public function test_copy_copies_merged_config_to_all_writers() $reader1->expects($this->once()) ->method('load') ->with('something') - ->will($this->returnValue(array('pie' => 'good', 'kohana' => 'awesome'))); + ->will($this->returnValue([ + 'pie' => 'good', + 'kohana' => 'awesome' + ])); $reader2->expects($this->once()) ->method('load') ->with('something') - ->will($this->returnValue(array('kohana' => 'good'))); + ->will($this->returnValue(['kohana' => 'good'])); $writer1 = $this->getMockBuilder('Kohana_Config_Writer') ->setMethods(['write']) @@ -399,7 +403,7 @@ public function test_copy_copies_merged_config_to_all_writers() // Due to crazy limitations in phpunit's mocking engine we have to be fairly // liberal here as to what order we receive the config items // Good news is that order shouldn't matter *yay* - // + // // Now save your eyes and skip the next... 13 lines! $key = $this->logicalOr('pie', 'kohana'); $val = $this->logicalOr('good', 'awesome'); diff --git a/system/tests/kohana/CookieTest.php b/system/tests/kohana/CookieTest.php index d577b3d..05d7b13 100644 --- a/system/tests/kohana/CookieTest.php +++ b/system/tests/kohana/CookieTest.php @@ -30,12 +30,12 @@ public function setUp() // @codingStandardsIgnoreEnd { parent::setUp(); - Kohana_CookieTest_TestableCookie::$_mock_cookies_set = array(); + Kohana_CookieTest_TestableCookie::$_mock_cookies_set = []; - $this->setEnvironment(array( + $this->setEnvironment([ 'Cookie::$salt' => 'some-random-salt', 'HTTP_USER_AGENT' => 'cli' - )); + ]); } /** @@ -45,21 +45,21 @@ public function setUp() */ public function test_set_creates_cookie_with_configured_cookie_options() { - $this->setEnvironment(array( + $this->setEnvironment([ 'Cookie::$path' => '/path', 'Cookie::$domain' => 'my.domain', 'Cookie::$secure' => TRUE, 'Cookie::$httponly' => FALSE, - )); + ]); Kohana_CookieTest_TestableCookie::set('cookie', 'value'); - $this->assertSetCookieWith(array( + $this->assertSetCookieWith([ 'path' => '/path', 'domain' => 'my.domain', 'secure' => TRUE, 'httponly' => FALSE - )); + ]); } /** @@ -69,11 +69,11 @@ public function test_set_creates_cookie_with_configured_cookie_options() */ public function provider_set_calculates_expiry_from_lifetime() { - return array( - array(NULL, self::COOKIE_EXPIRATION + self::UNIX_TIMESTAMP), - array(0, 0), - array(10, 10 + self::UNIX_TIMESTAMP), - ); + return [ + [NULL, self::COOKIE_EXPIRATION + self::UNIX_TIMESTAMP], + [0, 0], + [10, 10 + self::UNIX_TIMESTAMP], + ]; } /** @@ -85,9 +85,11 @@ public function provider_set_calculates_expiry_from_lifetime() */ public function test_set_calculates_expiry_from_lifetime($expiration, $expect_expiry) { - $this->setEnvironment(array('Cookie::$expiration' => self::COOKIE_EXPIRATION)); + $this->setEnvironment([ + 'Cookie::$expiration' => self::COOKIE_EXPIRATION + ]); Kohana_CookieTest_TestableCookie::set('foo', 'bar', $expiration); - $this->assertSetCookieWith(array('expire' => $expect_expiry)); + $this->assertSetCookieWith(['expire' => $expect_expiry]); } /** @@ -117,10 +119,10 @@ public function test_get_returns_value_if_cookie_present_and_signed() */ public function provider_get_returns_default_without_deleting_if_cookie_unsigned() { - return array( - array('unsalted'), - array('un~salted'), - ); + return [ + ['unsalted'], + ['un~salted'], + ]; } /** @@ -201,13 +203,53 @@ public function test_salt_creates_same_hash_for_same_values_and_state() */ public function provider_salt_creates_different_hash_for_different_data() { - return array( - array(array('name' => 'foo', 'value' => 'bar', 'salt' => 'our-salt', 'user-agent' => 'Chrome'), array('name' => 'changed')), - array(array('name' => 'foo', 'value' => 'bar', 'salt' => 'our-salt', 'user-agent' => 'Chrome'), array('value' => 'changed')), - array(array('name' => 'foo', 'value' => 'bar', 'salt' => 'our-salt', 'user-agent' => 'Chrome'), array('salt' => 'changed-salt')), - array(array('name' => 'foo', 'value' => 'bar', 'salt' => 'our-salt', 'user-agent' => 'Chrome'), array('user-agent' => 'Firefox')), - array(array('name' => 'foo', 'value' => 'bar', 'salt' => 'our-salt', 'user-agent' => 'Chrome'), array('user-agent' => NULL)), - ); + return [ + [ + [ + 'name' => 'foo', + 'value' => 'bar', + 'salt' => 'our-salt', + 'user-agent' => 'Chrome' + ], + ['name' => 'changed'] + ], + [ + [ + 'name' => 'foo', + 'value' => 'bar', + 'salt' => 'our-salt', + 'user-agent' => 'Chrome' + ], + ['value' => 'changed'] + ], + [ + [ + 'name' => 'foo', + 'value' => 'bar', + 'salt' => 'our-salt', + 'user-agent' => 'Chrome' + ], + ['salt' => 'changed-salt'] + ], + [ + [ + 'name' => 'foo', + 'value' => 'bar', + 'salt' => 'our-salt', + 'user-agent' => 'Chrome' + ], + ['user-agent' => 'Firefox'] + ], + [ + [ + 'name' => 'foo', + 'value' => 'bar', + 'salt' => 'our-salt', + 'user-agent' => 'Chrome' + ], + ['user-agent' => NULL] + ], + ]; } /** @@ -220,8 +262,8 @@ public function provider_salt_creates_different_hash_for_different_data() public function test_salt_creates_different_hash_for_different_data($first_args, $changed_args) { $second_args = array_merge($first_args, $changed_args); - $hashes = array(); - foreach (array($first_args, $second_args) as $args) { + $hashes = []; + foreach ([$first_args, $second_args] as $args) { Cookie::$salt = $args['salt']; $this->set_or_remove_http_user_agent($args['user-agent']); @@ -243,7 +285,7 @@ protected function assertDeletedCookie($name) { $this->assertArrayNotHasKey($name, $_COOKIE); // To delete the client-side cookie, Cookie::delete should send a new cookie with value NULL and expiry in the past - $this->assertSetCookieWith(array( + $this->assertSetCookieWith([ 'name' => $name, 'value' => NULL, 'expire' => -86400, @@ -251,7 +293,7 @@ protected function assertDeletedCookie($name) 'domain' => Cookie::$domain, 'secure' => Cookie::$secure, 'httponly' => Cookie::$httponly - )); + ]); } /** @@ -293,14 +335,14 @@ class Kohana_CookieTest_TestableCookie extends Cookie /** * @var array setcookie calls that were made */ - public static $_mock_cookies_set = array(); + public static $_mock_cookies_set = []; /** * {@inheritdoc} */ protected static function _setcookie($name, $value, $expire, $path, $domain, $secure, $httponly) { - self::$_mock_cookies_set[] = array( + self::$_mock_cookies_set[] = [ 'name' => $name, 'value' => $value, 'expire' => $expire, @@ -308,7 +350,7 @@ protected static function _setcookie($name, $value, $expire, $path, $domain, $se 'domain' => $domain, 'secure' => $secure, 'httponly' => $httponly - ); + ]; return TRUE; } diff --git a/system/tests/kohana/CoreTest.php b/system/tests/kohana/CoreTest.php index 0fc7994..51fc888 100644 --- a/system/tests/kohana/CoreTest.php +++ b/system/tests/kohana/CoreTest.php @@ -20,7 +20,7 @@ */ class Kohana_CoreTest extends Unittest_TestCase { - protected $old_modules = array(); + protected $old_modules = []; /** * Captures the module list as it was before this test @@ -54,13 +54,13 @@ public function tearDown() */ public function provider_sanitize() { - return array( + return [ // $value, $result - array('foo', 'foo'), - array("foo\r\nbar", "foo\nbar"), - array("foo\rbar", "foo\nbar"), - array("Is your name O\'reilly?", "Is your name O'reilly?") - ); + ['foo', 'foo'], + ["foo\r\nbar", "foo\nbar"], + ["foo\rbar", "foo\nbar"], + ["Is your name O\'reilly?", "Is your name O'reilly?"], + ]; } /** @@ -74,7 +74,7 @@ public function provider_sanitize() */ public function test_sanitize($value, $result) { - $this->setEnvironment(array('Kohana::$magic_quotes' => TRUE)); + $this->setEnvironment(['Kohana::$magic_quotes' => TRUE]); $this->assertSame($result, Kohana::sanitize($value)); } @@ -108,7 +108,7 @@ public function test_find_file_returns_false_or_array_on_failure() { $this->assertFalse(Kohana::find_file('configy', 'zebra')); - $this->assertSame(array(), Kohana::find_file('configy', 'zebra', NULL, TRUE)); + $this->assertSame([], Kohana::find_file('configy', 'zebra', NULL, TRUE)); } /** @@ -124,7 +124,7 @@ public function test_list_files_returns_array_on_success_and_failure() $this->assertInternalType('array', $files); $this->assertGreaterThan(3, count($files)); - $this->assertSame(array(), Kohana::list_files('geshmuck')); + $this->assertSame([], Kohana::list_files('geshmuck')); } /** @@ -136,8 +136,8 @@ public function test_list_files_returns_array_on_success_and_failure() public function test_globals_removes_user_def_globals() { $GLOBALS['hackers'] = 'foobar'; - $GLOBALS['name'] = array('', '', ''); - $GLOBALS['_POST'] = array(); + $GLOBALS['name'] = ['', '', '']; + $GLOBALS['_POST'] = []; Kohana::globals(); @@ -153,12 +153,12 @@ public function test_globals_removes_user_def_globals() */ public function provider_cache() { - return array( + return [ // $value, $result - array('foo', 'hello, world', 10), - array('bar', NULL, 10), - array('bar', NULL, -10), - ); + ['foo', 'hello, world', 10], + ['bar', NULL, 10], + ['bar', NULL, -10], + ]; } /** @@ -184,21 +184,54 @@ public function test_cache($key, $value, $lifetime) */ public function provider_message() { - return array( - array('no_message_file', 'anything', 'default', 'default'), - array('no_message_file', NULL, 'anything', array()), - array('kohana_core_message_tests', 'bottom_only', 'anything', 'inherited bottom message'), - array('kohana_core_message_tests', 'cfs_replaced', 'anything', 'overriding cfs_replaced message'), - array('kohana_core_message_tests', 'top_only', 'anything', 'top only message'), - array('kohana_core_message_tests', 'missing', 'default', 'default'), - array('kohana_core_message_tests', NULL, 'anything', - array( + return [ + [ + 'no_message_file', + 'anything', + 'default', + 'default' + ], + [ + 'no_message_file', + NULL, + 'anything', + [] + ], + [ + 'kohana_core_message_tests', + 'bottom_only', + 'anything', + 'inherited bottom message' + ], + [ + 'kohana_core_message_tests', + 'cfs_replaced', + 'anything', + 'overriding cfs_replaced message' + ], + [ + 'kohana_core_message_tests', + 'top_only', + 'anything', + 'top only message' + ], + [ + 'kohana_core_message_tests', + 'missing', + 'default', + 'default' + ], + [ + 'kohana_core_message_tests', + NULL, + 'anything', + [ 'bottom_only' => 'inherited bottom message', 'cfs_replaced' => 'overriding cfs_replaced message', 'top_only' => 'top only message' - ) - ), - ); + ] + ], + ]; } /** @@ -215,7 +248,10 @@ public function provider_message() public function test_message($file, $key, $default, $expected) { $test_path = realpath(dirname(__FILE__) . '/../test_data/message_tests'); - Kohana::modules(array('top' => "$test_path/top_module", 'bottom' => "$test_path/bottom_module")); + Kohana::modules([ + 'top' => "$test_path/top_module", + 'bottom' => "$test_path/bottom_module" + ]); $this->assertEquals($expected, Kohana::message($file, $key, $default, $expected)); } @@ -227,9 +263,9 @@ public function test_message($file, $key, $default, $expected) */ public function provider_error_handler() { - return array( - array(1, 'Foobar', 'foobar.php', __LINE__), - ); + return [ + [1, 'Foobar', 'foobar.php', __LINE__], + ]; } /** @@ -263,10 +299,19 @@ public function test_error_handler($code, $error, $file, $line) */ public function provider_modules_detects_invalid_modules() { - return array( - array(array('unittest' => MODPATH . 'fo0bar')), - array(array('unittest' => MODPATH . 'unittest', 'fo0bar' => MODPATH . 'fo0bar')), - ); + return [ + [ + [ + 'unittest' => MODPATH . 'fo0bar' + ] + ], + [ + [ + 'unittest' => MODPATH . 'unittest', + 'fo0bar' => MODPATH . 'fo0bar' + ] + ], + ]; } /** @@ -302,10 +347,16 @@ public function test_modules_detects_invalid_modules($source) */ public function provider_modules_sets_and_returns_valid_modules() { - return array( - array(array(), array()), - array(array('module' => __DIR__), array('module' => $this->dirSeparator(__DIR__ . '/'))), - ); + return [ + [ + [], + [] + ], + [ + ['module' => __DIR__], + ['module' => $this->dirSeparator(__DIR__ . '/')] + ], + ]; } /** diff --git a/system/tests/kohana/DateTest.php b/system/tests/kohana/DateTest.php index 811f41e..28b117c 100644 --- a/system/tests/kohana/DateTest.php +++ b/system/tests/kohana/DateTest.php @@ -57,9 +57,9 @@ public function tearDown() */ public function provider_offset() { - return array( - array(30600, 'Asia/Calcutta', 'America/Argentina/Buenos_Aires'), - ); + return [ + [30600, 'Asia/Calcutta', 'America/Argentina/Buenos_Aires'], + ]; } /** @@ -85,38 +85,38 @@ public function test_offset($expected, $remote, $local, $now = NULL) */ public function provider_am_pm() { - return array( + return [ // All possible values - array(0, 'AM'), - array(1, 'AM'), - array(2, 'AM'), - array(3, 'AM'), - array(4, 'AM'), - array(5, 'AM'), - array(6, 'AM'), - array(7, 'AM'), - array(8, 'AM'), - array(9, 'AM'), - array(10, 'AM'), - array(11, 'AM'), - array(12, 'PM'), - array(13, 'PM'), - array(14, 'PM'), - array(15, 'PM'), - array(16, 'PM'), - array(17, 'PM'), - array(18, 'PM'), - array(19, 'PM'), - array(20, 'PM'), - array(21, 'PM'), - array(22, 'PM'), - array(23, 'PM'), - array(24, 'PM'), + [0, 'AM'], + [1, 'AM'], + [2, 'AM'], + [3, 'AM'], + [4, 'AM'], + [5, 'AM'], + [6, 'AM'], + [7, 'AM'], + [8, 'AM'], + [9, 'AM'], + [10, 'AM'], + [11, 'AM'], + [12, 'PM'], + [13, 'PM'], + [14, 'PM'], + [15, 'PM'], + [16, 'PM'], + [17, 'PM'], + [18, 'PM'], + [19, 'PM'], + [20, 'PM'], + [21, 'PM'], + [22, 'PM'], + [23, 'PM'], + [24, 'PM'], // ampm doesn't validate the hour, so I don't think we should test it.. // test strings are converted - array('0', 'AM'), - array('12', 'PM'), - ); + ['0', 'AM'], + ['12', 'PM'], + ]; } /** @@ -142,36 +142,36 @@ public function test_am_pm($hour, $expected) */ public function provider_adjust() { - return array( + return [ // Might as well test all possibilities - array(1, 'am', '01'), - array(2, 'am', '02'), - array(3, 'am', '03'), - array(4, 'am', '04'), - array(5, 'am', '05'), - array(6, 'am', '06'), - array(7, 'am', '07'), - array(8, 'am', '08'), - array(9, 'am', '09'), - array(10, 'am', '10'), - array(11, 'am', '11'), - array(12, 'am', '00'), - array(1, 'pm', '13'), - array(2, 'pm', '14'), - array(3, 'pm', '15'), - array(4, 'pm', '16'), - array(5, 'pm', '17'), - array(6, 'pm', '18'), - array(7, 'pm', '19'), - array(8, 'pm', '20'), - array(9, 'pm', '21'), - array(10, 'pm', '22'), - array(11, 'pm', '23'), - array(12, 'pm', '12'), + [1, 'am', '01'], + [2, 'am', '02'], + [3, 'am', '03'], + [4, 'am', '04'], + [5, 'am', '05'], + [6, 'am', '06'], + [7, 'am', '07'], + [8, 'am', '08'], + [9, 'am', '09'], + [10, 'am', '10'], + [11, 'am', '11'], + [12, 'am', '00'], + [1, 'pm', '13'], + [2, 'pm', '14'], + [3, 'pm', '15'], + [4, 'pm', '16'], + [5, 'pm', '17'], + [6, 'pm', '18'], + [7, 'pm', '19'], + [8, 'pm', '20'], + [9, 'pm', '21'], + [10, 'pm', '22'], + [11, 'pm', '23'], + [12, 'pm', '12'], // It should also work with strings instead of ints - array('10', 'pm', '22'), - array('10', 'am', '10'), - ); + ['10', 'pm', '22'], + ['10', 'am', '10'], + ]; } /** @@ -197,23 +197,23 @@ public function test_adjust($hour, $ampm, $expected) */ public function provider_days() { - return array( + return [ // According to "the rhyme" these should be the same every year - array(9, FALSE, 30), - array(4, FALSE, 30), - array(6, FALSE, 30), - array(11, FALSE, 30), - array(1, FALSE, 31), - array(3, FALSE, 31), - array(5, FALSE, 31), - array(7, FALSE, 31), - array(8, FALSE, 31), - array(10, FALSE, 31), + [9, FALSE, 30], + [4, FALSE, 30], + [6, FALSE, 30], + [11, FALSE, 30], + [1, FALSE, 31], + [3, FALSE, 31], + [5, FALSE, 31], + [7, FALSE, 31], + [8, FALSE, 31], + [10, FALSE, 31], // February is such a pain - array(2, 2001, 28), - array(2, 2000, 29), - array(2, 2012, 29), - ); + [2, 2001, 28], + [2, 2000, 29], + [2, 2012, 29], + ]; } /** @@ -249,17 +249,39 @@ public function test_days($month, $year, $expected) */ public function provider_formatted_time() { - return array( + return [ // Test the default format - array('2010-04-16 17:00:00', '5:00PM 16th April 2010'), + [ + '2010-04-16 17:00:00', + '5:00PM 16th April 2010' + ], // Now we use our own format // Binary date! - array('01/01/2010 01:00', '1AM 1st January 2010', 'd/m/Y H:i'), + [ + '01/01/2010 01:00', + '1AM 1st January 2010', + 'd/m/Y H:i' + ], // Timezones (see #3902) - array('2011-04-01 01:23:45 Antarctica/South_Pole', '2011-04-01 01:23:45', 'Y-m-d H:i:s e', 'Antarctica/South_Pole'), - array('2011-04-01 01:23:45 Antarctica/South_Pole', '2011-03-31 14:23:45 Europe/Paris', 'Y-m-d H:i:s e', 'Antarctica/South_Pole'), - array('2011-04-01 01:23:45 Antarctica/South_Pole', '@1301574225', 'Y-m-d H:i:s e', 'Antarctica/South_Pole'), - ); + [ + '2011-04-01 01:23:45 Antarctica/South_Pole', + '2011-04-01 01:23:45', + 'Y-m-d H:i:s e', + 'Antarctica/South_Pole' + ], + [ + '2011-04-01 01:23:45 Antarctica/South_Pole', + '2011-03-31 14:23:45 Europe/Paris', + 'Y-m-d H:i:s e', + 'Antarctica/South_Pole' + ], + [ + '2011-04-01 01:23:45 Antarctica/South_Pole', + '@1301574225', + 'Y-m-d H:i:s e', + 'Antarctica/South_Pole' + ], + ]; } /** @@ -288,9 +310,9 @@ public function test_formatted_time($expected, $datetime_str, $timestamp_format */ public function provider_months() { - return array( - array( - array( + return [ + [ + [ 1 => "1", 2 => "2", 3 => "3", @@ -303,11 +325,11 @@ public function provider_months() 10 => "10", 11 => "11", 12 => "12" - ), + ], NULL - ), - array( - array( + ], + [ + [ 1 => "1", 2 => "2", 3 => "3", @@ -320,11 +342,11 @@ public function provider_months() 10 => "10", 11 => "11", 12 => "12" - ), + ], 'Guinness' - ), - array( - array( + ], + [ + [ 1 => "January", 2 => "February", 3 => "March", @@ -337,11 +359,11 @@ public function provider_months() 10 => "October", 11 => "November", 12 => "December" - ), + ], Date::MONTHS_LONG - ), - array( - array( + ], + [ + [ 1 => "Jan", 2 => "Feb", 3 => "Mar", @@ -354,10 +376,10 @@ public function provider_months() 10 => "Oct", 11 => "Nov", 12 => "Dec" - ), + ], Date::MONTHS_SHORT - ) - ); + ], + ]; } /** @@ -383,49 +405,74 @@ public function test_months($expected, $format) public function provider_span() { $time = time(); - return array( + return [ // Test that it must specify an output format - array( + [ $time, $time, '', FALSE - ), + ], // Test that providing only one output just returns that output - array( + [ $time - 30, $time, 'seconds', 30 - ), + ], // Random tests - array( + [ $time - 30, $time, 'years,months,weeks,days,hours,minutes,seconds', - array('years' => 0, 'months' => 0, 'weeks' => 0, 'days' => 0, 'hours' => 0, 'minutes' => 0, 'seconds' => 30), - ), - array( + [ + 'years' => 0, + 'months' => 0, + 'weeks' => 0, + 'days' => 0, + 'hours' => 0, + 'minutes' => 0, + 'seconds' => 30 + ] + ], + [ $time - (60 * 60 * 24 * 782) + (60 * 25), $time, 'years,months,weeks,days,hours,minutes,seconds', - array('years' => 2, 'months' => 1, 'weeks' => 3, 'days' => 0, 'hours' => 1, 'minutes' => 28, 'seconds' => 24), - ), + [ + 'years' => 2, + 'months' => 1, + 'weeks' => 3, + 'days' => 0, + 'hours' => 1, + 'minutes' => 28, + 'seconds' => 24 + ] + ], // Should be able to compare with the future & that it only uses formats specified - array( + [ $time + (60 * 60 * 24 * 15) + (60 * 5), $time, 'weeks,days,hours,minutes,seconds', - array('weeks' => 2, 'days' => 1, 'hours' => 0, 'minutes' => 5, 'seconds' => 0), - ), - array( + [ + 'weeks' => 2, + 'days' => 1, + 'hours' => 0, + 'minutes' => 5, + 'seconds' => 0 + ] + ], + [ // Add a bit of extra time to account for phpunit processing $time + (14 * 31 * 24 * 60 * 60) + (79 * 80), NULL, 'months,years', - array('months' => 2, 'years' => 1), - ), - ); + [ + 'months' => 2, + 'years' => 1 + ] + ], + ]; } /** @@ -459,48 +506,48 @@ public function provider_fuzzy_span() { $now = time(); - return array( - array('moments ago', $now - 30, $now), - array('in moments', $now + 30, $now), - array('a few minutes ago', $now - 10 * 60, $now), - array('in a few minutes', $now + 10 * 60, $now), - array('less than an hour ago', $now - 45 * 60, $now), - array('in less than an hour', $now + 45 * 60, $now), - array('a couple of hours ago', $now - 2 * 60 * 60, $now), - array('in a couple of hours', $now + 2 * 60 * 60, $now), - array('less than a day ago', $now - 12 * 60 * 60, $now), - array('in less than a day', $now + 12 * 60 * 60, $now), - array('about a day ago', $now - 30 * 60 * 60, $now), - array('in about a day', $now + 30 * 60 * 60, $now), - array('a couple of days ago', $now - 3 * 24 * 60 * 60, $now), - array('in a couple of days', $now + 3 * 24 * 60 * 60, $now), - array('less than a week ago', $now - 5 * 24 * 60 * 60, $now), - array('in less than a week', $now + 5 * 24 * 60 * 60, $now), - array('about a week ago', $now - 9 * 24 * 60 * 60, $now), - array('in about a week', $now + 9 * 24 * 60 * 60, $now), - array('less than a month ago', $now - 20 * 24 * 60 * 60, $now), - array('in less than a month', $now + 20 * 24 * 60 * 60, $now), - array('about a month ago', $now - 40 * 24 * 60 * 60, $now), - array('in about a month', $now + 40 * 24 * 60 * 60, $now), - array('a couple of months ago', $now - 3 * 30 * 24 * 60 * 60, $now), - array('in a couple of months', $now + 3 * 30 * 24 * 60 * 60, $now), - array('less than a year ago', $now - 7 * 31 * 24 * 60 * 60, $now), - array('in less than a year', $now + 7 * 31 * 24 * 60 * 60, $now), - array('about a year ago', $now - 18 * 31 * 24 * 60 * 60, $now), - array('in about a year', $now + 18 * 31 * 24 * 60 * 60, $now), - array('a couple of years ago', $now - 3 * 12 * 31 * 24 * 60 * 60, $now), - array('in a couple of years', $now + 3 * 12 * 31 * 24 * 60 * 60, $now), - array('a few years ago', $now - 5 * 12 * 31 * 24 * 60 * 60, $now), - array('in a few years', $now + 5 * 12 * 31 * 24 * 60 * 60, $now), - array('about a decade ago', $now - 11 * 12 * 31 * 24 * 60 * 60, $now), - array('in about a decade', $now + 11 * 12 * 31 * 24 * 60 * 60, $now), - array('a couple of decades ago', $now - 20 * 12 * 31 * 24 * 60 * 60, $now), - array('in a couple of decades', $now + 20 * 12 * 31 * 24 * 60 * 60, $now), - array('several decades ago', $now - 50 * 12 * 31 * 24 * 60 * 60, $now), - array('in several decades', $now + 50 * 12 * 31 * 24 * 60 * 60, $now), - array('a long time ago', $now - pow(10, 10), $now), - array('in a long time', $now + pow(10, 10), $now), - ); + return [ + ['moments ago', $now - 30, $now], + ['in moments', $now + 30, $now], + ['a few minutes ago', $now - 10 * 60, $now], + ['in a few minutes', $now + 10 * 60, $now], + ['less than an hour ago', $now - 45 * 60, $now], + ['in less than an hour', $now + 45 * 60, $now], + ['a couple of hours ago', $now - 2 * 60 * 60, $now], + ['in a couple of hours', $now + 2 * 60 * 60, $now], + ['less than a day ago', $now - 12 * 60 * 60, $now], + ['in less than a day', $now + 12 * 60 * 60, $now], + ['about a day ago', $now - 30 * 60 * 60, $now], + ['in about a day', $now + 30 * 60 * 60, $now], + ['a couple of days ago', $now - 3 * 24 * 60 * 60, $now], + ['in a couple of days', $now + 3 * 24 * 60 * 60, $now], + ['less than a week ago', $now - 5 * 24 * 60 * 60, $now], + ['in less than a week', $now + 5 * 24 * 60 * 60, $now], + ['about a week ago', $now - 9 * 24 * 60 * 60, $now], + ['in about a week', $now + 9 * 24 * 60 * 60, $now], + ['less than a month ago', $now - 20 * 24 * 60 * 60, $now], + ['in less than a month', $now + 20 * 24 * 60 * 60, $now], + ['about a month ago', $now - 40 * 24 * 60 * 60, $now], + ['in about a month', $now + 40 * 24 * 60 * 60, $now], + ['a couple of months ago', $now - 3 * 30 * 24 * 60 * 60, $now], + ['in a couple of months', $now + 3 * 30 * 24 * 60 * 60, $now], + ['less than a year ago', $now - 7 * 31 * 24 * 60 * 60, $now], + ['in less than a year', $now + 7 * 31 * 24 * 60 * 60, $now], + ['about a year ago', $now - 18 * 31 * 24 * 60 * 60, $now], + ['in about a year', $now + 18 * 31 * 24 * 60 * 60, $now], + ['a couple of years ago', $now - 3 * 12 * 31 * 24 * 60 * 60, $now], + ['in a couple of years', $now + 3 * 12 * 31 * 24 * 60 * 60, $now], + ['a few years ago', $now - 5 * 12 * 31 * 24 * 60 * 60, $now], + ['in a few years', $now + 5 * 12 * 31 * 24 * 60 * 60, $now], + ['about a decade ago', $now - 11 * 12 * 31 * 24 * 60 * 60, $now], + ['in about a decade', $now + 11 * 12 * 31 * 24 * 60 * 60, $now], + ['a couple of decades ago', $now - 20 * 12 * 31 * 24 * 60 * 60, $now], + ['in a couple of decades', $now + 20 * 12 * 31 * 24 * 60 * 60, $now], + ['several decades ago', $now - 50 * 12 * 31 * 24 * 60 * 60, $now], + ['in several decades', $now + 50 * 12 * 31 * 24 * 60 * 60, $now], + ['a long time ago', $now - pow(10, 10), $now], + ['in a long time', $now + pow(10, 10), $now], + ]; } /** @@ -526,9 +573,9 @@ public function test_fuzzy_span($expected, $timestamp, $local_timestamp) */ public function provider_years() { - return array( - array( - array( + return [ + [ + [ 2005 => '2005', 2006 => '2006', 2007 => '2007', @@ -540,11 +587,11 @@ public function provider_years() 2013 => '2013', 2014 => '2014', 2015 => '2015', - ), + ], 2005, 2015 - ), - ); + ], + ]; } /** @@ -562,9 +609,9 @@ public function test_years($expected, $start = FALSE, $end = FALSE) public function provider_hours() { - return array( - array( - array( + return [ + [ + [ 1 => '1', 2 => '2', 3 => '3', @@ -577,9 +624,9 @@ public function provider_hours() 10 => '10', 11 => '11', 12 => '12', - ), - ), - ); + ] + ], + ]; } /** @@ -602,10 +649,10 @@ public function test_hours($expected, $step = 1, $long = FALSE, $start = NULL) */ public function provider_seconds() { - return array( - array( + return [ + [ // Thank god for var_export() - array( + [ 0 => '00', 1 => '01', 2 => '02', 3 => '03', 4 => '04', 5 => '05', 6 => '06', 7 => '07', 8 => '08', 9 => '09', 10 => '10', 11 => '11', 12 => '12', 13 => '13', 14 => '14', @@ -618,12 +665,12 @@ public function provider_seconds() 45 => '45', 46 => '46', 47 => '47', 48 => '48', 49 => '49', 50 => '50', 51 => '51', 52 => '52', 53 => '53', 54 => '54', 55 => '55', 56 => '56', 57 => '57', 58 => '58', 59 => '59', - ), + ], 1, 0, 60 - ), - ); + ], + ]; } /** @@ -646,17 +693,17 @@ public function test_seconds($expected, $step = 1, $start = 0, $end = 60) */ public function provider_minutes() { - return array( - array( - array( + return [ + [ + [ 0 => '00', 5 => '05', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30', 35 => '35', 40 => '40', 45 => '45', 50 => '50', 55 => '55', - ), - 5, - ), - ); + ], + 5 + ], + ]; } /** @@ -680,12 +727,12 @@ public function test_minutes($expected, $step) */ public function test_minutes_defaults_to_using_step_of5() { - $minutes = array( + $minutes = [ 0 => '00', 5 => '05', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30', 35 => '35', 40 => '40', 45 => '45', 50 => '50', 55 => '55', - ); + ]; $this->assertSame( $minutes, Date::minutes() @@ -699,16 +746,10 @@ public function test_minutes_defaults_to_using_step_of5() */ public function provider_unix2dos() { - return array( - array( - 1024341746, - 1281786936 - ), - array( - 2162688, - 315554400 - ) - ); + return [ + [1024341746, 1281786936], + [2162688, 315554400], + ]; } /** @@ -738,16 +779,10 @@ public function test_unix2dos($expected, $timestamp) */ public function provider_dos2unix() { - return array( - array( - 1281786936, - 1024341746, - ), - array( - 315554400, - 2162688, - ), - ); + return [ + [1281786936, 1024341746], + [315554400, 2162688], + ]; } /** diff --git a/system/tests/kohana/DebugTest.php b/system/tests/kohana/DebugTest.php index d3375ee..13ee3d7 100644 --- a/system/tests/kohana/DebugTest.php +++ b/system/tests/kohana/DebugTest.php @@ -27,10 +27,13 @@ class Kohana_DebugTest extends Unittest_TestCase */ public function provider_vars() { - return array( + return [ // $thing, $expected - array(array('foobar'), "
array(1) (\n    0 => string(6) \"foobar\"\n)
"), - ); + [ + ['foobar'], + "
array(1) (\n    0 => string(6) \"foobar\"\n)
" + ], + ]; } /** @@ -54,16 +57,16 @@ public function test_var($thing, $expected) */ public function provider_debug_path() { - return array( - array( + return [ + [ SYSPATH . 'classes' . DIRECTORY_SEPARATOR . 'kohana' . EXT, 'SYSPATH' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'kohana.php' - ), - array( + ], + [ MODPATH . $this->dirSeparator('unittest/classes/kohana/unittest/runner') . EXT, $this->dirSeparator('MODPATH/unittest/classes/kohana/unittest/runner') . EXT - ), - ); + ], + ]; } /** @@ -87,15 +90,53 @@ public function test_debug_path($path, $expected) */ public function provider_dump() { - return array( - array('foobar', 128, 10, 'string(6) "foobar"'), - array('foobar', 2, 10, 'string(6) "fo …"'), - array(NULL, 128, 10, 'NULL'), - array(TRUE, 128, 10, 'bool TRUE'), - array(array('foobar'), 128, 10, "array(1) (\n 0 => string(6) \"foobar\"\n)"), - array(new StdClass, 128, 10, "object stdClass(0) {\n}"), - array("fo\x6F\xFF\x00bar\x8F\xC2\xB110", 128, 10, 'string(10) "foobar±10"'), - array(array('level1' => array('level2' => array('level3' => array('level4' => array('value' => 'something'))))), 128, 4, + return [ + [ + 'foobar', + 128, + 10, + 'string(6) "foobar"' + ], + [ + 'foobar', + 2, + 10, + 'string(6) "fo …"' + ], + [ + NULL, + 128, + 10, + 'NULL' + ], + [ + TRUE, + 128, + 10, + 'bool TRUE' + ], + [ + ['foobar'], + 128, + 10, + "array(1) (\n 0 => string(6) \"foobar\"\n)" + ], + [ + new StdClass, + 128, + 10, + "object stdClass(0) {\n}" + ], + [ + "fo\x6F\xFF\x00bar\x8F\xC2\xB110", + 128, + 10, + 'string(10) "foobar±10"' + ], + [ + ['level1' => ['level2' => ['level3' => ['level4' => ['value' => 'something']]]]], + 128, + 4, 'array(1) ( "level1" => array(1) ( "level2" => array(1) ( @@ -106,8 +147,9 @@ public function provider_dump() ) ) ) -)'), - ); +)' + ], + ]; } /** diff --git a/system/tests/kohana/ExceptionTest.php b/system/tests/kohana/ExceptionTest.php index 31f717f..69c8f01 100644 --- a/system/tests/kohana/ExceptionTest.php +++ b/system/tests/kohana/ExceptionTest.php @@ -24,23 +24,23 @@ class Kohana_ExceptionTest extends Unittest_TestCase */ public function provider_constructor() { - return array( - array(array(''), '', 0), - array(array(':a'), ':a', 0), - array(array(':a', NULL), ':a', 0), - array(array(':a', array()), ':a', 0), - array(array(':a', array(':a' => 'b')), 'b', 0), - array(array(':a :b', array(':a' => 'c', ':b' => 'd')), 'c d', 0), - array(array(':a', NULL, 5), ':a', 5), + return [ + [[''], '', 0], + [[':a'], ':a', 0], + [[':a', NULL], ':a', 0], + [[':a', []], ':a', 0], + [[':a', [':a' => 'b']], 'b', 0], + [[':a :b', [':a' => 'c', ':b' => 'd']], 'c d', 0], + [[':a', NULL, 5], ':a', 5], // #3358 - array(array(':a', NULL, '3F000'), ':a', '3F000'), + [[':a', NULL, '3F000'], ':a', '3F000'], // #3404 - array(array(':a', NULL, '42S22'), ':a', '42S22'), + [[':a', NULL, '42S22'], ':a', '42S22'], // #3927 - array(array(':a', NULL, 'b'), ':a', 'b'), + [[':a', NULL, 'b'], ':a', 'b'], // #4039 - array(array(':a', NULL, '25P01'), ':a', '25P01'), - ); + [[':a', NULL, '25P01'], ':a', '25P01'], + ]; } /** @@ -77,9 +77,9 @@ public function test_constructor($arguments, $expected_message, $expected_code) */ public function provider_text() { - return array( - array(new Kohana_Exception('foobar'), $this->dirSeparator('Kohana_Exception [ 0 ]: foobar ~ SYSPATH/tests/kohana/ExceptionTest.php [ ' . __LINE__ . ' ]')), - ); + return [ + [new Kohana_Exception('foobar'), $this->dirSeparator('Kohana_Exception [ 0 ]: foobar ~ SYSPATH/tests/kohana/ExceptionTest.php [ ' . __LINE__ . ' ]')], + ]; } /** diff --git a/system/tests/kohana/FeedTest.php b/system/tests/kohana/FeedTest.php index 2f1ff31..2132f91 100644 --- a/system/tests/kohana/FeedTest.php +++ b/system/tests/kohana/FeedTest.php @@ -26,7 +26,7 @@ public function setUp() // @codingStandardsIgnoreEnd { parent::setUp(); - Kohana::$config->load('url')->set('trusted_hosts', array('localhost')); + Kohana::$config->load('url')->set('trusted_hosts', ['localhost']); } /** @@ -36,11 +36,22 @@ public function setUp() */ public function provider_parse() { - return array( + return [ // $source, $expected - array(realpath(__DIR__ . '/../test_data/feeds/activity.atom'), array('Proposals (Political/Workflow) #4839 (New)', 'Proposals (Political/Workflow) #4782')), - array(realpath(__DIR__ . '/../test_data/feeds/example.rss20'), array('Example entry')), - ); + [ + realpath(__DIR__ . '/../test_data/feeds/activity.atom'), + [ + 'Proposals (Political/Workflow) #4839 (New)', + 'Proposals (Political/Workflow) #4782' + ] + ], + [ + realpath(__DIR__ . '/../test_data/feeds/example.rss20'), + [ + 'Example entry' + ] + ], + ]; } /** @@ -54,7 +65,7 @@ public function provider_parse() */ public function test_parse($source, $expected_titles) { - $titles = array(); + $titles = []; foreach (Feed::parse($source) as $item) { $titles[] = $item['title']; } @@ -69,28 +80,37 @@ public function test_parse($source, $expected_titles) */ public function provider_create() { - $info = array('pubDate' => 123, 'image' => array('link' => 'http://kohanaframework.org/image.png', 'url' => 'http://kohanaframework.org/', 'title' => 'title')); + $info = [ + 'pubDate' => 123, + 'image' => [ + 'link' => 'http://kohanaframework.org/image.png', + 'url' => 'http://kohanaframework.org/', 'title' => 'title' + ] + ]; - return array( + return [ // $source, $expected - array($info, array('foo' => array('foo' => 'bar', 'pubDate' => 123, 'link' => 'foo')), array('_SERVER' => array('HTTP_HOST' => 'localhost') + $_SERVER), - array( + [ + $info, + ['foo' => ['foo' => 'bar', 'pubDate' => 123, 'link' => 'foo']], + ['_SERVER' => ['HTTP_HOST' => 'localhost'] + $_SERVER], + [ 'tag' => 'channel', - 'descendant' => array( + 'descendant' => [ 'tag' => 'item', - 'child' => array( + 'child' => [ 'tag' => 'foo', 'content' => 'bar' - ) - ) - ), - array( + ] + ] + ], + [ $this->matcher_composer($info, 'image', 'link'), $this->matcher_composer($info, 'image', 'url'), $this->matcher_composer($info, 'image', 'title') - ) - ), - ); + ] + ], + ]; } /** @@ -103,16 +123,16 @@ public function provider_create() */ private function matcher_composer($data, $tag, $child) { - return array( + return [ 'tag' => 'channel', - 'descendant' => array( + 'descendant' => [ 'tag' => $tag, - 'child' => array( + 'child' => [ 'tag' => $child, 'content' => $data[$tag][$child] - ) - ) - ); + ] + ] + ]; } /** diff --git a/system/tests/kohana/FileTest.php b/system/tests/kohana/FileTest.php index e729c7c..3d5c585 100644 --- a/system/tests/kohana/FileTest.php +++ b/system/tests/kohana/FileTest.php @@ -25,10 +25,13 @@ class Kohana_FileTest extends Unittest_TestCase */ public function provider_mime() { - return array( + return [ // $value, $result - array(Kohana::find_file('tests', 'test_data/github', 'png'), 'image/png'), - ); + [ + Kohana::find_file('tests', 'test_data/github', 'png'), + 'image/png' + ], + ]; } /** @@ -52,10 +55,10 @@ public function test_mime($input, $expected) */ public function provider_split_join() { - return array( + return [ // $value, $result - array(Kohana::find_file('tests', 'test_data/github', 'png'), .01, 1), - ); + [Kohana::find_file('tests', 'test_data/github', 'png'), .01, 1], + ]; } /** diff --git a/system/tests/kohana/FormTest.php b/system/tests/kohana/FormTest.php index aa85e99..57c7c1b 100644 --- a/system/tests/kohana/FormTest.php +++ b/system/tests/kohana/FormTest.php @@ -23,11 +23,11 @@ class Kohana_FormTest extends Unittest_TestCase * @var array */ // @codingStandardsIgnoreStart - protected $environmentDefault = array( + protected $environmentDefault = [ 'Kohana::$base_url' => '/', 'HTTP_HOST' => 'kohanaframework.org', 'Kohana::$index_file' => '', - ); + ]; // @codingStandardsIgnoreEnd /** @@ -37,24 +37,24 @@ class Kohana_FormTest extends Unittest_TestCase */ public function provider_open() { - return array( - array( - array('', NULL), - array('action' => '') - ), - array( - array(NULL, NULL), - array('action' => '') - ), - array( - array('foo', NULL), - array('action' => '/foo') - ), - array( - array('foo', array('method' => 'get')), - array('action' => '/foo', 'method' => 'get') - ), - ); + return [ + [ + ['', NULL], + ['action' => ''] + ], + [ + [NULL, NULL], + ['action' => ''] + ], + [ + ['foo', NULL], + ['action' => '/foo'] + ], + [ + ['foo', ['method' => 'get']], + ['action' => '/foo', 'method' => 'get'] + ], + ]; } /** @@ -71,14 +71,14 @@ public function test_open($input, $expected) $tag = Form::open($action, $attributes); - $matcher = array( + $matcher = [ 'tag' => 'form', // Default attributes - 'attributes' => array( + 'attributes' => [ 'method' => 'post', 'accept-charset' => 'utf-8', - ), - ); + ], + ]; $matcher['attributes'] = $expected + $matcher['attributes']; @@ -102,13 +102,13 @@ public function test_close() */ public function provider_input() { - return array( + return [ // $value, $result - array('input', 'foo', 'bar', NULL, 'input'), - array('input', 'foo', NULL, NULL, 'input'), - array('hidden', 'foo', 'bar', NULL, 'hidden'), - array('password', 'foo', 'bar', NULL, 'password'), - ); + ['input', 'foo', 'bar', NULL, 'input'], + ['input', 'foo', NULL, NULL, 'input'], + ['hidden', 'foo', 'bar', NULL, 'hidden'], + ['password', 'foo', 'bar', NULL, 'password'], + ]; } /** @@ -121,10 +121,10 @@ public function provider_input() */ public function test_input($type, $name, $value, $attributes) { - $matcher = array( + $matcher = [ 'tag' => 'input', - 'attributes' => array('name' => $name, 'type' => $type) - ); + 'attributes' => ['name' => $name, 'type' => $type] + ]; // Form::input creates a text input if ($type === 'input') { @@ -153,10 +153,10 @@ public function test_input($type, $name, $value, $attributes) */ public function provider_file() { - return array( + return [ // $value, $result - array('foo', NULL, ''), - ); + ['foo', NULL, ''], + ]; } /** @@ -179,15 +179,15 @@ public function test_file($name, $attributes, $expected) */ public function provider_check() { - return array( + return [ // $value, $result - array('checkbox', 'foo', NULL, FALSE, NULL), - array('checkbox', 'foo', NULL, TRUE, NULL), - array('checkbox', 'foo', 'bar', TRUE, NULL), - array('radio', 'foo', NULL, FALSE, NULL), - array('radio', 'foo', NULL, TRUE, NULL), - array('radio', 'foo', 'bar', TRUE, NULL), - ); + ['checkbox', 'foo', NULL, FALSE, NULL], + ['checkbox', 'foo', NULL, TRUE, NULL], + ['checkbox', 'foo', 'bar', TRUE, NULL], + ['radio', 'foo', NULL, FALSE, NULL], + ['radio', 'foo', NULL, TRUE, NULL], + ['radio', 'foo', 'bar', TRUE, NULL], + ]; } /** @@ -200,7 +200,10 @@ public function provider_check() */ public function test_check($type, $name, $value, $checked, $attributes) { - $matcher = array('tag' => 'input', 'attributes' => array('name' => $name, 'type' => $type)); + $matcher = [ + 'tag' => 'input', + 'attributes' => ['name' => $name, 'type' => $type] + ]; if ($value !== NULL) { $matcher['attributes']['value'] = $value; @@ -225,14 +228,14 @@ public function test_check($type, $name, $value, $checked, $attributes) */ public function provider_text() { - return array( + return [ // $value, $result - array('textarea', 'foo', 'bar', NULL), - array('textarea', 'foo', 'bar', array('rows' => 20, 'cols' => 20)), - array('button', 'foo', 'bar', NULL), - array('label', 'foo', 'bar', NULL), - array('label', 'foo', NULL, NULL), - ); + ['textarea', 'foo', 'bar', NULL], + ['textarea', 'foo', 'bar', ['rows' => 20, 'cols' => 20]], + ['button', 'foo', 'bar', NULL], + ['label', 'foo', 'bar', NULL], + ['label', 'foo', NULL, NULL], + ]; } /** @@ -245,16 +248,16 @@ public function provider_text() */ public function test_text($type, $name, $body, $attributes) { - $matcher = array( + $matcher = [ 'tag' => $type, - 'attributes' => array(), + 'attributes' => [], 'content' => $body, - ); + ]; if ($type !== 'label') { - $matcher['attributes'] = array('name' => $name); + $matcher['attributes'] = ['name' => $name]; } else { - $matcher['attributes'] = array('for' => $name); + $matcher['attributes'] = ['for' => $name]; } @@ -274,16 +277,46 @@ public function test_text($type, $name, $body, $attributes) */ public function provider_select() { - return array( + return [ // $value, $result - array('foo', NULL, NULL, ""), - array('foo', array('bar' => 'bar'), NULL, ""), - array('foo', array('bar' => 'bar'), 'bar', ""), - array('foo', array('bar' => array('foo' => 'bar')), NULL, ""), - array('foo', array('bar' => array('foo' => 'bar')), 'foo', ""), + [ + 'foo', + NULL, + NULL, + "" + ], + [ + 'foo', + ['bar' => 'bar'], + NULL, + "" + ], + [ + 'foo', + ['bar' => 'bar'], + 'bar', + "" + ], + [ + 'foo', + ['bar' => ['foo' => 'bar']], + NULL, + "" + ], + [ + 'foo', + ['bar' => ['foo' => 'bar']], + 'foo', + "" + ], // #2286 - array('foo', array('bar' => 'bar', 'unit' => 'test', 'foo' => 'foo'), array('bar', 'foo'), ""), - ); + [ + 'foo', + ['bar' => 'bar', 'unit' => 'test', 'foo' => 'foo'], + ['bar', 'foo'], + "" + ], + ]; } /** @@ -307,10 +340,14 @@ public function test_select($name, $options, $selected, $expected) */ public function provider_submit() { - return array( + return [ // $value, $result - array('foo', 'Foobar!', ''), - ); + [ + 'foo', + 'Foobar!', + '' + ], + ]; } /** @@ -323,10 +360,14 @@ public function provider_submit() */ public function test_submit($name, $value, $expected) { - $matcher = array( + $matcher = [ 'tag' => 'input', - 'attributes' => array('name' => $name, 'type' => 'submit', 'value' => $value) - ); + 'attributes' => [ + 'name' => $name, + 'type' => 'submit', + 'value' => $value + ] + ]; $this->assertTag($matcher, Form::submit($name, $value)); } @@ -338,10 +379,15 @@ public function test_submit($name, $value, $expected) */ public function provider_image() { - return array( + return [ // $value, $result - array('foo', 'bar', array('src' => 'media/img/login.png'), ''), - ); + [ + 'foo', + 'bar', + ['src' => 'media/img/login.png'], + '' + ], + ]; } /** @@ -366,18 +412,48 @@ public function test_image($name, $value, $attributes, $expected) */ function provider_label() { - return array( + return [ // $value, $result // Single for provided - array('email', NULL, NULL, ''), - array('email_address', NULL, NULL, ''), - array('email-address', NULL, NULL, ''), + [ + 'email', + NULL, + NULL, + '' + ], + [ + 'email_address', + NULL, + NULL, + '' + ], + [ + 'email-address', + NULL, + NULL, + '' + ], // For and text values provided - array('name', 'First name', NULL, ''), + [ + 'name', + 'First name', + NULL, + '' + ], // with attributes - array('lastname', 'Last name', array('class' => 'text'), ''), - array('lastname', 'Last name', array('class' => 'text', 'id' => 'txt_lastname'), ''), - ); + [ + 'lastname', + 'Last name', + ['class' => 'text'], + '' + ], + [ + 'lastname', + 'Last name', + ['class' => 'text', 'id' => 'txt_lastname'], + '' + ], + ]; } /** diff --git a/system/tests/kohana/HTMLTest.php b/system/tests/kohana/HTMLTest.php index 870d6b2..e1da9e0 100644 --- a/system/tests/kohana/HTMLTest.php +++ b/system/tests/kohana/HTMLTest.php @@ -26,7 +26,9 @@ public function setUp() // @codingStandardsIgnoreEnd { parent::setUp(); - Kohana::$config->load('url')->set('trusted_hosts', array('www\.kohanaframework\.org')); + Kohana::$config->load('url')->set('trusted_hosts', [ + 'www\.kohanaframework\.org' + ]); } /** @@ -34,12 +36,12 @@ public function setUp() * @var array */ // @codingStandardsIgnoreStart - protected $environmentDefault = array( + protected $environmentDefault = [ 'Kohana::$base_url' => '/kohana/', 'Kohana::$index_file' => 'index.php', 'HTML::$strict' => TRUE, 'HTTP_HOST' => 'www.kohanaframework.org', - ); + ]; // @codingStandardsIgnoreStart /** @@ -49,33 +51,33 @@ public function setUp() */ public function provider_attributes() { - return array( - array( - array('name' => 'field', 'random' => 'not_quite', 'id' => 'unique_field'), - array(), + return [ + [ + ['name' => 'field', 'random' => 'not_quite', 'id' => 'unique_field'], + [], ' id="unique_field" name="field" random="not_quite"' - ), - array( - array('invalid' => NULL), - array(), + ], + [ + ['invalid' => NULL], + [], '' - ), - array( - array(), - array(), + ], + [ + [], + [], '' - ), - array( - array('name' => 'field', 'checked'), - array(), + ], + [ + ['name' => 'field', 'checked'], + [], ' name="field" checked="checked"', - ), - array( - array('id' => 'disabled_field', 'disabled'), - array('HTML::$strict' => FALSE), + ], + [ + ['id' => 'disabled_field', 'disabled'], + ['HTML::$strict' => FALSE], ' id="disabled_field" disabled', - ), - ); + ], + ]; } /** @@ -103,37 +105,37 @@ public function test_attributes(array $attributes, array $options, $expected) */ public function provider_script() { - return array( - array( + return [ + [ '', 'http://google.com/script.js', - ), - array( + ], + [ '', 'my/script.js', NULL, 'http', TRUE - ), - array( + ], + [ '', 'my/script.js', NULL, 'https', FALSE - ), - array( + ], + [ '', '/my/script.js', // Test absolute paths NULL, 'https', FALSE - ), - array( + ], + [ '', '//google.com/script.js', - ), - ); + ], + ]; } /** @@ -161,60 +163,58 @@ public function test_script($expected, $file, array $attributes = NULL, $protoco */ public function provider_style() { - return array( - array( + return [ + [ '', 'http://google.com/style.css', - array(), + [], NULL, FALSE - ), - array( + ], + [ '', 'my/style.css', - array(), + [], NULL, FALSE - ), - array( + ], + [ '', 'my/style.css', - array(), + [], 'https', FALSE - ), - array( + ], + [ '', 'my/style.css', - array(), + [], 'https', TRUE - ), - array( + ], + [ '', '/my/style.css', - array(), + [], 'https', TRUE - ), - array( + ], + [ // #4283: http://dev.kohanaframework.org/issues/4283 '', 'my/style.css', - array( - 'rel' => 'stylesheet/less' - ), + ['rel' => 'stylesheet/less'], 'https', TRUE - ), - array( + ], + [ '', '//google.com/style.css', - array(), + [], NULL, FALSE - ), - ); + ], + ]; } /** @@ -242,89 +242,89 @@ public function test_style($expected, $file, array $attributes = NULL, $protocol */ public function provider_anchor() { - return array( + return [ // a fragment-only anchor - array( + [ 'Kohana', - array(), + [], '#go-to-section-kohana', 'Kohana', - ), + ], // a query-only anchor - array( + [ 'Category A', - array(), + [], '?cat=a', 'Category A', - ), - array( + ], + [ 'Kohana', - array(), + [], 'http://kohanaframework.org', 'Kohana', - ), - array( + ], + [ 'GOOGLE', - array(), + [], 'http://google.com', 'GOOGLE', - array('target' => '_blank'), + ['target' => '_blank'], 'http', - ), - array( + ], + [ 'Kohana', - array(), + [], 'users/example', 'Kohana', NULL, 'https', FALSE, - ), - array( + ], + [ 'Kohana', - array(), + [], 'users/example', 'Kohana', NULL, 'https', TRUE, - ), - array( + ], + [ 'Kohana', - array(), + [], 'users/example', 'Kohana', NULL, 'https', - ), - array( + ], + [ 'Kohana', - array(), + [], 'users/example', 'Kohana', NULL, 'https', TRUE, - ), - array( + ], + [ 'Kohana', - array(), + [], 'users/example', 'Kohana', NULL, 'https', FALSE, - ), - array( + ], + [ 'Kohana', - array(), + [], '/users/example', 'Kohana', NULL, 'https', FALSE, - ), - ); + ], + ]; } /** @@ -349,38 +349,38 @@ public function test_anchor($expected, array $options, $uri, $title = NULL, arra */ public function provider_file_anchor() { - return array( - array( + return [ + [ 'My picture file', - array(), + [], 'mypic.png', 'My picture file', - ), - array( + ], + [ 'My picture file', - array('attr' => 'value'), + ['attr' => 'value'], 'mypic.png', 'My picture file', 'https', TRUE - ), - array( + ], + [ 'My picture file', - array(), + [], 'mypic.png', 'My picture file', 'ftp', FALSE - ), - array( + ], + [ 'My picture file', - array(), + [], '/mypic.png', 'My picture file', 'ftp', FALSE - ), - ); + ], + ]; } /** diff --git a/system/tests/kohana/HTTPTest.php b/system/tests/kohana/HTTPTest.php index ed08b81..ec033f2 100644 --- a/system/tests/kohana/HTTPTest.php +++ b/system/tests/kohana/HTTPTest.php @@ -27,7 +27,9 @@ public function setUp() // @codingStandardsIgnoreEnd { parent::setUp(); - Kohana::$config->load('url')->set('trusted_hosts', array('www\.example\.com')); + Kohana::$config->load('url')->set('trusted_hosts', [ + 'www\.example\.com' + ]); $this->_initial_request = Request::$initial; Request::$initial = new Request('/'); } @@ -49,11 +51,11 @@ public function tearDown() * @var array */ // @codingStandardsIgnoreStart - protected $environmentDefault = array( + protected $environmentDefault = [ 'Kohana::$base_url' => '/kohana/', 'Kohana::$index_file' => 'index.php', 'HTTP_HOST' => 'www.example.com', - ); + ]; // @codingStandardsIgnoreEnd /** @@ -63,26 +65,26 @@ public function tearDown() */ public function provider_redirect() { - return array( - array( + return [ + [ 'http://www.example.org/', 301, 'HTTP_Exception_301', 'http://www.example.org/' - ), - array( + ], + [ '/page_one', 302, 'HTTP_Exception_302', 'http://www.example.com/kohana/index.php/page_one' - ), - array( + ], + [ 'page_two', 303, 'HTTP_Exception_303', 'http://www.example.com/kohana/index.php/page_two' - ), - ); + ], + ]; } /** @@ -118,32 +120,32 @@ public function test_redirect($location, $code, $expected_exception, $expected_l */ public function provider_request_headers() { - return array( - array( - array( + return [ + [ + [ 'CONTENT_TYPE' => 'text/html; charset=utf-8', 'CONTENT_LENGTH' => '3547', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, sdch', 'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8,fr;q=0.6,hy;q=0.4', - ), - array( + ], + [ 'content-type' => 'text/html; charset=utf-8', 'content-length' => '3547', 'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'accept-encoding' => 'gzip, deflate, sdch', 'accept-language' => 'en-US,en;q=0.8,fr;q=0.6,hy;q=0.4', - ) - ), - array( - array( + ] + ], + [ + [ 'HTTP_WEIRD_HTTP_HEADER' => 'A weird value for a weird header', - ), - array( + ], + [ 'weird-http-header' => 'A weird value for a weird header', - ) - ), - ); + ] + ], + ]; } /** diff --git a/system/tests/kohana/Http/HeaderTest.php b/system/tests/kohana/Http/HeaderTest.php index b148866..288609d 100644 --- a/system/tests/kohana/Http/HeaderTest.php +++ b/system/tests/kohana/Http/HeaderTest.php @@ -10,7 +10,7 @@ * @group kohana.core.http * @group kohana.core.http.header * @group kohana.core.http.header - * + * * @package Kohana * @category Tests * @author Kohana Team @@ -26,40 +26,40 @@ class Kohana_HTTP_HeaderTest extends Unittest_TestCase */ public function provider_accept_quality() { - return array( - array( - array( + return [ + [ + [ 'text/html; q=1', 'text/plain; q=.5', 'application/json; q=.1', 'text/*' - ), - array( + ], + [ 'text/html' => (float) 1, 'text/plain' => 0.5, 'application/json' => 0.1, 'text/*' => (float) 1 - ) - ), - array( - array( + ] + ], + [ + [ 'text/*', 'text/html; level=1; q=0.4', 'application/xml+rss; q=0.5; level=4' - ), - array( + ], + [ 'text/*' => (float) 1, 'text/html; level=1' => 0.4, 'application/xml+rss; level=4' => 0.5 - ) - ) - ); + ] + ], + ]; } /** * Tests the `accept_quality` method parses the quality values * correctly out of header parts - * + * * @dataProvider provider_accept_quality * * @param array $parts input @@ -84,43 +84,43 @@ public function test_accept_quality(array $parts, array $expected) */ public function provider_parse_accept_header() { - return array( - array( + return [ + [ 'text/html, text/plain, text/*, */*', - array( - 'text' => array( + [ + 'text' => [ 'html' => (float) 1, 'plain' => (float) 1, '*' => (float) 1 - ), - '*' => array( + ], + '*' => [ '*' => (float) 1 - ) - ) - ), - array( + ] + ] + ], + [ 'text/html; q=.5, application/json, application/xml+rss; level=1; q=.7, text/*, */*', - array( - 'text' => array( + [ + 'text' => [ 'html' => 0.5, '*' => (float) 1 - ), - 'application' => array( + ], + 'application' => [ 'json' => (float) 1, 'xml+rss; level=1' => 0.7 - ), - '*' => array( + ], + '*' => [ '*' => (float) 1 - ) - ) - ) - ); + ] + ] + ], + ]; } /** * Tests the `parse_accept_header` method parses the Accept: header * correctly and returns expected output - * + * * @dataProvider provider_parse_accept_header * * @param string $accept accept in @@ -139,42 +139,42 @@ public function test_parse_accept_header($accept, array $expected) */ public function provider_parse_charset_header() { - return array( - array( + return [ + [ 'utf-8, utf-10, utf-16, iso-8859-1', - array( + [ 'utf-8' => (float) 1, 'utf-10' => (float) 1, 'utf-16' => (float) 1, 'iso-8859-1' => (float) 1 - ) - ), - array( + ] + ], + [ 'utf-8, utf-10; q=.9, utf-16; q=.5, iso-8859-1; q=.75', - array( + [ 'utf-8' => (float) 1, 'utf-10' => 0.9, 'utf-16' => 0.5, 'iso-8859-1' => 0.75 - ) - ), - array( + ] + ], + [ NULL, - array( + [ '*' => (float) 1 - ) - ) - ); + ] + ], + ]; } /** * Tests the `parse_charset_header` method parsed the Accept-Charset header * correctly - * + * * @dataProvider provider_parse_charset_header * - * @param string $accept accept - * @param array $expected expected + * @param string $accept accept + * @param array $expected expected * @return void */ public function test_parse_charset_header($accept, array $expected) @@ -189,46 +189,46 @@ public function test_parse_charset_header($accept, array $expected) */ public function provider_parse_encoding_header() { - return array( - array( + return [ + [ 'compress, gzip, blowfish', - array( + [ 'compress' => (float) 1, 'gzip' => (float) 1, 'blowfish' => (float) 1 - ) - ), - array( + ] + ], + [ 'compress, gzip; q=0.12345, blowfish; q=1.0', - array( + [ 'compress' => (float) 1, 'gzip' => 0.12345, 'blowfish' => (float) 1 - ) - ), - array( + ] + ], + [ NULL, - array( + [ '*' => (float) 1 - ) - ), - array( + ] + ], + [ '', - array( + [ 'identity' => (float) 1 - ) - ) - ); + ] + ], + ]; } /** * Tests the `parse_encoding_header` method parses the Accept-Encoding header * correctly - * + * * @dataProvider provider_parse_encoding_header * - * @param string $accept accept - * @param array $expected expected + * @param string $accept accept + * @param array $expected expected * @return void */ public function test_parse_encoding_header($accept, array $expected) @@ -243,61 +243,61 @@ public function test_parse_encoding_header($accept, array $expected) */ public function provider_parse_language_header() { - return array( - array( + return [ + [ 'en, en-us, en-gb, fr, fr-fr, es-es', - array( - 'en' => array( + [ + 'en' => [ '*' => (float) 1, 'us' => (float) 1, 'gb' => (float) 1 - ), - 'fr' => array( + ], + 'fr' => [ '*' => (float) 1, 'fr' => (float) 1 - ), - 'es' => array( + ], + 'es' => [ 'es' => (float) 1 - ) - ) - ), - array( + ] + ] + ], + [ 'en; q=.9, en-us, en-gb, fr; q=.5, fr-fr; q=0.4, es-es; q=0.9, en-gb-gb; q=.45', - array( - 'en' => array( + [ + 'en' => [ '*' => 0.9, 'us' => (float) 1, 'gb' => (float) 1, 'gb-gb' => 0.45 - ), - 'fr' => array( + ], + 'fr' => [ '*' => 0.5, 'fr' => 0.4 - ), - 'es' => array( + ], + 'es' => [ 'es' => 0.9 - ) - ) - ), - array( + ] + ] + ], + [ NULL, - array( - '*' => array( + [ + '*' => [ '*' => (float) 1 - ) - ) - ) - ); + ] + ] + ], + ]; } /** * Tests the `parse_language_header` method parses the Accept-Language header * correctly - * + * * @dataProvider provider_parse_language_header - * - * @param string $accept accept - * @param array $expected expected + * + * @param string $accept accept + * @param array $expected expected * @return void */ public function test_parse_language_header($accept, array $expected) @@ -312,45 +312,45 @@ public function test_parse_language_header($accept, array $expected) */ public function provider_create_cache_control() { - return array( - array( - array( + return [ + [ + [ 'public', 'max-age' => 1800, 'must-revalidate', 's-max-age' => 3600 - ), + ], 'public, max-age=1800, must-revalidate, s-max-age=3600' - ), - array( - array( + ], + [ + [ 'max-age' => 1800, 's-max-age' => 1800, 'public', 'must-revalidate', - ), + ], 'max-age=1800, s-max-age=1800, public, must-revalidate' - ), - array( - array( + ], + [ + [ 'private', 'no-cache', 'max-age' => 0, 'must-revalidate' - ), + ], 'private, no-cache, max-age=0, must-revalidate' - ) - ); + ], + ]; } /** * Tests that `create_cache_control()` outputs the correct cache control * string from the supplied input - * + * * @dataProvider provider_create_cache_control * - * @param array $input input - * @param string $expected expected + * @param array $input input + * @param string $expected expected * @return void */ public function test_create_cache_control(array $input, $expected) @@ -365,35 +365,35 @@ public function test_create_cache_control(array $input, $expected) */ public function provider_parse_cache_control() { - return array( - array( + return [ + [ 'public, max-age=1800, must-revalidate, s-max-age=3600', - array( + [ 'public', 'max-age' => 1800, 'must-revalidate', 's-max-age' => 3600 - ) - ), - array( + ] + ], + [ 'max-age=1800, s-max-age=1800, public, must-revalidate', - array( + [ 'max-age' => 1800, 's-max-age' => 1800, 'public', 'must-revalidate', - ) - ), - array( + ] + ], + [ 'private, no-cache, max-age=0, must-revalidate', - array( + [ 'private', 'no-cache', 'max-age' => 0, 'must-revalidate' - ) - ) - ); + ] + ], + ]; } /** @@ -401,9 +401,9 @@ public function provider_parse_cache_control() * parsed data from the input string * * @dataProvider provider_parse_cache_control - * - * @param string $input input - * @param array $expected expected + * + * @param string $input input + * @param array $expected expected * @return void */ public function test_parse_cache_control($input, array $expected) @@ -431,98 +431,68 @@ public function test_parse_cache_control($input, array $expected) public function provider_offsetSet() // @codingStandardsIgnoreEnd { - return array( - array( - array( + return [ + [ + [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'text/html, text/plain; q=.1, */*', 'Accept-Language' => 'en-gb, en-us, en; q=.1' - ), - array( - array( - 'Accept-Encoding', - 'compress, gzip', - FALSE - ) - ), - array( + ], + [ + ['Accept-Encoding', 'compress, gzip', FALSE] + ], + [ 'content-type' => 'application/x-www-form-urlencoded', 'accept' => 'text/html, text/plain; q=.1, */*', 'accept-language' => 'en-gb, en-us, en; q=.1', 'accept-encoding' => 'compress, gzip' - ) - ), - array( - array( + ] + ], + [ + [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'text/html, text/plain; q=.1, */*', 'Accept-Language' => 'en-gb, en-us, en; q=.1' - ), - array( - array( - 'Accept-Encoding', - 'compress, gzip', - FALSE - ), - array( - 'Accept-Encoding', - 'bzip', - FALSE - ) - ), - array( + ], + [ + ['Accept-Encoding', 'compress, gzip', FALSE], + ['Accept-Encoding', 'bzip', FALSE] + ], + [ 'content-type' => 'application/x-www-form-urlencoded', 'accept' => 'text/html, text/plain; q=.1, */*', 'accept-language' => 'en-gb, en-us, en; q=.1', - 'accept-encoding' => array( - 'compress, gzip', - 'bzip' - ) - ) - ), - array( - array( + 'accept-encoding' => ['compress, gzip', 'bzip'] + ] + ], + [ + [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'text/html, text/plain; q=.1, */*', 'Accept-Language' => 'en-gb, en-us, en; q=.1' - ), - array( - array( - 'Accept-Encoding', - 'compress, gzip', - FALSE - ), - array( - 'Accept-Encoding', - 'bzip', - TRUE - ), - array( - 'Accept', - 'text/*', - FALSE - ) - ), - array( + ], + [ + ['Accept-Encoding', 'compress, gzip', FALSE], + ['Accept-Encoding', 'bzip', TRUE], + ['Accept', 'text/*', FALSE] + ], + [ 'content-type' => 'application/x-www-form-urlencoded', - 'accept' => array( - 'text/html, text/plain; q=.1, */*', - 'text/*' - ), + 'accept' => ['text/html, text/plain; q=.1, */*', 'text/*'], 'accept-language' => 'en-gb, en-us, en; q=.1', 'accept-encoding' => 'bzip' - ) - ), - ); + ] + ], + ]; } /** * Ensures that offsetSet normalizes the array keys * * @dataProvider provider_offsetSet - * + * * @param array $constructor constructor - * @param array $to_set to_set + * @param array $to_set to_set * @param array $expected expected * @return void */ @@ -551,58 +521,58 @@ public function test_offsetSet(array $constructor, array $to_set, array $expecte public function provider_offsetGet() // @codingStandardsIgnoreEnd { - return array( - array( - array( + return [ + [ + [ 'FoO' => 'bar', 'START' => 'end', 'true' => TRUE - ), + ], 'FOO', 'bar' - ), - array( - array( + ], + [ + [ 'FoO' => 'bar', 'START' => 'end', 'true' => TRUE - ), + ], 'true', TRUE - ), - array( - array( + ], + [ + [ 'FoO' => 'bar', 'START' => 'end', 'true' => TRUE - ), + ], 'True', TRUE - ), - array( - array( + ], + [ + [ 'FoO' => 'bar', 'START' => 'end', 'true' => TRUE - ), + ], 'Start', 'end' - ), - array( - array( + ], + [ + [ 'content-type' => 'bar', 'Content-Type' => 'end', 'Accept' => '*/*' - ), + ], 'content-type', 'end' - ) - ); + ], + ]; } /** * Ensures that offsetGet normalizes the array keys - * + * * @dataProvider provider_offsetGet * * @param array start state @@ -628,54 +598,54 @@ public function test_offsetGet(array $state, $key, $expected) public function provider_offsetExists() // @codingStandardsIgnoreEnd { - return array( - array( - array( + return [ + [ + [ 'Accept' => 'text/html, application/json', 'Accept-Language' => 'en, en-GB', 'Content-Type' => 'application/x-www-form-urlencoded' - ), + ], 'Content-Type', TRUE - ), - array( - array( + ], + [ + [ 'Accept' => 'text/html, application/json', 'Accept-Language' => 'en, en-GB', 'Content-Type' => 'application/x-www-form-urlencoded' - ), + ], 'CONTENT-TYPE', TRUE - ), - array( - array( + ], + [ + [ 'Accept' => 'text/html, application/json', 'Accept-Language' => 'en, en-GB', 'Content-Type' => 'application/x-www-form-urlencoded' - ), + ], 'accept-language', TRUE - ), - array( - array( + ], + [ + [ 'Accept' => 'text/html, application/json', 'Accept-Language' => 'en, en-GB', 'Content-Type' => 'application/x-www-form-urlencoded' - ), + ], 'x-powered-by', FALSE - ) - ); + ], + ]; } /** * Ensures that offsetExists normalizes the array key - * + * * @dataProvider provider_offsetExists * - * @param array $state state - * @param string $key key - * @param boolean $expected expected + * @param array $state state + * @param string $key key + * @param boolean $expected expected * @return void */ // @codingStandardsIgnoreStart @@ -696,44 +666,44 @@ public function test_offsetExists(array $state, $key, $expected) public function provider_offsetUnset() // @codingStandardsIgnoreEnd { - return array( - array( - array( + return [ + [ + [ 'Accept' => 'text/html, application/json', 'Accept-Language' => 'en, en-GB', 'Content-Type' => 'application/x-www-form-urlencoded' - ), + ], 'Accept-Language', - array( + [ 'accept' => 'text/html, application/json', 'content-type' => 'application/x-www-form-urlencoded' - ) - ), - array( - array( + ] + ], + [ + [ 'Accept' => 'text/html, application/json', 'Accept-Language' => 'en, en-GB', 'Content-Type' => 'application/x-www-form-urlencoded' - ), + ], 'ACCEPT', - array( + [ 'accept-language' => 'en, en-GB', 'content-type' => 'application/x-www-form-urlencoded' - ) - ), - array( - array( + ] + ], + [ + [ 'Accept' => 'text/html, application/json', 'Accept-Language' => 'en, en-GB', 'Content-Type' => 'application/x-www-form-urlencoded' - ), + ], 'content-type', - array( + [ 'accept' => 'text/html, application/json', 'accept-language' => 'en, en-GB', - ) - ) - ); + ] + ], + ]; } /** @@ -741,9 +711,9 @@ public function provider_offsetUnset() * * @dataProvider provider_offsetUnset * - * @param array $state state - * @param string $remove remove - * @param array $expected expected + * @param array $state state + * @param string $remove remove + * @param array $expected expected * @return void */ // @codingStandardsIgnoreStart @@ -763,50 +733,50 @@ public function test_offsetUnset(array $state, $remove, array $expected) */ public function provider_parse_header_string() { - return array( - array( - array( + return [ + [ + [ "Content-Type: application/x-www-form-urlencoded\r\n", "Accept: text/html, text/plain; q=.5, application/json, */* \r\n", "X-Powered-By: Kohana Baby \r\n" - ), - array( + ], + [ 'content-type' => 'application/x-www-form-urlencoded', 'accept' => 'text/html, text/plain; q=.5, application/json, */* ', 'x-powered-by' => 'Kohana Baby ' - ) - ), - array( - array( + ] + ], + [ + [ "Content-Type: application/x-www-form-urlencoded\r\n", "Accept: text/html, text/plain; q=.5, application/json, */* \r\n", "X-Powered-By: Kohana Baby \r\n", "Content-Type: application/json\r\n" - ), - array( - 'content-type' => array( + ], + [ + 'content-type' => [ 'application/x-www-form-urlencoded', 'application/json' - ), + ], 'accept' => 'text/html, text/plain; q=.5, application/json, */* ', 'x-powered-by' => 'Kohana Baby ' - ) - ) - ); + ] + ], + ]; } /** * Tests that `parse_header_string` performs as expected - * + * * @dataProvider provider_parse_header_string * - * @param array headers - * @param array expected + * @param array headers + * @param array expected * @return void */ public function test_parse_header_string(array $headers, array $expected) { - $http_header = new HTTP_Header(array()); + $http_header = new HTTP_Header([]); foreach ($headers as $header) { @@ -823,73 +793,73 @@ public function test_parse_header_string(array $headers, array $expected) */ public function provider_accepts_at_quality() { - return array( - array( - array( + return [ + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), + ], 'application/json', FALSE, 1.0 - ), - array( - array( + ], + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), + ], 'text/html', FALSE, 0.5 - ), - array( - array( + ], + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), + ], 'text/plain', FALSE, 0.1 - ), - array( - array( + ], + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), + ], 'text/plain', TRUE, FALSE - ), - array( - array( + ], + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), + ], 'application/xml', FALSE, 1.0 - ), - array( - array( + ], + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), + ], 'application/xml', TRUE, FALSE - ), - array( - array(), + ], + [ + [], 'application/xml', FALSE, 1.0 - ), - array( - array(), + ], + [ + [], 'application/xml', TRUE, FALSE - ) - ); + ], + ]; } /** * Tests `accepts_at_quality` parsed the Accept: header as expected - * + * * @dataProvider provider_accepts_at_quality * * @param array starting state @@ -912,67 +882,51 @@ public function test_accepts_at_quality(array $state, $accept, $explicit, $expec */ public function provider_preferred_accept() { - return array( - array( - array( + return [ + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), - array( - 'text/html', - 'application/json', - 'text/plain' - ), + ], + ['text/html', 'application/json', 'text/plain'], FALSE, 'application/json' - ), - array( - array( + ], + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), - array( - 'text/plain', - 'application/xml', - 'image/jpeg' - ), + ], + ['text/plain', 'application/xml', 'image/jpeg'], FALSE, 'application/xml' - ), - array( - array( + ], + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1' - ), - array( - 'text/plain', - 'application/xml', - 'image/jpeg' - ), + ], + ['text/plain', 'application/xml', 'image/jpeg'], FALSE, 'text/plain' - ), - array( - array( + ], + [ + [ 'Accept' => 'application/json, text/html; q=.5, text/*; q=.1, */*' - ), - array( - 'text/plain', - 'application/xml', - 'image/jpeg' - ), + ], + ['text/plain', 'application/xml', 'image/jpeg'], TRUE, FALSE - ), - ); + ], + ]; } /** * Tests `preferred_accept` returns the correct preferred type - * + * * @dataProvider provider_preferred_accept * - * @param array state - * @param array accepts - * @param string explicit - * @param string expected + * @param array state + * @param array accepts + * @param string explicit + * @param string expected * @return void */ public function test_preferred_accept(array $state, array $accepts, $explicit, $expected) @@ -989,47 +943,47 @@ public function test_preferred_accept(array $state, array $accepts, $explicit, $ */ public function provider_accepts_charset_at_quality() { - return array( - array( - array( + return [ + [ + [ 'Accept-Charset' => 'utf-8, utf-10, utf-16, iso-8859-1' - ), + ], 'utf-8', 1.0 - ), - array( - array( + ], + [ + [ 'Accept-Charset' => 'utf-8, utf-10, utf-16, iso-8859-1' - ), + ], 'utf-16', 1.0 - ), - array( - array( + ], + [ + [ 'Accept-Charset' => 'utf-8; q=.1, utf-10, utf-16; q=.2, iso-8859-1' - ), + ], 'utf-8', 0.1 - ), - array( - array( + ], + [ + [ 'Accept-Charset' => 'utf-8; q=.1, utf-10, utf-16; q=.2, iso-8859-1; q=.5' - ), + ], 'iso-8859-1', 0.5 - ) - ); + ], + ]; } /** * Tests `accepts_charset_at_quality` works as expected, returning the correct * quality value - * + * * @dataProvider provider_accepts_charset_at_quality * - * @param array state - * @param string charset - * @param string expected + * @param array state + * @param string charset + * @param string expected * @return void */ public function test_accepts_charset_at_quality(array $state, $charset, $expected) @@ -1046,38 +1000,29 @@ public function test_accepts_charset_at_quality(array $state, $charset, $expecte */ public function provider_preferred_charset() { - return array( - array( - array( - 'Accept-Charset' => 'utf-8, utf-10, utf-16, iso-8859-1' - ), - array( - 'utf-8', - 'utf-16' - ), + return [ + [ + ['Accept-Charset' => 'utf-8, utf-10, utf-16, iso-8859-1'], + ['utf-8', 'utf-16'], 'utf-8' - ), - array( - array( - 'Accept-Charset' => 'utf-8, utf-10, utf-16, iso-8859-1' - ), - array( - 'UTF-10' - ), + ], + [ + ['Accept-Charset' => 'utf-8, utf-10, utf-16, iso-8859-1'], + ['UTF-10'], 'UTF-10' - ), - ); + ], + ]; } /** * Tests `preferred_charset` works as expected, returning the correct charset * from the list supplied - * + * * @dataProvider provider_preferred_charset * - * @param array state - * @param array charsets - * @param string expected + * @param array state + * @param array charsets + * @param string expected * @return void */ public function test_preferred_charset(array $state, array $charsets, $expected) @@ -1094,60 +1039,60 @@ public function test_preferred_charset(array $state, array $charsets, $expected) */ public function provider_accepts_encoding_at_quality() { - return array( - array( - array( + return [ + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.7, *; q=.5' - ), + ], 'gzip', FALSE, 1.0 - ), - array( - array( + ], + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.7, *; q=.5' - ), + ], 'gzip', TRUE, 1.0 - ), - array( - array( + ], + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.7, *; q=.5' - ), + ], 'blowfish', FALSE, 0.7 - ), - array( - array( + ], + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.7, *; q=.5' - ), + ], 'bzip', FALSE, 0.5 - ), - array( - array( + ], + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.7, *; q=.5' - ), + ], 'bzip', TRUE, (float) 0 - ) - ); + ], + ]; } /** * Tests `accepts_encoding_at_quality` parses and returns the correct * quality value for Accept-Encoding headers - * + * * @dataProvider provider_accepts_encoding_at_quality * - * @param array state - * @param string encoding - * @param boolean explicit - * @param float expected + * @param array state + * @param string encoding + * @param boolean explicit + * @param float expected * @return void */ public function test_accepts_encoding_at_quality(array $state, $encoding, $explicit, $expected) @@ -1163,50 +1108,50 @@ public function test_accepts_encoding_at_quality(array $state, $encoding, $expli */ public function provider_preferred_encoding() { - return array( - array( - array( + return [ + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.7, *; q=.5' - ), - array('gzip', 'blowfish', 'bzip'), + ], + ['gzip', 'blowfish', 'bzip'], FALSE, 'gzip' - ), - array( - array( + ], + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.7, *; q=.5' - ), - array('bzip', 'ROT-13'), + ], + ['bzip', 'ROT-13'], FALSE, 'bzip' - ), - array( - array( + ], + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.7, *; q=.5' - ), - array('bzip', 'ROT-13'), + ], + ['bzip', 'ROT-13'], TRUE, FALSE - ), - array( - array( + ], + [ + [ 'accept-encoding' => 'compress, gzip, blowfish; q=.2, *; q=.5' - ), - array('ROT-13', 'blowfish'), + ], + ['ROT-13', 'blowfish'], FALSE, 'ROT-13' - ), - ); + ], + ]; } /** * Tests that `preferred_encoding` parses and returns the correct * encoding type - * + * * @dataProvider provider_preferred_encoding * * @param array state in - * @param array encodings to interrogate + * @param array encodings to interrogate * @param boolean explicit check * @param string expected output * @return void @@ -1224,56 +1169,56 @@ public function test_preferred_encoding(array $state, array $encodings, $explici */ public function provider_accepts_language_at_quality() { - return array( - array( - array( + return [ + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), + ], 'en', FALSE, 0.5 - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), + ], 'en-gb', FALSE, 0.7 - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), + ], 'en', TRUE, 0.5 - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), + ], 'fr-ni', FALSE, 0.8 - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), + ], 'fr-ni', TRUE, (float) 0 - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-US' - ), + ], 'en-us', TRUE, (float) 1 - ), - ); + ], + ]; } /** @@ -1281,7 +1226,7 @@ public function provider_accepts_language_at_quality() * correctly and identifies the correct quality supplied, explicit or not * * @dataProvider provider_accepts_language_at_quality - * + * * @param array state in * @param string language to interrogate * @param boolean explicit check @@ -1301,72 +1246,54 @@ public function test_accepts_language_at_quality(array $state, $language, $expli */ public function provider_preferred_language() { - return array( - array( - array( + return [ + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), - array( - 'en', - 'fr', - 'en-gb' - ), + ], + ['en', 'fr', 'en-gb'], FALSE, 'fr' - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), - array( - 'en', - 'fr', - 'en-gb' - ), + ], + ['en', 'fr', 'en-gb'], TRUE, 'fr' - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), - array( - 'en-au', - 'fr-ni', - 'fr' - ), + ], + ['en-au', 'fr-ni', 'fr'], FALSE, 'fr-ni' - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-us; q=.9, en-gb; q=.7, en; q=.5, fr-fr; q=.9, fr; q=.8' - ), - array( - 'en-au', - 'fr-ni', - 'fr' - ), + ], + ['en-au', 'fr-ni', 'fr'], TRUE, 'fr' - ), - array( - array( + ], + [ + [ 'accept-language' => 'en-US' - ), - array( - 'en-us' - ), + ], + ['en-us'], TRUE, 'en-us' - ), - ); + ], + ]; } /** * Tests that `preferred_language` correctly identifies the right * language based on the Accept-Language header and `$explicit` setting - * + * * @dataProvider provider_preferred_language * * @param array state in @@ -1390,43 +1317,43 @@ public function provider_send_headers() { $content_type = Kohana::$content_type . '; charset=' . Kohana::$charset; - return array( - array( - array(), - array( + return [ + [ + [], + [ 'HTTP/1.1 200 OK', 'Content-Type: ' . $content_type, - ), - FALSE, - ), - array( - array(), - array( + ], + FALSE + ], + [ + [], + [ 'HTTP/1.1 200 OK', 'Content-Type: ' . $content_type, 'X-Powered-By: ' . Kohana::version(), - ), - TRUE, - ), - array( - array( + ], + TRUE + ], + [ + [ 'accept' => 'text/html, text/plain, text/*, */*', 'accept-charset' => 'utf-8, utf-10, iso-8859-1', 'accept-encoding' => 'compress, gzip', 'accept-language' => 'en, en-gb, en-us' - ), - array( + ], + [ 'HTTP/1.1 200 OK', 'Accept: text/html, text/plain, text/*, */*', 'Accept-Charset: utf-8, utf-10, iso-8859-1', 'Accept-Encoding: compress, gzip', 'Accept-Language: en, en-gb, en-us', 'Content-Type: ' . $content_type, - ), + ], FALSE - ), - array( - array( + ], + [ + [ 'accept' => 'text/html, text/plain, text/*, */*', 'accept-charset' => 'utf-8, utf-10, iso-8859-1', 'accept-encoding' => 'compress, gzip', @@ -1434,8 +1361,8 @@ public function provider_send_headers() 'content-type' => 'application/json', 'x-powered-by' => 'Mohana', 'x-ssl-enabled' => 'TRUE' - ), - array( + ], + [ 'HTTP/1.1 200 OK', 'Accept: text/html, text/plain, text/*, */*', 'Accept-Charset: utf-8, utf-10, iso-8859-1', @@ -1444,15 +1371,15 @@ public function provider_send_headers() 'Content-Type: application/json', 'X-Powered-By: Mohana', 'X-Ssl-Enabled: TRUE' - ), + ], TRUE - ) - ); + ], + ]; } /** * Tests that send headers processes the headers sent to PHP correctly - * + * * @dataProvider provider_send_headers * * @param array state in @@ -1466,16 +1393,16 @@ public function test_send_headers(array $state, array $expected, $expose) $response = new Response; $response->headers($state); - $this->assertSame( - $expected, $response->send_headers(FALSE, array($this, 'send_headers_handler')) - ); + $this->assertSame($expected, $response->send_headers(FALSE, [ + $this, 'send_headers_handler' + ])); } /** * Callback handler for send headers * - * @param array headers - * @param boolean replace + * @param array headers + * @param boolean replace * @return array */ public function send_headers_handler($response, $headers, $replace) diff --git a/system/tests/kohana/I18nTest.php b/system/tests/kohana/I18nTest.php index 298c6b4..686ef15 100644 --- a/system/tests/kohana/I18nTest.php +++ b/system/tests/kohana/I18nTest.php @@ -23,9 +23,9 @@ class Kohana_I18nTest extends Unittest_TestCase * @var array */ // @codingStandardsIgnoreStart - protected $environmentDefault = array( + protected $environmentDefault = [ 'I18n::$lang' => 'en-us', - ); + ]; // @codingStandardsIgnoreEnd /** @@ -35,11 +35,11 @@ class Kohana_I18nTest extends Unittest_TestCase */ public function provider_lang() { - return array( + return [ // $input, $expected_result - array(NULL, 'en-us'), - array('es-es', 'es-es'), - ); + [NULL, 'en-us'], + ['es-es', 'es-es'], + ]; } /** @@ -58,17 +58,17 @@ public function test_lang($input, $expected_result) /** * Provides test data for test_get() - * + * * @return array */ public function provider_get() { - return array( + return [ // $value, $result - array('en-us', 'Hello, world!', 'Hello, world!'), - array('es-es', 'Hello, world!', '¡Hola, mundo!'), - array('fr-fr', 'Hello, world!', 'Bonjour, monde!'), - ); + ['en-us', 'Hello, world!', 'Hello, world!'], + ['es-es', 'Hello, world!', '¡Hola, mundo!'], + ['fr-fr', 'Hello, world!', 'Bonjour, monde!'], + ]; } /** diff --git a/system/tests/kohana/InflectorTest.php b/system/tests/kohana/InflectorTest.php index 9411d53..d1558e7 100644 --- a/system/tests/kohana/InflectorTest.php +++ b/system/tests/kohana/InflectorTest.php @@ -20,19 +20,19 @@ class Kohana_InflectorTest extends Unittest_TestCase { /** * Provides test data for test_lang() - * + * * @return array */ public function provider_uncountable() { - return array( + return [ // $value, $result - array('fish', TRUE), - array('cat', FALSE), - array('deer', TRUE), - array('bison', TRUE), - array('friend', FALSE), - ); + ['fish', TRUE], + ['cat', FALSE], + ['deer', TRUE], + ['bison', TRUE], + ['friend', FALSE], + ]; } /** @@ -50,25 +50,25 @@ public function test_uncountable($input, $expected) /** * Provides test data for test_lang() - * + * * @return array */ public function provider_singular() { - return array( + return [ // $value, $result - array('fish', NULL, 'fish'), - array('cats', NULL, 'cat'), - array('cats', 2, 'cats'), - array('cats', '2', 'cats'), - array('children', NULL, 'child'), - array('meters', 0.6, 'meters'), - array('meters', 1.6, 'meters'), - array('meters', 1.0, 'meter'), - array('status', NULL, 'status'), - array('statuses', NULL, 'status'), - array('heroes', NULL, 'hero'), - ); + ['fish', NULL, 'fish'], + ['cats', NULL, 'cat'], + ['cats', 2, 'cats'], + ['cats', '2', 'cats'], + ['children', NULL, 'child'], + ['meters', 0.6, 'meters'], + ['meters', 1.6, 'meters'], + ['meters', 1.0, 'meter'], + ['status', NULL, 'status'], + ['statuses', NULL, 'status'], + ['heroes', NULL, 'hero'], + ]; } /** @@ -86,25 +86,25 @@ public function test_singular($input, $count, $expected) /** * Provides test data for test_lang() - * + * * @return array */ public function provider_plural() { - return array( + return [ // $value, $result - array('fish', NULL, 'fish'), - array('cat', NULL, 'cats'), - array('cats', 1, 'cats'), - array('cats', '1', 'cats'), - array('movie', NULL, 'movies'), - array('meter', 0.6, 'meters'), - array('meter', 1.6, 'meters'), - array('meter', 1.0, 'meter'), - array('hero', NULL, 'heroes'), - array('Dog', NULL, 'Dogs'), // Titlecase - array('DOG', NULL, 'DOGS'), // Uppercase - ); + ['fish', NULL, 'fish'], + ['cat', NULL, 'cats'], + ['cats', 1, 'cats'], + ['cats', '1', 'cats'], + ['movie', NULL, 'movies'], + ['meter', 0.6, 'meters'], + ['meter', 1.6, 'meters'], + ['meter', 1.0, 'meter'], + ['hero', NULL, 'heroes'], + ['Dog', NULL, 'Dogs'], // Titlecase + ['DOG', NULL, 'DOGS'], // Uppercase + ]; } /** @@ -122,20 +122,20 @@ public function test_plural($input, $count, $expected) /** * Provides test data for test_camelize() - * + * * @return array */ public function provider_camelize() { - return array( + return [ // $value, $result - array('mother cat', 'camelize', 'motherCat'), - array('kittens in bed', 'camelize', 'kittensInBed'), - array('mother cat', 'underscore', 'mother_cat'), - array('kittens in bed', 'underscore', 'kittens_in_bed'), - array('kittens-are-cats', 'humanize', 'kittens are cats'), - array('dogs_as_well', 'humanize', 'dogs as well'), - ); + ['mother cat', 'camelize', 'motherCat'], + ['kittens in bed', 'camelize', 'kittensInBed'], + ['mother cat', 'underscore', 'mother_cat'], + ['kittens in bed', 'underscore', 'kittens_in_bed'], + ['kittens-are-cats', 'humanize', 'kittens are cats'], + ['dogs_as_well', 'humanize', 'dogs as well'], + ]; } /** @@ -158,18 +158,18 @@ public function test_camelize($input, $method, $expected) */ public function provider_decamelize() { - return array( - array('getText', '_', 'get_text'), - array('getJSON', '_', 'get_json'), - array('getLongText', '_', 'get_long_text'), - array('getI18N', '_', 'get_i18n'), - array('getL10n', '_', 'get_l10n'), - array('getTe5t1ng', '_', 'get_te5t1ng'), - array('OpenFile', '_', 'open_file'), - array('CloseIoSocket', '_', 'close_io_socket'), - array('fooBar', ' ', 'foo bar'), - array('camelCase', '+', 'camel+case'), - ); + return [ + ['getText', '_', 'get_text'], + ['getJSON', '_', 'get_json'], + ['getLongText', '_', 'get_long_text'], + ['getI18N', '_', 'get_i18n'], + ['getL10n', '_', 'get_l10n'], + ['getTe5t1ng', '_', 'get_te5t1ng'], + ['OpenFile', '_', 'open_file'], + ['CloseIoSocket', '_', 'close_io_socket'], + ['fooBar', ' ', 'foo bar'], + ['camelCase', '+', 'camel+case'], + ]; } /** diff --git a/system/tests/kohana/LogTest.php b/system/tests/kohana/LogTest.php index 65b8145..608b3b5 100644 --- a/system/tests/kohana/LogTest.php +++ b/system/tests/kohana/LogTest.php @@ -29,7 +29,7 @@ public function test_messages_is_initially_empty() { $logger = new Log; - $this->assertAttributeSame(array(), '_messages', $logger); + $this->assertAttributeSame([], '_messages', $logger); } /** @@ -43,7 +43,7 @@ public function test_writers_is_initially_empty() { $logger = new Log; - $this->assertAttributeSame(array(), '_writers', $logger); + $this->assertAttributeSame([], '_writers', $logger); } /** @@ -61,9 +61,9 @@ public function test_attach_attaches_log_writer_and_returns_this() $this->assertSame($logger, $logger->attach($writer)); - $this->assertAttributeSame( - array(spl_object_hash($writer) => array('object' => $writer, 'levels' => array())), '_writers', $logger - ); + $this->assertAttributeSame([ + spl_object_hash($writer) => ['object' => $writer, 'levels' => []] + ], '_writers', $logger); } /** @@ -82,9 +82,12 @@ public function test_attach_attaches_log_writer_min_max_and_returns_this() $this->assertSame($logger, $logger->attach($writer, Log::NOTICE, Log::CRITICAL)); - $this->assertAttributeSame( - array(spl_object_hash($writer) => array('object' => $writer, 'levels' => array(Log::CRITICAL, Log::ERROR, Log::WARNING, Log::NOTICE))), '_writers', $logger - ); + $this->assertAttributeSame([ + spl_object_hash($writer) => [ + 'object' => $writer, + 'levels' => [Log::CRITICAL, Log::ERROR, Log::WARNING, Log::NOTICE] + ] + ], '_writers', $logger); } /** @@ -102,7 +105,7 @@ public function test_detach_removes_log_writer_and_returns_this() $this->assertSame($logger, $logger->detach($writer)); - $this->assertAttributeSame(array(), '_writers', $logger); + $this->assertAttributeSame([], '_writers', $logger); } } diff --git a/system/tests/kohana/NumTest.php b/system/tests/kohana/NumTest.php index adde31e..8a1c21f 100644 --- a/system/tests/kohana/NumTest.php +++ b/system/tests/kohana/NumTest.php @@ -51,12 +51,12 @@ public function tearDown() */ public function provider_bytes() { - return array( - array(204800.0, '200K'), - array(5242880.0, '5MiB'), - array(1000.0, 1000), - array(2684354560.0, '2.5GB'), - ); + return [ + [204800.0, '200K'], + [5242880.0, '5MiB'], + [1000.0, 1000], + [2684354560.0, '2.5GB'], + ]; } /** @@ -79,14 +79,14 @@ public function test_bytes($expected, $size) */ public function provider_ordinal() { - return array( - array(0, 'th'), - array(1, 'st'), - array(21, 'st'), - array(112, 'th'), - array(23, 'rd'), - array(42, 'nd'), - ); + return [ + [0, 'th'], + [1, 'st'], + [21, 'st'], + [112, 'th'], + [23, 'rd'], + [42, 'nd'], + ]; } /** @@ -107,14 +107,14 @@ public function test_ordinal($number, $expected) */ public function provider_format() { - return array( + return [ // English - array(10000, 2, FALSE, '10,000.00'), - array(10000, 2, TRUE, '10,000.00'), + [10000, 2, FALSE, '10,000.00'], + [10000, 2, TRUE, '10,000.00'], // Additional dp's should be removed - array(123.456, 2, FALSE, '123.46'), - array(123.456, 2, TRUE, '123.46'), - ); + [123.456, 2, FALSE, '123.46'], + [123.456, 2, TRUE, '123.46'], + ]; } /** @@ -138,56 +138,16 @@ public function test_format($number, $places, $monetary, $expected) */ function provider_round() { - return array( - array(5.5, 0, array( - 6.0, - 5.0, - 6.0, - 5.0, - )), - array(42.5, 0, array( - 43.0, - 42.0, - 42.0, - 43.0, - )), - array(10.4, 0, array( - 10.0, - 10.0, - 10.0, - 10.0, - )), - array(10.8, 0, array( - 11.0, - 11.0, - 11.0, - 11.0, - )), - array(-5.5, 0, array( - -6.0, - -5.0, - -6.0, - -5.0, - )), - array(-10.5, 0, array( - -11.0, - -10.0, - -10.0, - -11.0, - )), - array(26.12375, 4, array( - 26.1238, - 26.1237, - 26.1238, - 26.1237, - )), - array(26.12325, 4, array( - 26.1233, - 26.1232, - 26.1232, - 26.1233, - )), - ); + return [ + [5.5, 0, [6.0, 5.0, 6.0, 5.0]], + [42.5, 0, [43.0, 42.0, 42.0, 43.0]], + [10.4, 0, [10.0, 10.0, 10.0, 10.0]], + [10.8, 0, [11.0, 11.0, 11.0, 11.0]], + [-5.5, 0, [-6.0, -5.0, -6.0, -5.0]], + [-10.5, 0, [-11.0, -10.0, -10.0, -11.0]], + [26.12375, 4, [26.1238, 26.1237, 26.1238, 26.1237]], + [26.12325, 4, [26.1233, 26.1232, 26.1232, 26.1233]], + ]; } /** @@ -200,7 +160,7 @@ function provider_round() */ function test_round($input, $precision, $expected) { - foreach (array(Num::ROUND_HALF_UP, Num::ROUND_HALF_DOWN, Num::ROUND_HALF_EVEN, Num::ROUND_HALF_ODD) as $i => $mode) { + foreach ([Num::ROUND_HALF_UP, Num::ROUND_HALF_DOWN, Num::ROUND_HALF_EVEN, Num::ROUND_HALF_ODD] as $i => $mode) { $this->assertSame($expected[$i], Num::round($input, $precision, $mode, FALSE)); } } diff --git a/system/tests/kohana/RequestTest.php b/system/tests/kohana/RequestTest.php index 9eb4656..3859784 100644 --- a/system/tests/kohana/RequestTest.php +++ b/system/tests/kohana/RequestTest.php @@ -25,7 +25,7 @@ public function setUp() // @codingStandardsIgnoreEnd { parent::setUp(); - Kohana::$config->load('url')->set('trusted_hosts', array('localhost')); + Kohana::$config->load('url')->set('trusted_hosts', ['localhost']); $this->_initial_request = Request::$initial; Request::$initial = new Request('/'); } @@ -40,11 +40,11 @@ public function tearDown() public function test_initial() { - $this->setEnvironment(array( + $this->setEnvironment([ 'Request::$initial' => NULL, 'Request::$client_ip' => NULL, 'Request::$user_agent' => NULL, - '_SERVER' => array( + '_SERVER' => [ 'HTTPS' => NULL, 'PATH_INFO' => '/', 'HTTP_REFERER' => 'http://example.com/', @@ -52,10 +52,10 @@ public function test_initial() 'REMOTE_ADDR' => '127.0.0.1', 'REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'ajax-or-something', - ), - '_GET' => array(), - '_POST' => array(), - )); + ], + '_GET' => [], + '_POST' => [], + ]); $request = Request::factory(); @@ -71,9 +71,9 @@ public function test_initial() $this->assertEquals($request->requested_with(), 'ajax-or-something'); - $this->assertEquals($request->query(), array()); + $this->assertEquals($request->query(), []); - $this->assertEquals($request->post(), array()); + $this->assertEquals($request->post(), []); } /** @@ -83,13 +83,9 @@ public function test_initial() */ public function test_disable_external_tests() { - $this->setEnvironment( - array( - 'Request::$initial' => NULL, - ) - ); + $this->setEnvironment(['Request::$initial' => NULL]); - $request = new Request('http://www.google.com/', array(), FALSE); + $request = new Request('http://www.google.com/', [], FALSE); $this->assertEquals(FALSE, $request->is_external()); } @@ -100,10 +96,10 @@ public function test_disable_external_tests() */ public function provider_create() { - return array( - array('foo/bar', 'Request_Client_Internal'), - array('http://google.com', 'Request_Client_External'), - ); + return [ + ['foo/bar', 'Request_Client_Internal'], + ['http://google.com', 'Request_Client_External'], + ]; } /** @@ -129,7 +125,7 @@ public function test_param() $route = new Route('((/(/)))'); $uri = 'kohana_requesttest_dummy/foobar/some_id'; - $request = Request::factory($uri, NULL, TRUE, array($route)); + $request = Request::factory($uri, NULL, TRUE, [$route]); // We need to execute the request before it has matched a route $response = $request->execute(); @@ -151,9 +147,12 @@ public function test_param() $this->assertArrayNotHasKey('uri', $params); $this->assertArrayNotHasKey('route', $params); - $route = new Route('()', array('uri' => '.+')); - $route->defaults(array('controller' => 'kohana_requesttest_dummy', 'action' => 'foobar')); - $request = Request::factory('kohana_requesttest_dummy', NULL, TRUE, array($route)); + $route = new Route('()', ['uri' => '.+']); + $route->defaults([ + 'controller' => 'kohana_requesttest_dummy', + 'action' => 'foobar' + ]); + $request = Request::factory('kohana_requesttest_dummy', NULL, TRUE, [$route]); // We need to execute the request before it has matched a route $response = $request->execute(); @@ -190,7 +189,7 @@ public function test_route() try { $request->execute(); } catch (Exception $e) { - + } $this->assertInstanceOf('Route', $request->route()); @@ -216,7 +215,7 @@ public function test_route_is_not_set_before_execute() */ public function test_accept_type() { - $this->assertEquals(array('*/*' => 1), Request::accept_type()); + $this->assertEquals(['*/*' => 1], Request::accept_type()); } /** @@ -225,11 +224,23 @@ public function test_accept_type() */ public function provider_accept_lang() { - return array( - array('en-us', 1, array('_SERVER' => array('HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5'))), - array('en-us', 1, array('_SERVER' => array('HTTP_ACCEPT_LANGUAGE' => 'en-gb'))), - array('en-us', 1, array('_SERVER' => array('HTTP_ACCEPT_LANGUAGE' => 'sp-sp;q=0.5'))) - ); + return [ + [ + 'en-us', + 1, + ['_SERVER' => ['HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5']] + ], + [ + 'en-us', + 1, + ['_SERVER' => ['HTTP_ACCEPT_LANGUAGE' => 'en-gb']] + ], + [ + 'en-us', + 1, + ['_SERVER' => ['HTTP_ACCEPT_LANGUAGE' => 'sp-sp;q=0.5']] + ], + ]; } /** @@ -257,28 +268,12 @@ public function test_accept_lang($params, $expected, $enviroment) */ public function provider_url() { - return array( - array( - 'foo/bar', - 'http', - 'http://localhost/kohana/foo/bar' - ), - array( - 'foo', - 'http', - 'http://localhost/kohana/foo' - ), - array( - 'http://www.google.com', - 'http', - 'http://www.google.com' - ), - array( - '0', - 'http', - 'http://localhost/kohana/0' - ) - ); + return [ + ['foo/bar', 'http', 'http://localhost/kohana/foo/bar'], + ['foo', 'http', 'http://localhost/kohana/foo'], + ['http://www.google.com', 'http', 'http://www.google.com'], + ['0', 'http', 'http://localhost/kohana/0'], + ]; } /** @@ -297,20 +292,23 @@ public function test_url($uri, $protocol, $expected) $_SERVER['argc'] = 1; } - $this->setEnvironment(array( + $this->setEnvironment([ 'Kohana::$base_url' => '/kohana/', - '_SERVER' => array('HTTP_HOST' => 'localhost', 'argc' => $_SERVER['argc']), + '_SERVER' => [ + 'HTTP_HOST' => 'localhost', + 'argc' => $_SERVER['argc'] + ], 'Kohana::$index_file' => FALSE, - )); + ]); // issue #3967: inject the route so that we don't conflict with the application's default route $route = new Route('((/))'); - $route->defaults(array( + $route->defaults([ 'controller' => 'welcome', 'action' => 'index', - )); + ]); - $this->assertEquals(Request::factory($uri, array(), TRUE, array($route))->url($protocol), $expected); + $this->assertEquals(Request::factory($uri, [], TRUE, [$route])->url($protocol), $expected); } /** @@ -320,20 +318,11 @@ public function test_url($uri, $protocol, $expected) */ public function provider_set_protocol() { - return array( - array( - 'http/1.1', - 'HTTP/1.1', - ), - array( - 'ftp', - 'FTP', - ), - array( - 'hTTp/1.0', - 'HTTP/1.0', - ), - ); + return [ + ['http/1.1', 'HTTP/1.1'], + ['ftp', 'FTP'], + ['hTTp/1.0', 'HTTP/1.0'], + ]; } /** @@ -359,7 +348,7 @@ public function test_set_protocol($protocol, $expected) /** * Provides data for test_post_max_size_exceeded() - * + * * @return array */ public function provider_post_max_size_exceeded() @@ -367,29 +356,20 @@ public function provider_post_max_size_exceeded() // Get the post max size $post_max_size = Num::bytes(ini_get('post_max_size')); - return array( - array( - $post_max_size + 200000, - TRUE - ), - array( - $post_max_size - 20, - FALSE - ), - array( - $post_max_size, - FALSE - ) - ); + return [ + [$post_max_size + 200000, TRUE], + [$post_max_size - 20, FALSE], + [$post_max_size, FALSE], + ]; } /** * Tests the post_max_size_exceeded() method - * + * * @dataProvider provider_post_max_size_exceeded * - * @param int content_length - * @param bool expected + * @param int content_length + * @param bool expected * @return void */ public function test_post_max_size_exceeded($content_length, $expected) @@ -413,48 +393,24 @@ public function provider_uri_only_trimed_on_internal() { // issue #3967: inject the route so that we don't conflict with the application's default route $route = new Route('((/))'); - $route->defaults(array( + $route->defaults([ 'controller' => 'welcome', 'action' => 'index', - )); + ]); $old_request = Request::$initial; - Request::$initial = new Request(TRUE, array(), TRUE, array($route)); - - $result = array( - array( - new Request('http://www.google.com'), - 'http://www.google.com' - ), - array( - new Request('http://www.google.com/'), - 'http://www.google.com/' - ), - array( - new Request('foo/bar/'), - 'foo/bar' - ), - array( - new Request('foo/bar'), - 'foo/bar' - ), - array( - new Request('/0'), - '0' - ), - array( - new Request('0'), - '0' - ), - array( - new Request('/'), - '/' - ), - array( - new Request(''), - '/' - ) - ); + Request::$initial = new Request(TRUE, [], TRUE, [$route]); + + $result = [ + [new Request('http://www.google.com'), 'http://www.google.com'], + [new Request('http://www.google.com/'), 'http://www.google.com/'], + [new Request('foo/bar/'), 'foo/bar'], + [new Request('foo/bar'), 'foo/bar'], + [new Request('/0'), '0'], + [new Request('0'), '0'], + [new Request('/'), '/'], + [new Request(''), '/'], + ]; Request::$initial = $old_request; return $result; @@ -463,7 +419,7 @@ public function provider_uri_only_trimed_on_internal() /** * Tests that the uri supplied to Request is only trimed * for internal requests. - * + * * @dataProvider provider_uri_only_trimed_on_internal * * @return void @@ -480,20 +436,20 @@ public function test_uri_only_trimed_on_internal(Request $request, $expected) */ public function provider_options_set_to_external_client() { - $provider = array( - array( - array( + $provider = [ + [ + [ CURLOPT_PROXYPORT => 8080, CURLOPT_PROXYTYPE => CURLPROXY_HTTP, CURLOPT_VERBOSE => TRUE - ), - array( + ], + [ CURLOPT_PROXYPORT => 8080, CURLOPT_PROXYTYPE => CURLPROXY_HTTP, CURLOPT_VERBOSE => TRUE - ) - ) - ); + ] + ], + ]; return $provider; } @@ -503,17 +459,17 @@ public function provider_options_set_to_external_client() * can be set to the external client (for cURL and PECL_HTTP) * * @dataProvider provider_options_set_to_external_client - * - * @param array settings - * @param array expected + * + * @param array settings + * @param array expected * @return void */ public function test_options_set_to_external_client($settings, $expected) { - $request_client = Request_Client_External::factory(array(), 'Request_Client_Curl'); + $request_client = Request_Client_External::factory([], 'Request_Client_Curl'); // Test for empty array - $this->assertSame(array(), $request_client->options()); + $this->assertSame([], $request_client->options()); // Test that set works as expected $this->assertSame($request_client->options($settings), $request_client); @@ -533,26 +489,25 @@ public function provider_headers_get() { $x_powered_by = 'Kohana Unit Test'; $content_type = 'application/x-www-form-urlencoded'; - $request = new Request('foo/bar', array(), TRUE, array()); + $request = new Request('foo/bar', [], TRUE, []); - return array( - array( - $request->headers(array( + return [ + [ + $request->headers([ 'x-powered-by' => $x_powered_by, 'content-type' => $content_type - ) - ), - array( + ]), + [ 'x-powered-by' => $x_powered_by, 'content-type' => $content_type - ) - ) - ); + ] + ], + ]; } /** * Tests getting headers from the Request object - * + * * @dataProvider provider_headers_get * * @param Request request to test @@ -573,27 +528,27 @@ public function test_headers_get($request, $headers) */ public function provider_headers_set() { - return array( - array( - array( + return [ + [ + [ 'content-type' => 'application/x-www-form-urlencoded', 'x-test-header' => 'foo' - ), + ], "Content-Type: application/x-www-form-urlencoded\r\nX-Test-Header: foo\r\n\r\n" - ), - array( - array( + ], + [ + [ 'content-type' => 'application/json', 'x-powered-by' => 'kohana' - ), + ], "Content-Type: application/json\r\nX-Powered-By: kohana\r\n\r\n" - ) - ); + ], + ]; } /** * Tests the setting of headers to the request object - * + * * @dataProvider provider_headers_set * * @param array header(s) to set to the request object @@ -602,7 +557,7 @@ public function provider_headers_set() */ public function test_headers_set($headers, $expected) { - $request = new Request(TRUE, array(), TRUE, array()); + $request = new Request(TRUE, [], TRUE, []); $request->headers($headers); $this->assertSame($expected, (string) $request->headers()); } @@ -614,55 +569,46 @@ public function test_headers_set($headers, $expected) */ public function provider_query_parameter_parsing() { - return array( - array( + return [ + [ 'foo/bar', - array( + ['foo' => 'bar', 'sna' => 'fu'], + [ 'foo' => 'bar', 'sna' => 'fu' - ), - array( - 'foo' => 'bar', - 'sna' => 'fu' - ), - ), - array( + ] + ], + [ 'foo/bar?john=wayne&peggy=sue', - array( - 'foo' => 'bar', - 'sna' => 'fu' - ), - array( + ['foo' => 'bar', 'sna' => 'fu'], + [ 'john' => 'wayne', 'peggy' => 'sue', 'foo' => 'bar', 'sna' => 'fu' - ), - ), - array( + ] + ], + [ 'http://host.tld/foo/bar?john=wayne&peggy=sue', - array( - 'foo' => 'bar', - 'sna' => 'fu' - ), - array( + ['foo' => 'bar', 'sna' => 'fu'], + [ 'john' => 'wayne', 'peggy' => 'sue', 'foo' => 'bar', 'sna' => 'fu' - ), - ), - ); + ] + ], + ]; } /** * Tests that query parameters are parsed correctly - * + * * @dataProvider provider_query_parameter_parsing * * @param string url - * @param array query - * @param array expected + * @param array query + * @param array expected * @return void */ public function test_query_parameter_parsing($url, $query, $expected) @@ -711,28 +657,28 @@ public function provider_client() $internal_client = new Request_Client_Internal; $external_client = new Request_Client_Stream; - return array( - array( + return [ + [ new Request('http://kohanaframework.org'), $internal_client, $internal_client - ), - array( + ], + [ new Request('foo/bar'), $external_client, $external_client - ) - ); + ], + ]; } /** * Tests the getter/setter for request client - * + * * @dataProvider provider_client * - * @param Request $request - * @param Request_Client $client - * @param Request_Client $expected + * @param Request $request + * @param Request_Client $client + * @param Request_Client $expected * @return void */ public function test_client(Request $request, Request_Client $client, Request_Client $expected) @@ -747,10 +693,10 @@ public function test_client(Request $request, Request_Client $client, Request_Cl */ public function test_passes_client_params() { - $request = Request::factory('http://example.com/', array( + $request = Request::factory('http://example.com/', [ 'follow' => TRUE, 'strict_redirect' => FALSE - )); + ]); $client = $request->client(); @@ -766,7 +712,7 @@ public function test_content_length_after_render() $request = Request::factory('https://example.org/post') ->client(new Kohana_RequestTest_Header_Spying_Request_Client_External) ->method(Request::POST) - ->post(array('aaa' => 'bbb')); + ->post(['aaa' => 'bbb']); $request->render(); @@ -786,11 +732,11 @@ public function test_content_length_after_changing_post() $request = Request::factory('https://example.org/post') ->client(new Kohana_RequestTest_Header_Spying_Request_Client_External) ->method(Request::POST) - ->post(array('aaa' => 'bbb')); + ->post(['aaa' => 'bbb']); $request->render(); - $request->post(array('one' => 'one', 'two' => 'two', 'three' => 'three')); + $request->post(['one' => 'one', 'two' => 'two', 'three' => 'three']); $request->execute(); diff --git a/system/tests/kohana/ResponseTest.php b/system/tests/kohana/ResponseTest.php index e90f40a..325f7b9 100644 --- a/system/tests/kohana/ResponseTest.php +++ b/system/tests/kohana/ResponseTest.php @@ -30,10 +30,10 @@ public function provider_body() ->method('__toString') ->will($this->returnValue('foo')); - return array( - array('unit test', 'unit test'), - array($view, 'foo'), - ); + return [ + ['unit test', 'unit test'], + [$view, 'foo'], + ]; } /** @@ -61,11 +61,11 @@ public function test_body($source, $expected) */ public function provider_body_string_zero() { - return array( - array('0', '0'), - array("0", '0'), - array(0, '0') - ); + return [ + ['0', '0'], + ["0", '0'], + [0, '0'], + ]; } /** @@ -92,38 +92,35 @@ public function test_body_string_zero($string, $expected) */ public function provider_cookie_set() { - return array( - array( + return [ + [ 'test1', 'foo', - array( - 'test1' => array( + [ + 'test1' => [ 'value' => 'foo', 'expiration' => Cookie::$expiration - ), - ) - ), - array( - array( + ], + ] + ], + [ + [ 'test2' => 'stfu', - 'test3' => array( - 'value' => 'snafu', - 'expiration' => 123456789 - ) - ), + 'test3' => ['value' => 'snafu', 'expiration' => 123456789] + ], NULL, - array( - 'test2' => array( + [ + 'test2' => [ 'value' => 'stfu', 'expiration' => Cookie::$expiration - ), - 'test3' => array( + ], + 'test3' => [ 'value' => 'snafu', 'expiration' => 123456789 - ) - ) - ) - ); + ] + ] + ], + ]; } /** @@ -161,7 +158,7 @@ public function test_cookie_get() $response = new Response; // Test for empty cookies - $this->assertSame(array(), $response->cookie()); + $this->assertSame([], $response->cookie()); // Test for no specific cookie $this->assertNull($response->cookie('foobar')); diff --git a/system/tests/kohana/RouteTest.php b/system/tests/kohana/RouteTest.php index 7b1cc9a..1080e9c 100644 --- a/system/tests/kohana/RouteTest.php +++ b/system/tests/kohana/RouteTest.php @@ -29,7 +29,9 @@ public function setUp() { parent::setUp(); - Kohana::$config->load('url')->set('trusted_hosts', array('kohanaframework\.org')); + Kohana::$config->load('url')->set('trusted_hosts', [ + 'kohanaframework\.org' + ]); $this->cleanCacheDir(); } @@ -186,8 +188,11 @@ public function test_constructor_returns_if_uri_is_null() $route->__construct(NULL, NULL); $this->assertAttributeSame('', '_uri', $route); - $this->assertAttributeSame(array(), '_regex', $route); - $this->assertAttributeSame(array('action' => 'index', 'host' => FALSE), '_defaults', $route); + $this->assertAttributeSame([], '_regex', $route); + $this->assertAttributeSame([ + 'action' => 'index', + 'host' => FALSE + ], '_defaults', $route); $this->assertAttributeSame(NULL, '_route_regex', $route); } @@ -198,9 +203,9 @@ public function test_constructor_returns_if_uri_is_null() */ public function provider_constructor_only_changes_custom_regex_if_passed() { - return array( - array('/', '/'), - ); + return [ + ['/', '/'], + ]; } /** @@ -216,13 +221,13 @@ public function provider_constructor_only_changes_custom_regex_if_passed() */ public function test_constructor_only_changes_custom_regex_if_passed($uri, $uri2) { - $route = new Route($uri, array()); + $route = new Route($uri, []); - $this->assertAttributeSame(array(), '_regex', $route); + $this->assertAttributeSame([], '_regex', $route); $route = new Route($uri2, NULL); - $this->assertAttributeSame(array(), '_regex', $route); + $this->assertAttributeSame([], '_regex', $route); } /** @@ -235,7 +240,7 @@ public function test_constructor_only_changes_custom_regex_if_passed($uri, $uri2 */ public function test_route_uses_custom_regex_passed_to_constructor() { - $regex = array('id' => '[0-9]{1,2}'); + $regex = ['id' => '[0-9]{1,2}']; $route = new Route('(/(/))', $regex); @@ -252,9 +257,12 @@ public function test_route_uses_custom_regex_passed_to_constructor() */ public function provider_matches_returns_false_on_failure() { - return array( - array('projects/(/((/(/))))', 'apple/pie'), - ); + return [ + [ + 'projects/(/((/(/))))', + 'apple/pie' + ], + ]; } /** @@ -282,14 +290,14 @@ public function test_matches_returns_false_on_failure($uri, $match) */ public function provider_matches_returns_array_of_parameters_on_successful_match() { - return array( - array( + return [ + [ '((/(/)))', 'welcome/index', 'Welcome', 'index', - ), - ); + ], + ]; } /** @@ -326,36 +334,28 @@ public function test_matches_returns_array_of_parameters_on_successful_match($ur */ public function provider_defaults_are_used_if_params_arent_specified() { - return array( - array( + return [ + [ '(/(/))', NULL, - array('controller' => 'Welcome', 'action' => 'index'), + ['controller' => 'Welcome', 'action' => 'index'], 'Welcome', 'index', 'unit/test/1', - array( - 'controller' => 'unit', - 'action' => 'test', - 'id' => '1' - ), - 'Welcome', - ), - array( + ['controller' => 'unit', 'action' => 'test', 'id' => '1'], + 'Welcome' + ], + [ '((/(/)))', NULL, - array('controller' => 'welcome', 'action' => 'index'), + ['controller' => 'welcome', 'action' => 'index'], 'Welcome', 'index', 'unit/test/1', - array( - 'controller' => 'unit', - 'action' => 'test', - 'id' => '1' - ), - '', - ), - ); + ['controller' => 'unit', 'action' => 'test', 'id' => '1'], + '' + ], + ]; } /** @@ -397,81 +397,81 @@ public function test_defaults_are_used_if_params_arent_specified($uri, $regex, $ */ public function provider_optional_groups_containing_specified_params() { - return array( + return [ /** * Specifying this should cause controller and action to show up * refs #4113 */ - array( + [ '((/(/)))', - array('controller' => 'welcome', 'action' => 'index'), - array('id' => '1'), - 'welcome/index/1', - ), - array( + ['controller' => 'welcome', 'action' => 'index'], + ['id' => '1'], + 'welcome/index/1' + ], + [ '(/(/))', - array('controller' => 'welcome', 'action' => 'index'), - array('action' => 'foo'), - 'welcome/foo', - ), - array( + ['controller' => 'welcome', 'action' => 'index'], + ['action' => 'foo'], + 'welcome/foo' + ], + [ '(/(/))', - array('controller' => 'welcome', 'action' => 'index'), - array('action' => 'index'), - 'welcome', - ), + ['controller' => 'welcome', 'action' => 'index'], + ['action' => 'index'], + 'welcome' + ], /** * refs #4630 */ - array( + [ 'api(/)/const(/)(/)', - array('version' => 1), + ['version' => 1], NULL, - 'api/const', - ), - array( + 'api/const' + ], + [ 'api(/)/const(/)(/)', - array('version' => 1), - array('version' => 9), - 'api/9/const', - ), - array( + ['version' => 1], + ['version' => 9], + 'api/9/const' + ], + [ 'api(/)/const(/)(/)', - array('version' => 1), - array('id' => 2), - 'api/const/2', - ), - array( + ['version' => 1], + ['id' => 2], + 'api/const/2' + ], + [ 'api(/)/const(/)(/)', - array('version' => 1), - array('custom' => 'x'), - 'api/const/x', - ), - array( + ['version' => 1], + ['custom' => 'x'], + 'api/const/x' + ], + [ '((/(/)(/)))', - array('controller' => 'test', 'action' => 'index', 'type' => 'html'), - array('type' => 'json'), - 'test/index/json', - ), - array( + ['controller' => 'test', 'action' => 'index', 'type' => 'html'], + ['type' => 'json'], + 'test/index/json' + ], + [ '((/(/)(/)))', - array('controller' => 'test', 'action' => 'index', 'type' => 'html'), - array('id' => 123), - 'test/index/123', - ), - array( + ['controller' => 'test', 'action' => 'index', 'type' => 'html'], + ['id' => 123], + 'test/index/123' + ], + [ '((/(/)(/)))', - array('controller' => 'test', 'action' => 'index', 'type' => 'html'), - array('id' => 123, 'type' => 'html'), - 'test/index/123', - ), - array( + ['controller' => 'test', 'action' => 'index', 'type' => 'html'], + ['id' => 123, 'type' => 'html'], + 'test/index/123' + ], + [ '((/(/)(/)))', - array('controller' => 'test', 'action' => 'index', 'type' => 'html'), - array('id' => 123, 'type' => 'json'), - 'test/index/123/json', - ), - ); + ['controller' => 'test', 'action' => 'index', 'type' => 'html'], + ['id' => 123, 'type' => 'json'], + 'test/index/123/json' + ], + ]; } /** @@ -503,13 +503,13 @@ public function test_optional_groups_containing_specified_params($uri, $defaults public function test_defaults_are_not_used_if_param_is_identical() { $route = new Route('((/(/)))'); - $route->defaults(array( + $route->defaults([ 'controller' => 'welcome', 'action' => 'index' - )); + ]); - $this->assertSame('', $route->uri(array('controller' => 'welcome'))); - $this->assertSame('welcome2', $route->uri(array('controller' => 'welcome2'))); + $this->assertSame('', $route->uri(['controller' => 'welcome'])); + $this->assertSame('welcome2', $route->uri(['controller' => 'welcome2'])); } /** @@ -519,13 +519,13 @@ public function test_defaults_are_not_used_if_param_is_identical() */ public function provider_required_parameters_are_needed() { - return array( - array( + return [ + [ 'admin(/(/(/)))', 'admin', - 'admin/users/add', - ), - ); + 'admin/users/add' + ], + ]; } /** @@ -570,14 +570,14 @@ public function test_required_parameters_are_needed($uri, $matches_route1, $matc */ public function provider_reverse_routing_returns_routes_uri_if_route_is_static() { - return array( - array( + return [ + [ 'info/about_us', NULL, 'info/about_us', - array('some' => 'random', 'params' => 'to confuse'), - ), - ); + ['some' => 'random', 'params' => 'to confuse'] + ], + ]; } /** @@ -605,22 +605,22 @@ public function test_reverse_routing_returns_routes_uri_if_route_is_static($uri, */ public function provider_uri_throws_exception_if_required_params_are_missing() { - return array( - array( + return [ + [ '(/ 'awesome-action'), - ), + ['action' => 'awesome-action'] + ], /** * Optional params are required when they lead to a specified param * refs #4113 */ - array( + [ '((/))', NULL, - array('action' => 'awesome-action'), - ), - ); + ['action' => 'awesome-action'] + ], + ]; } /** @@ -648,23 +648,16 @@ public function test_uri_throws_exception_if_required_params_are_missing($uri, $ */ public function provider_uri_fills_required_uri_segments_from_params() { - return array( - array( + return [ + [ '/(/)', NULL, 'users/edit', - array( - 'controller' => 'users', - 'action' => 'edit', - ), + ['controller' => 'users', 'action' => 'edit'], 'users/edit/god', - array( - 'controller' => 'users', - 'action' => 'edit', - 'id' => 'god', - ), - ), - ); + ['controller' => 'users', 'action' => 'edit', 'id' => 'god'] + ], + ]; } /** @@ -698,11 +691,20 @@ public function test_uri_fills_required_uri_segments_from_params($uri, $regex, $ */ public function provider_composing_url_from_route() { - return array( - array('/'), - array('/news/view/42', array('controller' => 'news', 'action' => 'view', 'id' => 42)), - array('http://kohanaframework.org/news', array('controller' => 'news'), 'http') - ); + return [ + [ + '/' + ], + [ + '/news/view/42', + ['controller' => 'news', 'action' => 'view', 'id' => 42] + ], + [ + 'http://kohanaframework.org/news', + ['controller' => 'news'], + 'http' + ], + ]; } /** @@ -719,16 +721,13 @@ public function provider_composing_url_from_route() public function test_composing_url_from_route($expected, $params = NULL, $protocol = NULL) { Route::set('foobar', '((/(/)))') - ->defaults(array( - 'controller' => 'welcome', - ) - ); + ->defaults(['controller' => 'welcome']); - $this->setEnvironment(array( - '_SERVER' => array('HTTP_HOST' => 'kohanaframework.org'), + $this->setEnvironment([ + '_SERVER' => ['HTTP_HOST' => 'kohanaframework.org'], 'Kohana::$base_url' => '/', 'Kohana::$index_file' => '', - )); + ]); $this->assertSame($expected, Route::url('foobar', $params, $protocol)); } @@ -743,12 +742,10 @@ public function test_composing_url_from_route($expected, $params = NULL, $protoc */ public function test_compile_uses_custom_regex_if_specificed() { - $compiled = Route::compile( - '(/(/))', array( + $compiled = Route::compile('(/(/))', [ 'controller' => '[a-z]+', 'id' => '\d+', - ) - ); + ]); $this->assertSame('#^(?P[a-z]+)(?:/(?P[^/.,;?\n]++)(?:/(?P\d+))?)?$#uD', $compiled); } @@ -761,20 +758,18 @@ public function test_is_external_route_from_host() { // Setup local route Route::set('internal', 'local/test/route') - ->defaults(array( + ->defaults([ 'controller' => 'foo', 'action' => 'bar' - ) - ); + ]); // Setup external route Route::set('external', 'local/test/route') - ->defaults(array( + ->defaults([ 'controller' => 'foo', 'action' => 'bar', 'host' => 'http://kohanaframework.org' - ) - ); + ]); // Test internal route $this->assertFalse(Route::get('internal')->is_external()); @@ -790,34 +785,34 @@ public function test_is_external_route_from_host() */ public function provider_external_route_includes_params_in_uri() { - return array( - array( + return [ + [ '/', - array( + [ 'controller' => 'foo', 'action' => 'bar', 'host' => 'kohanaframework.org' - ), + ], 'http://kohanaframework.org/foo/bar' - ), - array( + ], + [ '/', - array( + [ 'controller' => 'foo', 'action' => 'bar', 'host' => 'http://kohanaframework.org' - ), + ], 'http://kohanaframework.org/foo/bar' - ), - array( + ], + [ 'foo/bar', - array( + [ 'controller' => 'foo', 'host' => 'http://kohanaframework.org' - ), + ], 'http://kohanaframework.org/foo/bar' - ), - ); + ], + ]; } /** @@ -840,31 +835,22 @@ public function test_external_route_includes_params_in_uri($route, $defaults, $e */ public function provider_route_filter_modify_params() { - return array( - array( + return [ + [ '/', - array( - 'controller' => 'Test', - 'action' => 'same', - ), - array('Route_Holder', 'route_filter_modify_params_array'), + ['controller' => 'Test', 'action' => 'same'], + ['Route_Holder', 'route_filter_modify_params_array'], 'test/different', - array( - 'controller' => 'Test', - 'action' => 'modified', - ), - ), - array( + ['controller' => 'Test', 'action' => 'modified'] + ], + [ '/', - array( - 'controller' => 'test', - 'action' => 'same', - ), - array('Route_Holder', 'route_filter_modify_params_false'), + ['controller' => 'test', 'action' => 'same'], + ['Route_Holder', 'route_filter_modify_params_false'], 'test/fail', - FALSE, - ), - ); + FALSE + ], + ]; } /** @@ -892,19 +878,16 @@ public function test_route_filter_modify_params($route, $defaults, $filter, $uri */ public function provider_route_uri_encode_parameters() { - return array( - array( + return [ + [ 'article', 'blog/article/', - array( - 'controller' => 'home', - 'action' => 'index' - ), + ['controller' => 'home', 'action' => 'index'], 'article_name', 'Article name with special chars \\ ##', 'blog/article/Article%20name%20with%20special%20chars%20\\%20%23%23' - ) - ); + ], + ]; } /** @@ -919,7 +902,7 @@ public function test_route_uri_encode_parameters($name, $uri_callback, $defaults { Route::set($name, $uri_callback)->defaults($defaults); - $get_route_uri = Route::get($name)->uri(array($uri_key => $uri_value)); + $get_route_uri = Route::get($name)->uri([$uri_key => $uri_value]); $this->assertSame($expected, $get_route_uri); } diff --git a/system/tests/kohana/SecurityTest.php b/system/tests/kohana/SecurityTest.php index ff7d3d4..74a3c97 100644 --- a/system/tests/kohana/SecurityTest.php +++ b/system/tests/kohana/SecurityTest.php @@ -21,9 +21,9 @@ class Kohana_SecurityTest extends Unittest_TestCase */ public function provider_encode_php_tags() { - return array( - array("<?php echo 'helloo'; ?>", ""), - ); + return [ + ["<?php echo 'helloo'; ?>", ""], + ]; } /** @@ -45,9 +45,9 @@ public function test_encode_php_tags($expected, $input) */ public function provider_strip_image_tags() { - return array( - array('foo', ''), - ); + return [ + ['foo', ''], + ]; } /** @@ -69,10 +69,13 @@ public function test_strip_image_tags($expected, $input) */ public function provider_csrf_token() { - $array = array(); + $array = []; for ($i = 0; $i <= 4; $i++) { Security::$token_name = 'token_' . $i; - $array[] = array(Security::token(TRUE), Security::check(Security::token(FALSE)), $i); + $array[] = [ + Security::token(TRUE), + Security::check(Security::token(FALSE)), $i + ]; } return $array; } diff --git a/system/tests/kohana/SessionTest.php b/system/tests/kohana/SessionTest.php index 3b6324d..818ad16 100644 --- a/system/tests/kohana/SessionTest.php +++ b/system/tests/kohana/SessionTest.php @@ -24,10 +24,10 @@ class Kohana_SessionTest extends Unittest_TestCase * @return Session */ // @codingStandardsIgnoreStart - public function getMockSession(array $config = array()) + public function getMockSession(array $config = []) // @codingStandardsIgnoreEnd { - return $this->getMockForAbstractClass('Session', array($config)); + return $this->getMockForAbstractClass('Session', [$config]); } /** @@ -39,33 +39,33 @@ public function getMockSession(array $config = array()) */ public function provider_constructor_uses_settings_from_config_and_casts() { - return array( - // array(expected, input) + return [ + // [expected, input] // data set 0 - array( - array( + [ + [ 'name' => 'awesomeness', 'lifetime' => 1231456421, 'encrypted' => FALSE - ), - array( + ], + [ 'name' => 'awesomeness', 'lifetime' => '1231456421', - 'encrypted' => FALSE, - ), - ), + 'encrypted' => FALSE + ] + ], // data set 1 - array( - array( + [ + [ 'name' => '123', - 'encrypted' => 'default', - ), - array( + 'encrypted' => 'default' + ], + [ 'name' => 123, - 'encrypted' => TRUE, - ), - ), - ); + 'encrypted' => TRUE + ] + ], + ]; } /** @@ -78,7 +78,7 @@ public function provider_constructor_uses_settings_from_config_and_casts() */ public function test_constructor_uses_settings_from_config_and_casts($expected, $config) { - $session = $this->getMockForAbstractClass('Session', array($config)); + $session = $this->getMockForAbstractClass('Session', [$config]); foreach ($expected as $var => $value) { $this->assertAttributeSame($value, '_' . $var, $session); @@ -95,13 +95,13 @@ public function test_constructor_uses_settings_from_config_and_casts($expected, */ public function test_constructor_loads_session_with_session_id() { - $config = array(); + $config = []; $session_id = 'lolums'; // Don't auto-call constructor, we need to setup the mock first $session = $this->getMockBuilder('Session') ->disableOriginalConstructor() - ->setMethods(array('read')) + ->setMethods(['read']) ->getMockForAbstractClass(); $session @@ -145,7 +145,7 @@ public function test_initially_session_has_no_data() { $session = $this->getMockSession(); - $this->assertAttributeSame(array(), '_data', $session); + $this->assertAttributeSame([], '_data', $session); } /** @@ -195,11 +195,11 @@ public function test_default_session_is_not_classed_as_destroyed() */ public function provider_get_returns_default_if_var_dnx() { - return array( - array('something_crazy', FALSE), - array('a_true', TRUE), - array('an_int', 158163158), - ); + return [ + ['something_crazy', FALSE], + ['a_true', TRUE], + ['an_int', 158163158], + ]; } /** @@ -286,13 +286,13 @@ public function test_set_adds_and_modifies_to_session_data() $this->assertSame($session, $session->set('pork', 'pie')); $this->assertAttributeSame( - array('pork' => 'pie'), '_data', $session + ['pork' => 'pie'], '_data', $session ); $session->set('pork', 'delicious'); $this->assertAttributeSame( - array('pork' => 'delicious'), '_data', $session + ['pork' => 'delicious'], '_data', $session ); } @@ -309,12 +309,12 @@ public function test_delete_removes_select_session_data() // Bit of a hack for mass-loading session data $data = & $session->as_array(); - $data += array( + $data += [ 'a' => 'A', 'b' => 'B', 'c' => 'C', 'easy' => '123' - ); + ]; // Make a copy of $data for testing purposes $copy = $data; @@ -344,25 +344,25 @@ public function test_delete_removes_select_session_data() */ public function provider_read_loads_session_data() { - return array( + return [ // If driver returns array then just load it up - array( - array(), + [ + [], 'wacka_wacka', - array() - ), - array( - array('the it' => 'crowd'), + [] + ], + [ + ['the it' => 'crowd'], 'the_it_crowd', - array('the it' => 'crowd'), - ), + ['the it' => 'crowd'], + ], // If it's a string an encrpytion is disabled (by default) base64decode and unserialize - array( - array('dead' => 'arrival'), + [ + ['dead' => 'arrival'], 'lolums', 'YToxOntzOjQ6ImRlYWQiO3M6NzoiYXJyaXZhbCI7fQ==' - ), - ); + ], + ]; } /** @@ -377,7 +377,7 @@ public function provider_read_loads_session_data() * @dataProvider provider_read_loads_session_data * @covers Session::read */ - public function test_read_loads_session_data($expected_data, $session_id, $driver_data, array $config = array()) + public function test_read_loads_session_data($expected_data, $session_id, $driver_data, array $config = []) { $session = $this->getMockSession($config); @@ -433,7 +433,7 @@ public function test_destroy_deletes_data_if_driver_destroys_session() $this->assertTrue($session->destroy()); - $this->assertAttributeSame(array(), '_data', $session); + $this->assertAttributeSame([], '_data', $session); } /** @@ -459,7 +459,7 @@ public function test_destroy_only_deletes_data_if_driver_destroys_session() $this->assertFalse($session->destroy()); $this->assertAttributeSame( - array('asd' => 'dsa', 'dog' => 'god'), '_data', $session + ['asd' => 'dsa', 'dog' => 'god'], '_data', $session ); } @@ -482,7 +482,7 @@ public function test_get_once_gets_once_or_returns_default() // Now test that it actually removes the value $this->assertSame('bar', $session->get_once('foo')); - $this->assertAttributeSame(array(), '_data', $session); + $this->assertAttributeSame([], '_data', $session); $this->assertSame('maybe', $session->get_once('foo', 'maybe')); } diff --git a/system/tests/kohana/TextTest.php b/system/tests/kohana/TextTest.php index a293114..7e7a000 100644 --- a/system/tests/kohana/TextTest.php +++ b/system/tests/kohana/TextTest.php @@ -44,16 +44,10 @@ function test_auto_para_returns_empty_string_on_empty_input() */ function provider_auto_para_does_not_enclose_html_tags_in_paragraphs() { - return array( - array( - array('div'), - '
Pick a plum of peppers
', - ), - array( - array('div'), - '
Tangas
', - ), - ); + return [ + [['div'], '
Pick a plum of peppers
'], + [['div'], '
Tangas
'], + ]; } /** @@ -70,7 +64,7 @@ function test_auto_para_does_not_enclose_html_tags_in_paragraphs(array $tags, $t foreach ($tags as $tag) { $this->assertNotTag( - array('tag' => $tag, 'ancestor' => array('tag' => 'p')), $output + ['tag' => $tag, 'ancestor' => ['tag' => 'p']], $output ); } } @@ -109,13 +103,12 @@ public function test_auto_para_replaces_multiple_newlines_with_paragraph() */ function provider_limit_words() { - return array - ( - array('', '', 100, NULL), - array('…', 'The rain in spain', -10, NULL), - array('The rain…', 'The rain in spain', 2, NULL), - array('The rain...', 'The rain in spain', 2, '...'), - ); + return [ + ['', '', 100, NULL], + ['…', 'The rain in spain', -10, NULL], + ['The rain…', 'The rain in spain', 2, NULL], + ['The rain...', 'The rain in spain', 2, '...'], + ]; } /** @@ -135,19 +128,72 @@ function test_limit_words($expected, $str, $limit, $end_char) */ function provider_limit_chars() { - return array - ( - array('', '', 100, NULL, FALSE), - array('…', 'BOO!', -42, NULL, FALSE), - array('making php bet…', 'making php better for the sane', 14, NULL, FALSE), - array('Garçon! Un café s.v.p.', 'Garçon! Un café s.v.p.', 50, '__', FALSE), - array('Garçon!__', 'Garçon! Un café s.v.p.', 8, '__', FALSE), + return [ + [ + '', + '', + 100, + NULL, + FALSE + ], + [ + '…', + 'BOO!', + -42, + NULL, + FALSE + ], + [ + 'making php bet…', + 'making php better for the sane', + 14, + NULL, + FALSE + ], + [ + 'Garçon! Un café s.v.p.', + 'Garçon! Un café s.v.p.', + 50, + '__', + FALSE + ], + [ + 'Garçon!__', + 'Garçon! Un café s.v.p.', + 8, + '__', + FALSE + ], // @issue 3238 - array('making php…', 'making php better for the sane', 14, NULL, TRUE), - array('Garçon!__', 'Garçon! Un café s.v.p.', 9, '__', TRUE), - array('Garçon!__', 'Garçon! Un café s.v.p.', 7, '__', TRUE), - array('__', 'Garçon! Un café s.v.p.', 5, '__', TRUE), - ); + [ + 'making php…', + 'making php better for the sane', + 14, + NULL, + TRUE + ], + [ + 'Garçon!__', + 'Garçon! Un café s.v.p.', + 9, + '__', + TRUE + ], + [ + 'Garçon!__', + 'Garçon! Un café s.v.p.', + 7, + '__', + TRUE + ], + [ + '__', + 'Garçon! Un café s.v.p.', + 5, + '__', + TRUE + ], + ]; } /** @@ -168,7 +214,7 @@ function test_limit_chars($expected, $str, $limit, $end_char, $preserve_words) */ function test_alternate_alternates_between_parameters() { - list($val_a, $val_b, $val_c) = array('good', 'bad', 'ugly'); + list($val_a, $val_b, $val_c) = ['good', 'bad', 'ugly']; $this->assertSame('good', Text::alternate($val_a, $val_b, $val_c)); $this->assertSame('bad', Text::alternate($val_a, $val_b, $val_c)); @@ -185,7 +231,7 @@ function test_alternate_alternates_between_parameters() */ function test_alternate_resets_when_called_with_no_params_and_returns_empty_string() { - list($val_a, $val_b, $val_c) = array('yes', 'no', 'maybe'); + list($val_a, $val_b, $val_c) = ['yes', 'no', 'maybe']; $this->assertSame('yes', Text::alternate($val_a, $val_b, $val_c)); @@ -201,10 +247,10 @@ function test_alternate_resets_when_called_with_no_params_and_returns_empty_stri */ public function provider_ucfirst() { - return array( - array('Content-Type', 'content-type', '-'), - array('Բարեւ|Ձեզ', 'բարեւ|ձեզ', '|'), - ); + return [ + ['Content-Type', 'content-type', '-'], + ['Բարեւ|Ձեզ', 'բարեւ|ձեզ', '|'], + ]; } /** @@ -225,11 +271,10 @@ public function test_ucfirst($expected, $string, $delimiter) */ function provider_reduce_slashes() { - return array - ( - array('/', '//'), - array('/google/php/kohana/', '//google/php//kohana//'), - ); + return [ + ['/', '//'], + ['/google/php/kohana/', '//google/php//kohana//'], + ]; } /** @@ -250,16 +295,38 @@ function test_reduce_slashes($expected, $str) */ function provider_censor() { - - return array - ( + return [ // If the replacement is 1 character long it should be repeated for the length of the removed word - array("A donkey is also an ***", 'A donkey is also an ass', array('ass'), '*', TRUE), - array("Cake### isn't nearly as good as kohana###", "CakePHP isn't nearly as good as kohanaphp", array('php'), '#', TRUE), + [ + "A donkey is also an ***", + 'A donkey is also an ass', + ['ass'], + '*', + TRUE + ], + [ + "Cake### isn't nearly as good as kohana###", + "CakePHP isn't nearly as good as kohanaphp", + ['php'], + '#', + TRUE + ], // If it's > 1 then it's just replaced straight out - array("If you're born out of wedlock you're a --expletive--", "If you're born out of wedlock you're a child", array('child'), '--expletive--', TRUE), - array('class', 'class', array('ass'), '*', FALSE), - ); + [ + "If you're born out of wedlock you're a --expletive--", + "If you're born out of wedlock you're a child", + ['child'], + '--expletive--', + TRUE + ], + [ + 'class', + 'class', + ['ass'], + '*', + FALSE + ], + ]; } /** @@ -280,17 +347,17 @@ function test_censor($expected, $str, $badwords, $replacement, $replace_partial_ */ function provider_random() { - return array( - array('alnum', 8), - array('alpha', 10), - array('hexdec', 20), - array('nozero', 5), - array('numeric', 14), - array('distinct', 12), - array('aeiou', 4), - array('‹¡›«¿»', 8), // UTF8 characters - array(NULL, 8), // Issue #3256 - ); + return [ + ['alnum', 8], + ['alpha', 10], + ['hexdec', 20], + ['nozero', 5], + ['numeric', 14], + ['distinct', 12], + ['aeiou', 4], + ['‹¡›«¿»', 8], // UTF8 characters + [NULL, 8], // Issue #3256 + ]; } /** @@ -345,11 +412,10 @@ function test_random($type, $length) */ function provider_similar() { - return array - ( + return [ // TODO: add some more cases - array('foo', array('foobar', 'food', 'fooberry')), - ); + ['foo', ['foobar', 'food', 'fooberry']], + ]; } /** @@ -371,16 +437,15 @@ function test_similar($expected, $words) */ public function provider_bytes() { - return array - ( + return [ // TODO: cover the other units - array('256.00 B', 256, NULL, NULL, TRUE), - array('1.02 kB', 1024, NULL, NULL, TRUE), + ['256.00 B', 256, NULL, NULL, TRUE], + ['1.02 kB', 1024, NULL, NULL, TRUE], // In case you need to know the size of a floppy disk in petabytes - array('0.00147 GB', 1.44 * 1000 * 1024, 'GB', '%01.5f %s', TRUE), + ['0.00147 GB', 1.44 * 1000 * 1024, 'GB', '%01.5f %s', TRUE], // SI is the standard, but lets deviate slightly - array('1.00 MiB', 1024 * 1024, 'MiB', NULL, FALSE), - ); + ['1.00 MiB', 1024 * 1024, 'MiB', NULL, FALSE], + ]; } /** @@ -401,93 +466,92 @@ function test_bytes($expected, $bytes, $force_unit, $format, $si) */ function provider_widont() { - return array - ( + return [ // A very simple widont test - array( + [ 'A very simple test', - 'A very simple test', - ), + 'A very simple test' + ], // Single word items shouldn't be changed - array( + [ 'Test', - 'Test', - ), + 'Test' + ], // Single word after single space shouldn't be changed either - array( - ' Test', + [ ' Test', - ), + ' Test' + ], // Single word with HTML all around - array( + [ '
  • Test

    • ', - '
      • Test

        • ', - ), + '
          • Test

            • ' + ], // Single word after single space with HTML all around - array( - '
              • Test

                • ', + [ '
                  • Test

                    • ', - ), + '
                      • Test

                        • ' + ], // Widont with more than one paragraph - array( + [ '

                          In a couple of paragraphs

                          paragraph two

                          ', - '

                          In a couple of paragraphs

                          paragraph two

                          ', - ), + '

                          In a couple of paragraphs

                          paragraph two

                          ' + ], // a link inside a heading - array( + [ '

                          In a link inside a heading

                          ', - '

                          In a link inside a heading

                          ', - ), + '

                          In a link inside a heading

                          ' + ], // a link followed by text - array( + [ '

                          In a link followed by other text

                          ', - '

                          In a link followed by other text

                          ', - ), + '

                          In a link followed by other text

                          ' + ], // empty html, with no text inside - array( + [ '

                          ', - '

                          ', - ), + '

                          ' + ], // apparently, we don't love DIVs - array( - '
                          Divs get no love!
                          ', + [ '
                          Divs get no love!
                          ', - ), + '
                          Divs get no love!
                          ' + ], // we don't love PREs, either - array( + [ '
                          Neither do PREs
                          ', - '
                          Neither do PREs
                          ', - ), + '
                          Neither do PREs
                          ' + ], // but we love DIVs with paragraphs - array( + [ '

                          But divs with paragraphs do!

                          ', - '

                          But divs with paragraphs do!

                          ', - ), - array( + '

                          But divs with paragraphs do!

                          ' + ], + [ 'No gain, no pain', - 'No gain, no pain', - ), - array( - "spaces?what'rethey?", + 'No gain, no pain' + ], + [ "spaces?what'rethey?", - ), + "spaces?what'rethey?" + ], /* * // @issue 3499, with HTML at the end - * array( + * [ * 'with HTML at the end  Kohana', - * 'with HTML at the end Kohana', - * ), + * 'with HTML at the end Kohana' + * ], * // @issue 3499, with HTML with attributes at the end - * array( + * [ * 'with HTML at the end: Kohana', - * 'with HTML at the end: Kohana', - * ), + * 'with HTML at the end: Kohana' + * ], */ - array( + [ '', - '', - ), - ); + '' + ], + ]; } /** @@ -531,16 +595,16 @@ function test_auto_link_emails_respects_word_boundaries() */ public function provider_number() { - return array( - array('one', 1), - array('twenty-three', 23), - array('fourty-two', 42), - array('five million, six hundred and thirty-two', 5000632), - array('five million, six hundred and thirty', 5000630), - array('nine hundred million', 900000000), - array('thirty-seven thousand', 37000), - array('one thousand and twenty-four', 1024), - ); + return [ + ['one', 1], + ['twenty-three', 23], + ['fourty-two', 42], + ['five million, six hundred and thirty-two', 5000632], + ['five million, six hundred and thirty', 5000630], + ['nine hundred million', 900000000], + ['thirty-seven thousand', 37000], + ['one thousand and twenty-four', 1024], + ]; } /** @@ -561,79 +625,79 @@ public function test_number($expected, $number) */ public function provider_auto_link_urls() { - return array( + return [ // First we try with the really obvious url - array( + [ 'Some random text http://www.google.com', - 'Some random text http://www.google.com', - ), + 'Some random text http://www.google.com' + ], // Then we try with varying urls - array( + [ 'Some random www.google.com', - 'Some random www.google.com', - ), - array( - 'Some random google.com', + 'Some random www.google.com' + ], + [ 'Some random google.com', - ), + 'Some random google.com' + ], // Check that it doesn't link urls in a href - array( + [ 'Look at me Awesome stuff', - 'Look at me Awesome stuff', - ), - array( - 'Look at me http://www.google.com', + 'Look at me Awesome stuff' + ], + [ 'Look at me http://www.google.com', - ), + 'Look at me http://www.google.com' + ], // Punctuation at the end of the URL - array( + [ 'Wow http://www.google.com!', - 'Wow http://www.google.com!', - ), - array( + 'Wow http://www.google.com!' + ], + [ 'Zomg www.google.com!', 'Zomg www.google.com!', - ), - array( + ], + [ 'Well this, www.google.com, is cool', - 'Well this, www.google.com, is cool', - ), + 'Well this, www.google.com, is cool' + ], // @issue 3190 - array( + [ 'www.google.com', - 'www.google.com', - ), - array( + 'www.google.com' + ], + [ 'www.google.com http://www.google.com/', - 'www.google.com http://www.google.com/', - ), + 'www.google.com http://www.google.com/' + ], // @issue 3436 - array( + [ 'http://www.google.com/', - 'http://www.google.com/', - ), + 'http://www.google.com/' + ], // @issue 4208, URLs with a path - array( + [ 'Foobar www.google.com/analytics cake', - 'Foobar www.google.com/analytics cake', - ), - array( + 'Foobar www.google.com/analytics cake' + ], + [ 'Look at this www.google.com/analytics!', - 'Look at this www.google.com/analytics!', - ), - array( + 'Look at this www.google.com/analytics!' + ], + [ 'Path http://www.google.com/analytics works?', - 'Path http://www.google.com/analytics works?', - ), - array( + 'Path http://www.google.com/analytics works?' + ], + [ 'Path http://www.google.com/analytics', - 'Path http://www.google.com/analytics', - ), - array( + 'Path http://www.google.com/analytics' + ], + [ 'Path www.google.com/analytics', - 'Path www.google.com/analytics', - ), - ); + 'Path www.google.com/analytics' + ], + ]; } /** @@ -654,22 +718,22 @@ public function test_auto_link_urls($expected, $text) */ public function provider_auto_link_emails() { - return array( + return [ // @issue 3162 - array( + [ 'info@test.com', - 'info@test.com', - ), - array( + 'info@test.com' + ], + [ 'info@test.com', - 'info@test.com', - ), + 'info@test.com' + ], // @issue 3189 - array( + [ 'email@address.com email@address.com', - 'email@address.com email@address.com', - ), - ); + 'email@address.com email@address.com' + ], + ]; } /** @@ -691,17 +755,17 @@ public function test_auto_link_emails($expected, $text) */ public function provider_auto_link() { - return array( - array( + return [ + [ 'Hi there, my site is kohanaframework.org and you can email me at nobody@kohanaframework.org', - array('kohanaframework.org'), - ), - array( + ['kohanaframework.org'], + ], + [ 'Hi my.domain.com@domain.com you came from', FALSE, - array('my.domain.com@domain.com'), - ), - ); + ['my.domain.com@domain.com'] + ], + ]; } /** @@ -710,7 +774,7 @@ public function provider_auto_link() * @test * @dataProvider provider_auto_link */ - public function test_auto_link($text, $urls = array(), $emails = array()) + public function test_auto_link($text, $urls = [], $emails = []) { $linked_text = Text::auto_link($text); @@ -730,40 +794,40 @@ public function test_auto_link($text, $urls = array(), $emails = array()) public function provider_user_agents() { - return array( - array( + return [ + [ "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36", - array( + [ 'browser' => 'Chrome', 'version' => '37.0.2049.0', 'platform' => "Windows 8.1" - ) - ), - array( + ] + ], + [ "Mozilla/5.0 (Macintosh; U; Mac OS X 10_6_1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5", - array( + [ 'browser' => 'Chrome', 'version' => '530.5', 'platform' => "Mac OS X" - ) - ), - array( + ] + ], + [ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2", - array( + [ 'browser' => 'Safari', 'version' => '534.57.2', 'platform' => 'Mac OS X' - ) - ), - array( + ] + ], + [ "Lynx/2.8.8dev.3 libwww-FM/2.14 SSL-MM/1.4.1", - array( + [ 'browser' => 'Lynx', 'version' => '2.8.8dev.3', 'platform' => false - ) - ) - ); + ] + ], + ]; } /** @@ -822,9 +886,11 @@ public function test_user_agent_returns_correct_platform($userAgent, $expectedDa */ public function test_user_agent_accepts_array() { - $agent_info = Text::user_agent( - 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 ' . - '(KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36', array('browser', 'version', 'platform')); + $agent_info = Text::user_agent('Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36', [ + 'browser', + 'version', + 'platform' + ]); $this->assertArrayHasKey('browser', $agent_info); $this->assertArrayHasKey('version', $agent_info); diff --git a/system/tests/kohana/URLTest.php b/system/tests/kohana/URLTest.php index 848c662..34270a4 100644 --- a/system/tests/kohana/URLTest.php +++ b/system/tests/kohana/URLTest.php @@ -26,7 +26,10 @@ public function setUp() // @codingStandardsIgnoreEnd { parent::setUp(); - Kohana::$config->load('url')->set('trusted_hosts', array('example\.com', 'example\.org')); + Kohana::$config->load('url')->set('trusted_hosts', [ + 'example\.com', + 'example\.org' + ]); } /** @@ -34,12 +37,12 @@ public function setUp() * @var array */ // @codingStandardsIgnoreStart - protected $environmentDefault = array( + protected $environmentDefault = [ 'Kohana::$base_url' => '/kohana/', 'Kohana::$index_file' => 'index.php', 'HTTP_HOST' => 'example.com', - '_GET' => array(), - ); + '_GET' => [], + ]; // @codingStandardsIgnoreEnd /** @@ -49,29 +52,102 @@ public function setUp() */ public function provider_base() { - return array( + return [ // $protocol, $index, $expected, $enviroment // Test with different combinations of parameters for max code coverage - array(NULL, FALSE, '/kohana/'), - array('http', FALSE, 'http://example.com/kohana/'), - array(NULL, TRUE, '/kohana/index.php/'), - array(NULL, TRUE, '/kohana/index.php/'), - array('http', TRUE, 'http://example.com/kohana/index.php/'), - array('https', TRUE, 'https://example.com/kohana/index.php/'), - array('ftp', TRUE, 'ftp://example.com/kohana/index.php/'), + [ + NULL, + FALSE, + '/kohana/' + ], + [ + 'http', + FALSE, + 'http://example.com/kohana/' + ], + [ + NULL, + TRUE, + '/kohana/index.php/' + ], + [ + NULL, + TRUE, + '/kohana/index.php/' + ], + [ + 'http', + TRUE, + 'http://example.com/kohana/index.php/' + ], + [ + 'https', + TRUE, + 'https://example.com/kohana/index.php/' + ], + [ + 'ftp', + TRUE, + 'ftp://example.com/kohana/index.php/' + ], // Test for automatic protocol detection, protocol = TRUE - array(TRUE, TRUE, 'cli://example.com/kohana/index.php/', array('HTTPS' => FALSE, 'Request::$initial' => Request::factory('/')->protocol('cli'))), + [ + TRUE, + TRUE, + 'cli://example.com/kohana/index.php/', + [ + 'HTTPS' => FALSE, + 'Request::$initial' => Request::factory('/')->protocol('cli') + ] + ], // Change base url' - array('https', FALSE, 'https://example.com/kohana/', array('Kohana::$base_url' => 'omglol://example.com/kohana/')), + [ + 'https', + FALSE, + 'https://example.com/kohana/', + [ + 'Kohana::$base_url' => 'omglol://example.com/kohana/' + ] + ], // Use port in base url, issue #3307 - array('http', FALSE, 'http://example.com:8080/', array('Kohana::$base_url' => 'example.com:8080/')), + [ + 'http', + FALSE, + 'http://example.com:8080/', + [ + 'Kohana::$base_url' => 'example.com:8080/' + ] + ], // Use protocol from base url if none specified - array(NULL, FALSE, 'http://www.example.com/', array('Kohana::$base_url' => 'http://www.example.com/')), + [ + NULL, + FALSE, + 'http://www.example.com/', + [ + 'Kohana::$base_url' => 'http://www.example.com/' + ] + ], // Use HTTP_HOST before SERVER_NAME - array('http', FALSE, 'http://example.com/kohana/', array('HTTP_HOST' => 'example.com', 'SERVER_NAME' => 'example.org')), + [ + 'http', + FALSE, + 'http://example.com/kohana/', + [ + 'HTTP_HOST' => 'example.com', + 'SERVER_NAME' => 'example.org' + ] + ], // Use SERVER_NAME if HTTP_HOST DNX - array('http', FALSE, 'http://example.org/kohana/', array('HTTP_HOST' => NULL, 'SERVER_NAME' => 'example.org')), - ); + [ + 'http', + FALSE, + 'http://example.org/kohana/', + [ + 'HTTP_HOST' => NULL, + 'SERVER_NAME' => 'example.org' + ] + ], + ]; } /** @@ -84,7 +160,7 @@ public function provider_base() * @param string $expected Expected url * @param array $enviroment Array of enviroment vars to change @see Kohana_URLTest::setEnvironment() */ - public function test_base($protocol, $index, $expected, array $enviroment = array()) + public function test_base($protocol, $index, $expected, array $enviroment = []) { $this->setEnvironment($enviroment); @@ -100,25 +176,89 @@ public function test_base($protocol, $index, $expected, array $enviroment = arra */ public function provider_site() { - return array( - array('', NULL, '/kohana/index.php/'), - array('', 'http', 'http://example.com/kohana/index.php/'), - array('my/site', NULL, '/kohana/index.php/my/site'), - array('my/site', 'http', 'http://example.com/kohana/index.php/my/site'), + return [ + [ + '', + NULL, + '/kohana/index.php/' + ], + [ + '', + 'http', + 'http://example.com/kohana/index.php/' + ], + [ + 'my/site', + NULL, + '/kohana/index.php/my/site' + ], + [ + 'my/site', + 'http', + 'http://example.com/kohana/index.php/my/site' + ], // @ticket #3110 - array('my/site/page:5', NULL, '/kohana/index.php/my/site/page:5'), - array('my/site/page:5', 'http', 'http://example.com/kohana/index.php/my/site/page:5'), - array('my/site?var=asd&kohana=awesome', NULL, '/kohana/index.php/my/site?var=asd&kohana=awesome'), - array('my/site?var=asd&kohana=awesome', 'http', 'http://example.com/kohana/index.php/my/site?var=asd&kohana=awesome'), - array('?kohana=awesome&life=good', NULL, '/kohana/index.php/?kohana=awesome&life=good'), - array('?kohana=awesome&life=good', 'http', 'http://example.com/kohana/index.php/?kohana=awesome&life=good'), - array('?kohana=awesome&life=good#fact', NULL, '/kohana/index.php/?kohana=awesome&life=good#fact'), - array('?kohana=awesome&life=good#fact', 'http', 'http://example.com/kohana/index.php/?kohana=awesome&life=good#fact'), - array('some/long/route/goes/here?kohana=awesome&life=good#fact', NULL, '/kohana/index.php/some/long/route/goes/here?kohana=awesome&life=good#fact'), - array('some/long/route/goes/here?kohana=awesome&life=good#fact', 'http', 'http://example.com/kohana/index.php/some/long/route/goes/here?kohana=awesome&life=good#fact'), - array('/route/goes/here?kohana=awesome&life=good#fact', 'https', 'https://example.com/kohana/index.php/route/goes/here?kohana=awesome&life=good#fact'), - array('/route/goes/here?kohana=awesome&life=good#fact', 'ftp', 'ftp://example.com/kohana/index.php/route/goes/here?kohana=awesome&life=good#fact'), - ); + [ + 'my/site/page:5', + NULL, + '/kohana/index.php/my/site/page:5' + ], + [ + 'my/site/page:5', + 'http', + 'http://example.com/kohana/index.php/my/site/page:5' + ], + [ + 'my/site?var=asd&kohana=awesome', + NULL, + '/kohana/index.php/my/site?var=asd&kohana=awesome' + ], + [ + 'my/site?var=asd&kohana=awesome', + 'http', + 'http://example.com/kohana/index.php/my/site?var=asd&kohana=awesome' + ], + [ + '?kohana=awesome&life=good', + NULL, + '/kohana/index.php/?kohana=awesome&life=good' + ], + [ + '?kohana=awesome&life=good', + 'http', + 'http://example.com/kohana/index.php/?kohana=awesome&life=good' + ], + [ + '?kohana=awesome&life=good#fact', + NULL, + '/kohana/index.php/?kohana=awesome&life=good#fact' + ], + [ + '?kohana=awesome&life=good#fact', + 'http', + 'http://example.com/kohana/index.php/?kohana=awesome&life=good#fact' + ], + [ + 'some/long/route/goes/here?kohana=awesome&life=good#fact', + NULL, + '/kohana/index.php/some/long/route/goes/here?kohana=awesome&life=good#fact' + ], + [ + 'some/long/route/goes/here?kohana=awesome&life=good#fact', + 'http', + 'http://example.com/kohana/index.php/some/long/route/goes/here?kohana=awesome&life=good#fact' + ], + [ + '/route/goes/here?kohana=awesome&life=good#fact', + 'https', + 'https://example.com/kohana/index.php/route/goes/here?kohana=awesome&life=good#fact' + ], + [ + '/route/goes/here?kohana=awesome&life=good#fact', + 'ftp', + 'ftp://example.com/kohana/index.php/route/goes/here?kohana=awesome&life=good#fact' + ], + ]; } /** @@ -131,7 +271,7 @@ public function provider_site() * @param string $expected Expected result * @param array $enviroment Array of enviroment vars to set */ - public function test_site($uri, $protocol, $expected, array $enviroment = array()) + public function test_site($uri, $protocol, $expected, array $enviroment = []) { $this->setEnvironment($enviroment); @@ -148,12 +288,12 @@ public function test_site($uri, $protocol, $expected, array $enviroment = array( */ public function provider_site_url_encode_uri() { - $provider = array( - array('test', 'encode'), - array('test', 'éñçø∂ë∂'), - array('†é߆', 'encode'), - array('†é߆', 'éñçø∂ë∂', 'µåñ¥'), - ); + $provider = [ + ['test', 'encode'], + ['test', 'éñçø∂ë∂'], + ['†é߆', 'encode'], + ['†é߆', 'éñçø∂ë∂', 'µåñ¥'], + ]; foreach ($provider as $i => $params) { // Every non-ASCII character except for forward slash should be encoded... @@ -162,7 +302,7 @@ public function provider_site_url_encode_uri() // ... from a URI that is not encoded $uri = implode('/', $params); - $provider[$i] = array("/kohana/index.php/{$expected}", $uri); + $provider[$i] = ["/kohana/index.php/{$expected}", $uri]; } return $provider; @@ -185,29 +325,78 @@ public function test_site_url_encode_uri($expected, $uri) */ public function provider_title() { - return array( + return [ // Tests that.. // Title is converted to lowercase - array('we-shall-not-be-moved', 'WE SHALL NOT BE MOVED', '-'), + [ + 'we-shall-not-be-moved', + 'WE SHALL NOT BE MOVED', + '-' + ], // Excessive white space is removed and replaced with 1 char - array('thissssss-is-it', 'THISSSSSS IS IT ', '-'), + [ + 'thissssss-is-it', + 'THISSSSSS IS IT ', + '-' + ], // separator is either - (dash) or _ (underscore) & others are converted to underscores - array('some-title', 'some title', '-'), - array('some_title', 'some title', '_'), - array('some!title', 'some title', '!'), - array('some:title', 'some title', ':'), + [ + 'some-title', + 'some title', + '-' + ], + [ + 'some_title', + 'some title', + '_' + ], + [ + 'some!title', + 'some title', + '!' + ], + [ + 'some:title', + 'some title', + ':' + ], // Numbers are preserved - array('99-ways-to-beat-apple', '99 Ways to beat apple', '-'), + [ + '99-ways-to-beat-apple', + '99 Ways to beat apple', + '-' + ], // ... with lots of spaces & caps - array('99_ways_to_beat_apple', '99 ways TO beat APPLE', '_'), - array('99-ways-to-beat-apple', '99 ways TO beat APPLE', '-'), + [ + '99_ways_to_beat_apple', + '99 ways TO beat APPLE', + '_' + ], + [ + '99-ways-to-beat-apple', + '99 ways TO beat APPLE', + '-' + ], // Invalid characters are removed - array('each-gbp-is-now-worth-32-usd', 'Each GBP(£) is now worth 32 USD($)', '-'), + [ + 'each-gbp-is-now-worth-32-usd', + 'Each GBP(£) is now worth 32 USD($)', + '-' + ], // ... inc. separator - array('is-it-reusable-or-re-usable', 'Is it reusable or re-usable?', '-'), + [ + 'is-it-reusable-or-re-usable', + 'Is it reusable or re-usable?', + '-' + ], // Doing some crazy UTF8 tests - array('espana-wins', 'España-wins', '-', TRUE), - ); + [ + 'espana-wins', + 'España-wins', + '-', + TRUE + ], + ]; } /** @@ -232,22 +421,71 @@ public function test_title($expected, $title, $separator, $ascii_only = FALSE) */ public function provider_query() { - return array( - array(array(), '', NULL), - array(array('_GET' => array('test' => 'data')), '?test=data', NULL), - array(array(), '?test=data', array('test' => 'data')), - array(array('_GET' => array('more' => 'data')), '?more=data&test=data', array('test' => 'data')), - array(array('_GET' => array('sort' => 'down')), '?test=data', array('test' => 'data'), FALSE), + return [ + [ + [], + '', + NULL + ], + [ + ['_GET' => ['test' => 'data']], + '?test=data', + NULL + ], + [ + [], + '?test=data', + ['test' => 'data'] + ], + [ + ['_GET' => ['more' => 'data']], + '?more=data&test=data', + ['test' => 'data'] + ], + [ + ['_GET' => ['sort' => 'down']], + '?test=data', + ['test' => 'data'], + FALSE + ], // http://dev.kohanaframework.org/issues/3362 - array(array(), '', array('key' => NULL)), - array(array(), '?key=0', array('key' => FALSE)), - array(array(), '?key=1', array('key' => TRUE)), - array(array('_GET' => array('sort' => 'down')), '?sort=down&key=1', array('key' => TRUE)), - array(array('_GET' => array('sort' => 'down')), '?sort=down&key=0', array('key' => FALSE)), + [ + [], + '', + ['key' => NULL] + ], + [ + [], + '?key=0', + ['key' => FALSE] + ], + [ + [], + '?key=1', + ['key' => TRUE] + ], + [ + ['_GET' => ['sort' => 'down']], + '?sort=down&key=1', + ['key' => TRUE] + ], + [ + ['_GET' => ['sort' => 'down']], + '?sort=down&key=0', + ['key' => FALSE] + ], // @issue 4240 - array(array('_GET' => array('foo' => array('a' => 100))), '?foo%5Ba%5D=100&foo%5Bb%5D=bar', array('foo' => array('b' => 'bar'))), - array(array('_GET' => array('a' => 'a')), '?a=b', array('a' => 'b')), - ); + [ + ['_GET' => ['foo' => ['a' => 100]]], + '?foo%5Ba%5D=100&foo%5Bb%5D=bar', + ['foo' => ['b' => 'bar']] + ], + [ + ['_GET' => ['a' => 'a']], + '?a=b', + ['a' => 'b'] + ], + ]; } /** @@ -275,41 +513,32 @@ public function test_query($enviroment, $expected, $params, $use_get = TRUE) */ public function provider_is_trusted_host() { - return array( + return [ // data set #0 - array( + [ 'givenhost', - array( - 'list-of-trusted-hosts', - ), + ['list-of-trusted-hosts'], FALSE - ), + ], // data set #1 - array( + [ 'givenhost', - array( - 'givenhost', - 'example\.com', - ), + ['givenhost', 'example\.com'], TRUE - ), + ], // data set #2 - array( + [ 'www.kohanaframework.org', - array( - '.*\.kohanaframework\.org', - ), + ['.*\.kohanaframework\.org'], TRUE - ), + ], // data set #3 - array( + [ 'kohanaframework.org', - array( - '.*\.kohanaframework\.org', - ), + ['.*\.kohanaframework\.org'], FALSE // because we are requesting a subdomain - ), - ); + ], + ]; } /** diff --git a/system/tests/kohana/UTF8Test.php b/system/tests/kohana/UTF8Test.php index f576438..8f9f81b 100644 --- a/system/tests/kohana/UTF8Test.php +++ b/system/tests/kohana/UTF8Test.php @@ -22,14 +22,14 @@ class Kohana_UTF8Test extends Unittest_TestCase */ public function provider_clean() { - return array( - array("\0", ''), - array("→foo\021", '→foo'), - array("\x7Fbar", 'bar'), - array("\xFF", ''), - array("\x41", 'A'), - array(array("→foo\021", "\x41"), array('→foo', 'A')), - ); + return [ + ["\0", ''], + ["→foo\021", '→foo'], + ["\x7Fbar", 'bar'], + ["\xFF", ''], + ["\x41", 'A'], + [["→foo\021", "\x41"], ['→foo', 'A']], + ]; } /** @@ -48,13 +48,13 @@ public function test_clean($input, $expected) */ public function provider_is_ascii() { - return array( - array("\0", TRUE), - array("\$eno\r", TRUE), - array('Señor', FALSE), - array(array('Se', 'nor'), TRUE), - array(array('Se', 'ñor'), FALSE), - ); + return [ + ["\0", TRUE], + ["\$eno\r", TRUE], + ['Señor', FALSE], + [['Se', 'nor'], TRUE], + [['Se', 'ñor'], FALSE], + ]; } /** @@ -73,13 +73,13 @@ public function test_is_ascii($input, $expected) */ public function provider_strip_ascii_ctrl() { - return array( - array("\0", ''), - array("→foo\021", '→foo'), - array("\x7Fbar", 'bar'), - array("\xFF", "\xFF"), - array("\x41", 'A'), - ); + return [ + ["\0", ''], + ["→foo\021", '→foo'], + ["\x7Fbar", 'bar'], + ["\xFF", "\xFF"], + ["\x41", 'A'], + ]; } /** @@ -98,10 +98,10 @@ public function test_strip_ascii_ctrl($input, $expected) */ public function provider_strip_non_ascii() { - return array( - array("\0\021\x7F", "\0\021\x7F"), - array('I ♥ cocoñùт', 'I coco'), - ); + return [ + ["\0\021\x7F", "\0\021\x7F"], + ['I ♥ cocoñùт', 'I coco'], + ]; } /** @@ -120,14 +120,14 @@ public function test_strip_non_ascii($input, $expected) */ public function provider_transliterate_to_ascii() { - return array( - array('Cocoñùт', -1, 'Coconuт'), - array('COCOÑÙТ', -1, 'COCOÑÙТ'), - array('Cocoñùт', 0, 'Coconuт'), - array('COCOÑÙТ', 0, 'COCONUТ'), - array('Cocoñùт', 1, 'Cocoñùт'), - array('COCOÑÙТ', 1, 'COCONUТ'), - ); + return [ + ['Cocoñùт', -1, 'Coconuт'], + ['COCOÑÙТ', -1, 'COCOÑÙТ'], + ['Cocoñùт', 0, 'Coconuт'], + ['COCOÑÙТ', 0, 'COCONUТ'], + ['Cocoñùт', 1, 'Cocoñùт'], + ['COCOÑÙТ', 1, 'COCONUТ'], + ]; } /** @@ -146,10 +146,10 @@ public function test_transliterate_to_ascii($input, $case, $expected) */ public function provider_strlen() { - return array( - array('Cocoñùт', 7), - array('Coconut', 7), - ); + return [ + ['Cocoñùт', 7], + ['Coconut', 7], + ]; } /** @@ -168,10 +168,10 @@ public function test_strlen($input, $expected) */ public function provider_strpos() { - return array( - array('Cocoñùт', 'o', 0, 1), - array('Cocoñùт', 'ñ', 1, 4), - ); + return [ + ['Cocoñùт', 'o', 0, 1], + ['Cocoñùт', 'ñ', 1, 4], + ]; } /** @@ -190,10 +190,10 @@ public function test_strpos($input, $str, $offset, $expected) */ public function provider_strrpos() { - return array( - array('Cocoñùт', 'o', 0, 3), - array('Cocoñùт', 'ñ', 2, 4), - ); + return [ + ['Cocoñùт', 'o', 0, 3], + ['Cocoñùт', 'ñ', 2, 4], + ]; } /** @@ -212,12 +212,12 @@ public function test_strrpos($input, $str, $offset, $expected) */ public function provider_substr() { - return array( - array('Cocoñùт', 3, 2, 'oñ'), - array('Cocoñùт', 3, 9, 'oñùт'), - array('Cocoñùт', 3, NULL, 'oñùт'), - array('Cocoñùт', 3, -2, 'oñ'), - ); + return [ + ['Cocoñùт', 3, 2, 'oñ'], + ['Cocoñùт', 3, 9, 'oñùт'], + ['Cocoñùт', 3, NULL, 'oñùт'], + ['Cocoñùт', 3, -2, 'oñ'], + ]; } /** @@ -236,10 +236,10 @@ public function test_substr($input, $offset, $length, $expected) */ public function provider_substr_replace() { - return array( - array('Cocoñùт', 'šš', 3, 2, 'Cocššùт'), - array('Cocoñùт', 'šš', 3, 9, 'Cocšš'), - ); + return [ + ['Cocoñùт', 'šš', 3, 2, 'Cocššùт'], + ['Cocoñùт', 'šš', 3, 9, 'Cocšš'], + ]; } /** @@ -258,10 +258,10 @@ public function test_substr_replace($input, $replacement, $offset, $length, $exp */ public function provider_strtolower() { - return array( - array('COCOÑÙТ', 'cocoñùт'), - array('JÄGER', 'jäger'), - ); + return [ + ['COCOÑÙТ', 'cocoñùт'], + ['JÄGER', 'jäger'], + ]; } /** @@ -280,10 +280,10 @@ public function test_strtolower($input, $expected) */ public function provider_strtoupper() { - return array( - array('Cocoñùт', 'COCOÑÙТ'), - array('jäger', 'JÄGER'), - ); + return [ + ['Cocoñùт', 'COCOÑÙТ'], + ['jäger', 'JÄGER'], + ]; } /** @@ -302,9 +302,9 @@ public function test_strtoupper($input, $expected) */ public function provider_ucfirst() { - return array( - array('ñùт', 'Ñùт'), - ); + return [ + ['ñùт', 'Ñùт'], + ]; } /** @@ -323,10 +323,10 @@ public function test_ucfirst($input, $expected) */ public function provider_ucwords() { - return array( - array('ExAmple', 'ExAmple'), - array('i ♥ Cocoñùт', 'I ♥ Cocoñùт'), - ); + return [ + ['ExAmple', 'ExAmple'], + ['i ♥ Cocoñùт', 'I ♥ Cocoñùт'], + ]; } /** @@ -345,13 +345,13 @@ public function test_ucwords($input, $expected) */ public function provider_strcasecmp() { - return array( - array('Cocoñùт', 'Cocoñùт', 0), - array('Čau', 'Čauo', -1), - array('Čau', 'Ča', 1), - array('Cocoñùт', 'Cocoñ', 4), - array('Cocoñùт', 'Coco', 6), - ); + return [ + ['Cocoñùт', 'Cocoñùт', 0], + ['Čau', 'Čauo', -1], + ['Čau', 'Ča', 1], + ['Cocoñùт', 'Cocoñ', 4], + ['Cocoñùт', 'Coco', 6], + ]; } /** @@ -370,12 +370,12 @@ public function test_strcasecmp($input, $input2, $expected) */ public function provider_str_ireplace() { - return array( - array('т', 't', 'cocoñuт', 'cocoñut'), - array('Ñ', 'N', 'cocoñuт', 'cocoNuт'), - array(array('т', 'Ñ', 'k' => 'k'), array('t', 'N', 'K'), array('cocoñuт'), array('cocoNut')), - array(array('ñ'), 'n', 'cocoñuт', 'coconuт'), - ); + return [ + ['т', 't', 'cocoñuт', 'cocoñut'], + ['Ñ', 'N', 'cocoñuт', 'cocoNuт'], + [['т', 'Ñ', 'k' => 'k'], ['t', 'N', 'K'], ['cocoñuт'], ['cocoNut']], + [['ñ'], 'n', 'cocoñuт', 'coconuт'], + ]; } /** @@ -394,11 +394,11 @@ public function test_str_ireplace($search, $replace, $subject, $expected) */ public function provider_stristr() { - return array( - array('Cocoñùт', 'oñ', 'oñùт'), - array('Cocoñùт', 'o', 'ocoñùт'), - array('Cocoñùт', 'k', FALSE), - ); + return [ + ['Cocoñùт', 'oñ', 'oñùт'], + ['Cocoñùт', 'o', 'ocoñùт'], + ['Cocoñùт', 'k', FALSE], + ]; } /** @@ -417,12 +417,12 @@ public function test_stristr($input, $input2, $expected) */ public function provider_strspn() { - return array( - array("foo", "o", 1, 2, 2), - array('Cocoñùт', 'oñ', NULL, NULL, 1), - array('Cocoñùт', 'oñ', 2, 4, 1), - array('Cocoñùт', 'šš', 3, 9, 4), - ); + return [ + ["foo", "o", 1, 2, 2], + ['Cocoñùт', 'oñ', NULL, NULL, 1], + ['Cocoñùт', 'oñ', 2, 4, 1], + ['Cocoñùт', 'šš', 3, 9, 4], + ]; } /** @@ -441,11 +441,11 @@ public function test_strspn($input, $mask, $offset, $length, $expected) */ public function provider_strcspn() { - return array( - array('Cocoñùт', 'oñ', NULL, NULL, 1), - array('Cocoñùт', 'oñ', 2, 4, 1), - array('Cocoñùт', 'šš', 3, 9, 4), - ); + return [ + ['Cocoñùт', 'oñ', NULL, NULL, 1], + ['Cocoñùт', 'oñ', 2, 4, 1], + ['Cocoñùт', 'šš', 3, 9, 4], + ]; } /** @@ -464,11 +464,11 @@ public function test_strcspn($input, $mask, $offset, $length, $expected) */ public function provider_str_pad() { - return array( - array('Cocoñùт', 10, 'š', STR_PAD_RIGHT, 'Cocoñùтššš'), - array('Cocoñùт', 10, 'š', STR_PAD_LEFT, 'šššCocoñùт'), - array('Cocoñùт', 10, 'š', STR_PAD_BOTH, 'šCocoñùтšš'), - ); + return [ + ['Cocoñùт', 10, 'š', STR_PAD_RIGHT, 'Cocoñùтššš'], + ['Cocoñùт', 10, 'š', STR_PAD_LEFT, 'šššCocoñùт'], + ['Cocoñùт', 10, 'š', STR_PAD_BOTH, 'šCocoñùтšš'], + ]; } /** @@ -498,11 +498,11 @@ public function test_str_pad_error() */ public function provider_str_split() { - return array( - array('Bár', 1, array('B', 'á', 'r')), - array('Cocoñùт', 2, array('Co', 'co', 'ñù', 'т')), - array('Cocoñùт', 3, array('Coc', 'oñù', 'т')), - ); + return [ + ['Bár', 1, ['B', 'á', 'r']], + ['Cocoñùт', 2, ['Co', 'co', 'ñù', 'т']], + ['Cocoñùт', 3, ['Coc', 'oñù', 'т']], + ]; } /** @@ -521,9 +521,9 @@ public function test_str_split($input, $split_length, $expected) */ public function provider_strrev() { - return array( - array('Cocoñùт', 'тùñocoC'), - ); + return [ + ['Cocoñùт', 'тùñocoC'], + ]; } /** @@ -542,11 +542,11 @@ public function test_strrev($input, $expected) */ public function provider_trim() { - return array( - array(' bar ', NULL, 'bar'), - array('bar', 'b', 'ar'), - array('barb', 'b', 'ar'), - ); + return [ + [' bar ', NULL, 'bar'], + ['bar', 'b', 'ar'], + ['barb', 'b', 'ar'], + ]; } /** @@ -565,12 +565,12 @@ public function test_trim($input, $input2, $expected) */ public function provider_ltrim() { - return array( - array(' bar ', NULL, 'bar '), - array('bar', 'b', 'ar'), - array('barb', 'b', 'arb'), - array('ñùт', 'ñ', 'ùт'), - ); + return [ + [' bar ', NULL, 'bar '], + ['bar', 'b', 'ar'], + ['barb', 'b', 'arb'], + ['ñùт', 'ñ', 'ùт'], + ]; } /** @@ -589,12 +589,12 @@ public function test_ltrim($input, $charlist, $expected) */ public function provider_rtrim() { - return array( - array(' bar ', NULL, ' bar'), - array('bar', 'b', 'bar'), - array('barb', 'b', 'bar'), - array('Cocoñùт', 'т', 'Cocoñù'), - ); + return [ + [' bar ', NULL, ' bar'], + ['bar', 'b', 'bar'], + ['barb', 'b', 'bar'], + ['Cocoñùт', 'т', 'Cocoñù'], + ]; } /** @@ -613,11 +613,11 @@ public function test_rtrim($input, $input2, $expected) */ public function provider_ord() { - return array( - array('f', 102), - array('ñ', 241), - array('Ñ', 209), - ); + return [ + ['f', 102], + ['ñ', 241], + ['Ñ', 209], + ]; } /** diff --git a/system/tests/kohana/UploadTest.php b/system/tests/kohana/UploadTest.php index f9b8826..d1a54d8 100644 --- a/system/tests/kohana/UploadTest.php +++ b/system/tests/kohana/UploadTest.php @@ -20,56 +20,69 @@ class Kohana_UploadTest extends Unittest_TestCase { /** * Provides test data for test_size() - * + * * @return array */ public function provider_size() { - return array( + return [ // $field, $bytes, $environment, $expected - array( + [ 'unit_test', 5, - array('_FILES' => array('unit_test' => array('error' => UPLOAD_ERR_INI_SIZE))), + [ + '_FILES' => [ + 'unit_test' => [ + 'error' => UPLOAD_ERR_INI_SIZE + ] + ] + ], FALSE - ), - array( + ], + [ 'unit_test', 5, - array('_FILES' => array('unit_test' => array('error' => UPLOAD_ERR_NO_FILE))), + [ + '_FILES' => [ + 'unit_test' => [ + 'error' => UPLOAD_ERR_NO_FILE + ] + ] + ], TRUE - ), - array( + ], + [ 'unit_test', '6K', - array('_FILES' => array( - 'unit_test' => array( + [ + '_FILES' => [ + 'unit_test' => [ 'error' => UPLOAD_ERR_OK, 'name' => 'Unit_Test File', 'type' => 'image/png', 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ) - ), + ] + ] + ], TRUE - ), - array( + ], + [ 'unit_test', '1B', - array('_FILES' => array( - 'unit_test' => array( + ['_FILES' => [ + 'unit_test' => [ 'error' => UPLOAD_ERR_OK, 'name' => 'Unit_Test File', 'type' => 'image/png', 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ) - ), + ] + ] + ], FALSE - ), - ); + ], + ]; } /** @@ -99,17 +112,17 @@ public function test_size($field, $bytes, $environment, $expected) */ public function test_size_throws_exception_for_invalid_size() { - $this->setEnvironment(array( - '_FILES' => array( - 'unit_test' => array( + $this->setEnvironment([ + '_FILES' => [ + 'unit_test' => [ 'error' => UPLOAD_ERR_OK, 'name' => 'Unit_Test File', 'type' => 'image/png', 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ) - )); + ] + ] + ]); Upload::size($_FILES['unit_test'], '1DooDah'); } @@ -122,63 +135,63 @@ public function test_size_throws_exception_for_invalid_size() */ public function provider_valid() { - return array( - array( + return [ + [ TRUE, - array( + [ 'error' => UPLOAD_ERR_OK, 'name' => 'Unit_Test File', 'type' => 'image/png', 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ), - array( + ] + ], + [ FALSE, - array( + [ 'name' => 'Unit_Test File', 'type' => 'image/png', 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ), - array( + ] + ], + [ FALSE, - array( + [ 'error' => UPLOAD_ERR_OK, 'type' => 'image/png', 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ), - array( + ] + ], + [ FALSE, - array( + [ 'name' => 'Unit_Test File', 'error' => UPLOAD_ERR_OK, 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ), - array( + ] + ], + [ FALSE, - array( + [ 'error' => UPLOAD_ERR_OK, 'name' => 'Unit_Test File', 'type' => 'image/png', 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ), - array( + ] + ], + [ FALSE, - array( + [ 'error' => UPLOAD_ERR_OK, 'name' => 'Unit_Test File', 'type' => 'image/png', 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), - ) - ), - ); + ] + ], + ]; } /** @@ -190,11 +203,11 @@ public function provider_valid() */ public function test_valid($expected, $file) { - $this->setEnvironment(array( - '_FILES' => array( + $this->setEnvironment([ + '_FILES' => [ 'unit_test' => $file, - ), - )); + ], + ]); $this->assertSame($expected, Upload::valid($_FILES['unit_test'])); } @@ -207,21 +220,21 @@ public function test_valid($expected, $file) */ public function test_type() { - $this->setEnvironment(array( - '_FILES' => array( - 'unit_test' => array( + $this->setEnvironment([ + '_FILES' => [ + 'unit_test' => [ 'error' => UPLOAD_ERR_OK, 'name' => 'github.png', 'type' => 'image/png', 'tmp_name' => Kohana::find_file('tests', 'test_data/github', 'png'), 'size' => filesize(Kohana::find_file('tests', 'test_data/github', 'png')), - ) - ) - )); + ] + ] + ]); - $this->assertTrue(Upload::type($_FILES['unit_test'], array('jpg', 'png', 'gif'))); + $this->assertTrue(Upload::type($_FILES['unit_test'], ['jpg', 'png', 'gif'])); - $this->assertFalse(Upload::type($_FILES['unit_test'], array('docx'))); + $this->assertFalse(Upload::type($_FILES['unit_test'], ['docx'])); } } diff --git a/system/tests/kohana/ValidTest.php b/system/tests/kohana/ValidTest.php index 0671628..621ab69 100644 --- a/system/tests/kohana/ValidTest.php +++ b/system/tests/kohana/ValidTest.php @@ -24,19 +24,19 @@ class Kohana_ValidTest extends Unittest_TestCase */ public function provider_alpha() { - return array( - array('asdavafaiwnoabwiubafpowf', TRUE), - array('!aidhfawiodb', FALSE), - array('51535oniubawdawd78', FALSE), - array('!"£$(G$W£(HFW£F(HQ)"n', FALSE), + return [ + ['asdavafaiwnoabwiubafpowf', TRUE], + ['!aidhfawiodb', FALSE], + ['51535oniubawdawd78', FALSE], + ['!"£$(G$W£(HFW£F(HQ)"n', FALSE], // UTF-8 tests - array('あいうえお', TRUE, TRUE), - array('¥', FALSE, TRUE), + ['あいうえお', TRUE, TRUE], + ['¥', FALSE, TRUE], // Empty test - array('', FALSE, FALSE), - array(NULL, FALSE, FALSE), - array(FALSE, FALSE, FALSE), - ); + ['', FALSE, FALSE], + [NULL, FALSE, FALSE], + [FALSE, FALSE, FALSE], + ]; } /** @@ -61,20 +61,20 @@ public function test_alpha($string, $expected, $utf8 = FALSE) */ public function provide_alpha_numeric() { - return array( - array('abcd1234', TRUE), - array('abcd', TRUE), - array('1234', TRUE), - array('abc123&^/-', FALSE), + return [ + ['abcd1234', TRUE], + ['abcd', TRUE], + ['1234', TRUE], + ['abc123&^/-', FALSE], // UTF-8 tests - array('あいうえお', TRUE, TRUE), - array('零一二三四五', TRUE, TRUE), - array('あい四五£^£^', FALSE, TRUE), + ['あいうえお', TRUE, TRUE], + ['零一二三四五', TRUE, TRUE], + ['あい四五£^£^', FALSE, TRUE], // Empty test - array('', FALSE, FALSE), - array(NULL, FALSE, FALSE), - array(FALSE, FALSE, FALSE), - ); + ['', FALSE, FALSE], + [NULL, FALSE, FALSE], + [FALSE, FALSE, FALSE], + ]; } /** @@ -99,17 +99,17 @@ public function test_alpha_numeric($input, $expected, $utf8 = FALSE) */ public function provider_alpha_dash() { - return array( - array('abcdef', TRUE), - array('12345', TRUE), - array('abcd1234', TRUE), - array('abcd1234-', TRUE), - array('abc123&^/-', FALSE), + return [ + ['abcdef', TRUE], + ['12345', TRUE], + ['abcd1234', TRUE], + ['abcd1234-', TRUE], + ['abc123&^/-', FALSE], // Empty test - array('', FALSE), - array(NULL, FALSE), - array(FALSE, FALSE), - ); + ['', FALSE], + [NULL, FALSE], + [FALSE, FALSE], + ]; } /** @@ -141,22 +141,22 @@ public function test_alpha_dash($input, $expected, $contains_utf8 = FALSE) */ public function provider_date() { - return array( - array('now', TRUE), - array('10 September 2010', TRUE), - array('+1 day', TRUE), - array('+1 week', TRUE), - array('+1 week 2 days 4 hours 2 seconds', TRUE), - array('next Thursday', TRUE), - array('last Monday', TRUE), - array('blarg', FALSE), - array('in the year 2000', FALSE), - array('324824', FALSE), + return [ + ['now', TRUE], + ['10 September 2010', TRUE], + ['+1 day', TRUE], + ['+1 week', TRUE], + ['+1 week 2 days 4 hours 2 seconds', TRUE], + ['next Thursday', TRUE], + ['last Monday', TRUE], + ['blarg', FALSE], + ['in the year 2000', FALSE], + ['324824', FALSE], // Empty test - array('', FALSE), - array(NULL, FALSE), - array(FALSE, FALSE), - ); + ['', FALSE], + [NULL, FALSE], + [FALSE, FALSE], + ]; } /** @@ -179,18 +179,18 @@ public function test_date($date, $expected) */ public function provider_decimal() { - return array( + return [ // Empty test - array('', 2, NULL, FALSE), - array(NULL, 2, NULL, FALSE), - array(FALSE, 2, NULL, FALSE), - array('45.1664', 3, NULL, FALSE), - array('45.1664', 4, NULL, TRUE), - array('45.1664', 4, 2, TRUE), - array('-45.1664', 4, NULL, TRUE), - array('+45.1664', 4, NULL, TRUE), - array('-45.1664', 3, NULL, FALSE), - ); + ['', 2, NULL, FALSE], + [NULL, 2, NULL, FALSE], + [FALSE, 2, NULL, FALSE], + ['45.1664', 3, NULL, FALSE], + ['45.1664', 4, NULL, TRUE], + ['45.1664', 4, 2, TRUE], + ['-45.1664', 4, NULL, TRUE], + ['+45.1664', 4, NULL, TRUE], + ['-45.1664', 3, NULL, FALSE], + ]; } /** @@ -216,18 +216,18 @@ public function test_decimal($decimal, $places, $digits, $expected) */ public function provider_digit() { - return array( - array('12345', TRUE), - array('10.5', FALSE), - array('abcde', FALSE), - array('abcd1234', FALSE), - array('-5', FALSE), - array(-5, FALSE), + return [ + ['12345', TRUE], + ['10.5', FALSE], + ['abcde', FALSE], + ['abcd1234', FALSE], + ['-5', FALSE], + [-5, FALSE], // Empty test - array('', FALSE), - array(NULL, FALSE), - array(FALSE, FALSE), - ); + ['', FALSE], + [NULL, FALSE], + [FALSE, FALSE], + ]; } /** @@ -256,23 +256,23 @@ public function test_digit($input, $expected, $contains_utf8 = FALSE) */ public function provider_color() { - return array( - array('#000000', TRUE), - array('#GGGGGG', FALSE), - array('#AbCdEf', TRUE), - array('#000', TRUE), - array('#abc', TRUE), - array('#DEF', TRUE), - array('000000', TRUE), - array('GGGGGG', FALSE), - array('AbCdEf', TRUE), - array('000', TRUE), - array('DEF', TRUE), + return [ + ['#000000', TRUE], + ['#GGGGGG', FALSE], + ['#AbCdEf', TRUE], + ['#000', TRUE], + ['#abc', TRUE], + ['#DEF', TRUE], + ['000000', TRUE], + ['GGGGGG', FALSE], + ['AbCdEf', TRUE], + ['000', TRUE], + ['DEF', TRUE], // Empty test - array('', FALSE), - array(NULL, FALSE), - array(FALSE, FALSE), - ); + ['', FALSE], + [NULL, FALSE], + [FALSE, FALSE], + ]; } /** @@ -295,21 +295,21 @@ public function test_color($color, $expected) */ public function provider_credit_card() { - return array( - array('4222222222222', 'visa', TRUE), - array('4012888888881881', 'visa', TRUE), - array('4012888888881881', NULL, TRUE), - array('4012888888881881', array('mastercard', 'visa'), TRUE), - array('4012888888881881', array('discover', 'mastercard'), FALSE), - array('4012888888881881', 'mastercard', FALSE), - array('5105105105105100', 'mastercard', TRUE), - array('6011111111111117', 'discover', TRUE), - array('6011111111111117', 'visa', FALSE), + return [ + ['4222222222222', 'visa', TRUE], + ['4012888888881881', 'visa', TRUE], + ['4012888888881881', NULL, TRUE], + ['4012888888881881', ['mastercard', 'visa'], TRUE], + ['4012888888881881', ['discover', 'mastercard'], FALSE], + ['4012888888881881', 'mastercard', FALSE], + ['5105105105105100', 'mastercard', TRUE], + ['6011111111111117', 'discover', TRUE], + ['6011111111111117', 'visa', FALSE], // Empty test - array('', NULL, FALSE), - array(NULL, NULL, FALSE), - array(FALSE, NULL, FALSE), - ); + ['', NULL, FALSE], + [NULL, NULL, FALSE], + [FALSE, NULL, FALSE], + ]; } /** @@ -334,20 +334,20 @@ public function test_credit_card($number, $type, $expected) */ public function provider_luhn() { - return array( - array('4222222222222', TRUE), - array('4012888888881881', TRUE), - array('5105105105105100', TRUE), - array('6011111111111117', TRUE), - array('60111111111111.7', FALSE), - array('6011111111111117X', FALSE), - array('6011111111111117 ', FALSE), - array('WORD ', FALSE), + return [ + ['4222222222222', TRUE], + ['4012888888881881', TRUE], + ['5105105105105100', TRUE], + ['6011111111111117', TRUE], + ['60111111111111.7', FALSE], + ['6011111111111117X', FALSE], + ['6011111111111117 ', FALSE], + ['WORD ', FALSE], // Empty test - array('', FALSE), - array(NULL, FALSE), - array(FALSE, FALSE), - ); + ['', FALSE], + [NULL, FALSE], + [FALSE, FALSE], + ]; } /** @@ -373,25 +373,25 @@ public function test_luhn($number, $expected) */ public function provider_email() { - return array( - array('foo', TRUE, FALSE), - array('foo', FALSE, FALSE), - array('foo@bar', TRUE, TRUE), + return [ + ['foo', TRUE, FALSE], + ['foo', FALSE, FALSE], + ['foo@bar', TRUE, TRUE], // RFC is less strict than the normal regex, presumably to allow // admin@localhost, therefore we IGNORE IT!!! - array('foo@bar', FALSE, FALSE), - array('foo@bar.com', FALSE, TRUE), - array('foo@barcom:80', FALSE, FALSE), - array('foo@bar.sub.com', FALSE, TRUE), - array('foo+asd@bar.sub.com', FALSE, TRUE), - array('foo.asd@bar.sub.com', FALSE, TRUE), + ['foo@bar', FALSE, FALSE], + ['foo@bar.com', FALSE, TRUE], + ['foo@barcom:80', FALSE, FALSE], + ['foo@bar.sub.com', FALSE, TRUE], + ['foo+asd@bar.sub.com', FALSE, TRUE], + ['foo.asd@bar.sub.com', FALSE, TRUE], // RFC says 254 length max #4011 - array(Text::random(NULL, 200) . '@' . Text::random(NULL, 50) . '.com', FALSE, FALSE), + [Text::random(NULL, 200) . '@' . Text::random(NULL, 50) . '.com', FALSE, FALSE], // Empty test - array('', TRUE, FALSE), - array(NULL, TRUE, FALSE), - array(FALSE, TRUE, FALSE), - ); + ['', TRUE, FALSE], + [NULL, TRUE, FALSE], + [FALSE, TRUE, FALSE], + ]; } /** @@ -419,15 +419,15 @@ public function test_email($email, $strict, $correct) */ public function provider_email_domain() { - return array( - array('google.com', TRUE), + return [ + ['google.com', TRUE], // Don't anybody dare register this... - array('DAWOMAWIDAIWNDAIWNHDAWIHDAIWHDAIWOHDAIOHDAIWHD.com', FALSE), + ['DAWOMAWIDAIWNDAIWNHDAWIHDAIWHDAIWOHDAIOHDAIWHD.com', FALSE], // Empty test - array('', FALSE), - array(NULL, FALSE), - array(FALSE, FALSE), - ); + ['', FALSE], + [NULL, FALSE], + [FALSE, FALSE], + ]; } /** @@ -465,18 +465,18 @@ public function test_email_domain($email, $correct) */ public function provider_exact_length() { - return array( - array('somestring', 10, TRUE), - array('somestring', 11, FALSE), - array('anotherstring', 13, TRUE), + return [ + ['somestring', 10, TRUE], + ['somestring', 11, FALSE], + ['anotherstring', 13, TRUE], // Empty test - array('', 10, FALSE), - array(NULL, 10, FALSE), - array(FALSE, 10, FALSE), + ['', 10, FALSE], + [NULL, 10, FALSE], + [FALSE, 10, FALSE], // Test array of allowed lengths - array('somestring', array(1, 3, 5, 7, 9, 10), TRUE), - array('somestring', array(1, 3, 5, 7, 9), FALSE), - ); + ['somestring', [1, 3, 5, 7, 9, 10], TRUE], + ['somestring', [1, 3, 5, 7, 9], FALSE], + ]; } /** @@ -506,16 +506,16 @@ public function test_exact_length($string, $length, $correct) */ public function provider_equals() { - return array( - array('foo', 'foo', TRUE), - array('1', '1', TRUE), - array(1, '1', FALSE), - array('011', 011, FALSE), + return [ + ['foo', 'foo', TRUE], + ['1', '1', TRUE], + [1, '1', FALSE], + ['011', 011, FALSE], // Empty test - array('', 123, FALSE), - array(NULL, 123, FALSE), - array(FALSE, 123, FALSE), - ); + ['', 123, FALSE], + [NULL, 123, FALSE], + [FALSE, 123, FALSE], + ]; } /** @@ -541,19 +541,19 @@ public function test_equals($string, $required, $correct) */ public function provider_ip() { - return array( - array('75.125.175.50', FALSE, TRUE), + return [ + ['75.125.175.50', FALSE, TRUE], // PHP 5.3.6 fixed a bug that allowed 127.0.0.1 as a public ip: http://bugs.php.net/53150 - array('127.0.0.1', FALSE, version_compare(PHP_VERSION, '5.3.6', '<')), - array('256.257.258.259', FALSE, FALSE), - array('255.255.255.255', FALSE, FALSE), - array('192.168.0.1', FALSE, FALSE), - array('192.168.0.1', TRUE, TRUE), + ['127.0.0.1', FALSE, version_compare(PHP_VERSION, '5.3.6', '<')], + ['256.257.258.259', FALSE, FALSE], + ['255.255.255.255', FALSE, FALSE], + ['192.168.0.1', FALSE, FALSE], + ['192.168.0.1', TRUE, TRUE], // Empty test - array('', TRUE, FALSE), - array(NULL, TRUE, FALSE), - array(FALSE, TRUE, FALSE), - ); + ['', TRUE, FALSE], + [NULL, TRUE, FALSE], + [FALSE, TRUE, FALSE], + ]; } /** @@ -579,18 +579,18 @@ public function test_ip($input_ip, $allow_private, $expected_result) */ public function provider_max_length() { - return array( + return [ // Border line - array('some', 4, TRUE), + ['some', 4, TRUE], // Exceeds - array('KOHANARULLLES', 2, FALSE), + ['KOHANARULLLES', 2, FALSE], // Under - array('CakeSucks', 10, TRUE), + ['CakeSucks', 10, TRUE], // Empty test - array('', -10, FALSE), - array(NULL, -10, FALSE), - array(FALSE, -10, FALSE), - ); + ['', -10, FALSE], + [NULL, -10, FALSE], + [FALSE, -10, FALSE], + ]; } /** @@ -618,15 +618,15 @@ public function test_max_length($string, $maxlength, $correct) */ public function provider_min_length() { - return array( - array('This is obviously long enough', 10, TRUE), - array('This is not', 101, FALSE), - array('This is on the borderline', 25, TRUE), + return [ + ['This is obviously long enough', 10, TRUE], + ['This is not', 101, FALSE], + ['This is on the borderline', 25, TRUE], // Empty test - array('', 10, FALSE), - array(NULL, 10, FALSE), - array(FALSE, 10, FALSE), - ); + ['', 10, FALSE], + [NULL, 10, FALSE], + [FALSE, 10, FALSE], + ]; } /** @@ -661,17 +661,17 @@ public function provider_not_empty() $ao1 = new ArrayObject; $ao1['test'] = 'value'; - return array( - array(array(), FALSE), - array(NULL, FALSE), - array('', FALSE), - array($ao, FALSE), - array($ao1, TRUE), - array(array(NULL), TRUE), - array(0, TRUE), - array('0', TRUE), - array('Something', TRUE), - ); + return [ + [[], FALSE], + [NULL, FALSE], + ['', FALSE], + [$ao, FALSE], + [$ao1, TRUE], + [[NULL], TRUE], + [0, TRUE], + ['0', TRUE], + ['Something', TRUE], + ]; } /** @@ -696,29 +696,29 @@ public function test_not_empty($value, $empty) */ public function provider_numeric() { - return array( - array(12345, TRUE), - array(123.45, TRUE), - array('12345', TRUE), - array('10.5', TRUE), - array('-10.5', TRUE), - array('10.5a', FALSE), + return [ + [12345, TRUE], + [123.45, TRUE], + ['12345', TRUE], + ['10.5', TRUE], + ['-10.5', TRUE], + ['10.5a', FALSE], // @issue 3240 - array(.4, TRUE), - array(-.4, TRUE), - array(4., TRUE), - array(-4., TRUE), - array('.5', TRUE), - array('-.5', TRUE), - array('5.', TRUE), - array('-5.', TRUE), - array('.', FALSE), - array('1.2.3', FALSE), + [.4, TRUE], + [-.4, TRUE], + [4., TRUE], + [-4., TRUE], + ['.5', TRUE], + ['-.5', TRUE], + ['5.', TRUE], + ['-5.', TRUE], + ['.', FALSE], + ['1.2.3', FALSE], // Empty test - array('', FALSE), - array(NULL, FALSE), - array(FALSE, FALSE), - ); + ['', FALSE], + [NULL, FALSE], + [FALSE, FALSE], + ]; } /** @@ -742,22 +742,22 @@ public function test_numeric($input, $expected) */ public function provider_phone() { - return array( - array('0163634840', NULL, TRUE), - array('+27173634840', NULL, TRUE), - array('123578', NULL, FALSE), + return [ + ['0163634840', NULL, TRUE], + ['+27173634840', NULL, TRUE], + ['123578', NULL, FALSE], // Some uk numbers - array('01234456778', NULL, TRUE), - array('+0441234456778', NULL, FALSE), + ['01234456778', NULL, TRUE], + ['+0441234456778', NULL, FALSE], // Google UK case you're interested - array('+44 20-7031-3000', array(12), TRUE), + ['+44 20-7031-3000', [12], TRUE], // BT Corporate - array('020 7356 5000', NULL, TRUE), + ['020 7356 5000', NULL, TRUE], // Empty test - array('', NULL, FALSE), - array(NULL, NULL, FALSE), - array(FALSE, NULL, FALSE), - ); + ['', NULL, FALSE], + [NULL, NULL, FALSE], + [FALSE, NULL, FALSE], + ]; } /** @@ -780,16 +780,16 @@ public function test_phone($phone, $lengths, $expected) */ public function provider_regex() { - return array( - array('hello world', '/[a-zA-Z\s]++/', TRUE), - array('123456789', '/[0-9]++/', TRUE), - array('£$%£%', '/[abc]/', FALSE), - array('Good evening', '/hello/', FALSE), + return [ + ['hello world', '/[a-zA-Z\s]++/', TRUE], + ['123456789', '/[0-9]++/', TRUE], + ['£$%£%', '/[abc]/', FALSE], + ['Good evening', '/hello/', FALSE], // Empty test - array('', '/hello/', FALSE), - array(NULL, '/hello/', FALSE), - array(FALSE, '/hello/', FALSE), - ); + ['', '/hello/', FALSE], + [NULL, '/hello/', FALSE], + [FALSE, '/hello/', FALSE], + ]; } /** @@ -815,30 +815,30 @@ public function test_regex($value, $regex, $expected) */ public function provider_range() { - return array( - array(1, 0, 2, NULL, TRUE), - array(-1, -5, 0, NULL, TRUE), - array(-1, 0, 1, NULL, FALSE), - array(1, 0, 0, NULL, FALSE), - array(2147483647, 0, 200000000000000, NULL, TRUE), - array(-2147483647, -2147483655, 2147483645, NULL, TRUE), + return [ + [1, 0, 2, NULL, TRUE], + [-1, -5, 0, NULL, TRUE], + [-1, 0, 1, NULL, FALSE], + [1, 0, 0, NULL, FALSE], + [2147483647, 0, 200000000000000, NULL, TRUE], + [-2147483647, -2147483655, 2147483645, NULL, TRUE], // #4043 - array(2, 0, 10, 2, TRUE), - array(3, 0, 10, 2, FALSE), + [2, 0, 10, 2, TRUE], + [3, 0, 10, 2, FALSE], // #4672 - array(0, 0, 10, NULL, TRUE), - array(10, 0, 10, NULL, TRUE), - array(-10, -10, 10, NULL, TRUE), - array(-10, -1, 1, NULL, FALSE), - array(0, 0, 10, 2, TRUE), // with $step - array(10, 0, 10, 2, TRUE), - array(10, 0, 10, 3, FALSE), // max outside $step - array(12, 0, 12, 3, TRUE), + [0, 0, 10, NULL, TRUE], + [10, 0, 10, NULL, TRUE], + [-10, -10, 10, NULL, TRUE], + [-10, -1, 1, NULL, FALSE], + [0, 0, 10, 2, TRUE], // with $step + [10, 0, 10, 2, TRUE], + [10, 0, 10, 3, FALSE], // max outside $step + [12, 0, 12, 3, TRUE], // Empty test - array('', 5, 10, NULL, FALSE), - array(NULL, 5, 10, NULL, FALSE), - array(FALSE, 5, 10, NULL, FALSE), - ); + ['', 5, 10, NULL, FALSE], + [NULL, 5, 10, NULL, FALSE], + [FALSE, 5, 10, NULL, FALSE], + ]; } /** @@ -867,40 +867,41 @@ public function test_range($number, $min, $max, $step, $expected) */ public function provider_url() { - $data = array( - array('http://google.com', TRUE), - array('http://google.com/', TRUE), - array('http://google.com/?q=abc', TRUE), - array('http://google.com/#hash', TRUE), - array('http://localhost', TRUE), - array('http://hello-world.pl', TRUE), - array('http://hello--world.pl', TRUE), - array('http://h.e.l.l.0.pl', TRUE), - array('http://server.tld/get/info', TRUE), - array('http://127.0.0.1', TRUE), - array('http://127.0.0.1:80', TRUE), - array('http://user@127.0.0.1', TRUE), - array('http://user:pass@127.0.0.1', TRUE), - array('ftp://my.server.com', TRUE), - array('rss+xml://rss.example.com', TRUE), - array('http://google.2com', FALSE), - array('http://google.com?q=abc', FALSE), - array('http://google.com#hash', FALSE), - array('http://hello-.pl', FALSE), - array('http://hel.-lo.world.pl', FALSE), - array('http://ww£.google.com', FALSE), - array('http://127.0.0.1234', FALSE), - array('http://127.0.0.1.1', FALSE), - array('http://user:@127.0.0.1', FALSE), - array("http://finalnewline.com\n", FALSE), + $data = [ + ['http://google.com', TRUE], + ['http://google.com/', TRUE], + ['http://google.com/?q=abc', TRUE], + ['http://google.com/#hash', TRUE], + ['http://localhost', TRUE], + ['http://hello-world.pl', TRUE], + ['http://hello--world.pl', TRUE], + ['http://h.e.l.l.0.pl', TRUE], + ['http://server.tld/get/info', TRUE], + ['http://127.0.0.1', TRUE], + ['http://127.0.0.1:80', TRUE], + ['http://user@127.0.0.1', TRUE], + ['http://user:pass@127.0.0.1', TRUE], + ['ftp://my.server.com', TRUE], + ['rss+xml://rss.example.com', TRUE], + ['http://google.2com', FALSE], + ['http://google.com?q=abc', FALSE], + ['http://google.com#hash', FALSE], + ['http://hello-.pl', FALSE], + ['http://hel.-lo.world.pl', FALSE], + ['http://ww£.google.com', FALSE], + ['http://127.0.0.1234', FALSE], + ['http://127.0.0.1.1', FALSE], + ['http://user:@127.0.0.1', FALSE], + ["http://finalnewline.com\n", FALSE], // Empty test - array('', FALSE), - array(NULL, FALSE), - array(FALSE, FALSE), - ); - - $data[] = array('http://' . str_repeat('123456789.', 25) . 'com/', TRUE); // 253 chars - $data[] = array('http://' . str_repeat('123456789.', 25) . 'info/', FALSE); // 254 chars + ['', FALSE], + [NULL, FALSE], + [FALSE, FALSE], + // 253 chars + ['http://' . str_repeat('123456789.', 25) . 'com/', TRUE], + // 254 chars + ['http://' . str_repeat('123456789.', 25) . 'info/', FALSE], + ]; return $data; } @@ -925,15 +926,15 @@ public function test_url($url, $expected) */ public function provider_matches() { - return array( - array(array('a' => 'hello', 'b' => 'hello'), 'a', 'b', TRUE), - array(array('a' => 'hello', 'b' => 'hello '), 'a', 'b', FALSE), - array(array('a' => '1', 'b' => 1), 'a', 'b', FALSE), + return [ + [['a' => 'hello', 'b' => 'hello'], 'a', 'b', TRUE], + [['a' => 'hello', 'b' => 'hello '], 'a', 'b', FALSE], + [['a' => '1', 'b' => 1], 'a', 'b', FALSE], // Empty test - array(array('a' => '', 'b' => 'hello'), 'a', 'b', FALSE), - array(array('a' => NULL, 'b' => 'hello'), 'a', 'b', FALSE), - array(array('a' => FALSE, 'b' => 'hello'), 'a', 'b', FALSE), - ); + [['a' => '', 'b' => 'hello'], 'a', 'b', FALSE], + [['a' => NULL, 'b' => 'hello'], 'a', 'b', FALSE], + [['a' => FALSE, 'b' => 'hello'], 'a', 'b', FALSE], + ]; } /** diff --git a/system/tests/kohana/ValidationTest.php b/system/tests/kohana/ValidationTest.php index c52fe7b..f6cbe97 100644 --- a/system/tests/kohana/ValidationTest.php +++ b/system/tests/kohana/ValidationTest.php @@ -28,11 +28,11 @@ class Kohana_ValidationTest extends Unittest_TestCase */ public function test_factory_method_returns_instance_with_values() { - $values = array( + $values = [ 'this' => 'something else', 'writing tests' => 'sucks', 'why the hell' => 'amIDoingThis', - ); + ]; $instance = Validation::factory($values); @@ -53,17 +53,21 @@ public function test_factory_method_returns_instance_with_values() */ public function test_copy_copies_all_attributes_except_data() { - $validation = new Validation(array('foo' => 'bar', 'fud' => 'fear, uncertainty, doubt', 'num' => 9)); + $validation = new Validation([ + 'foo' => 'bar', + 'fud' => 'fear, uncertainty, doubt', + 'num' => 9 + ]); $validation->rule('num', 'is_int')->rule('foo', 'is_string'); - $copy_data = array('foo' => 'no', 'fud' => 'maybe', 'num' => 42); + $copy_data = ['foo' => 'no', 'fud' => 'maybe', 'num' => 42]; $copy = $validation->copy($copy_data); $this->assertNotSame($validation, $copy); - foreach (array('_rules', '_bound', '_labels', '_empty_rules', '_errors') as $attribute) { + foreach (['_rules', '_bound', '_labels', '_empty_rules', '_errors'] as $attribute) { // This is just an easy way to check that the attributes are identical // Without hardcoding the expected values $this->assertAttributeSame( @@ -82,9 +86,9 @@ public function test_copy_copies_all_attributes_except_data() */ public function test_initially_there_are_no_labels() { - $validation = new Validation(array()); + $validation = new Validation([]); - $this->assertAttributeSame(array(), '_labels', $validation); + $this->assertAttributeSame([], '_labels', $validation); } /** @@ -98,19 +102,22 @@ public function test_initially_there_are_no_labels() */ public function test_label_adds_and_overwrites_label_and_returns_this() { - $validation = new Validation(array()); + $validation = new Validation([]); $this->assertSame($validation, $validation->label('email', 'Email Address')); - $this->assertAttributeSame(array('email' => 'Email Address'), '_labels', $validation); + $this->assertAttributeSame([ + 'email' => 'Email Address' + ], '_labels', $validation); $this->assertSame($validation, $validation->label('email', 'Your Email')); $validation->label('name', 'Your Name'); - $this->assertAttributeSame( - array('email' => 'Your Email', 'name' => 'Your Name'), '_labels', $validation - ); + $this->assertAttributeSame([ + 'email' => 'Your Email', + 'name' => 'Your Name' + ], '_labels', $validation); } /** @@ -123,18 +130,21 @@ public function test_label_adds_and_overwrites_label_and_returns_this() */ public function test_labels_adds_and_overwrites_multiple_labels_and_returns_this() { - $validation = new Validation(array()); - $initial_data = array('kung fu' => 'fighting', 'fast' => 'cheetah'); + $validation = new Validation([]); + $initial_data = ['kung fu' => 'fighting', 'fast' => 'cheetah']; $this->assertSame($validation, $validation->labels($initial_data)); $this->assertAttributeSame($initial_data, '_labels', $validation); - $this->assertSame($validation, $validation->labels(array('fast' => 'lightning'))); + $this->assertSame($validation, $validation->labels([ + 'fast' => 'lightning' + ])); - $this->assertAttributeSame( - array('fast' => 'lightning', 'kung fu' => 'fighting'), '_labels', $validation - ); + $this->assertAttributeSame([ + 'fast' => 'lightning', + 'kung fu' => 'fighting' + ], '_labels', $validation); } /** @@ -147,9 +157,9 @@ public function test_labels_adds_and_overwrites_multiple_labels_and_returns_this */ public function test_bind_adds_and_overwrites_multiple_variables_and_returns_this() { - $validation = new Validation(array()); - $data = array('kung fu' => 'fighting', 'fast' => 'cheetah'); - $bound = array(':foo' => 'some value'); + $validation = new Validation([]); + $data = ['kung fu' => 'fighting', 'fast' => 'cheetah']; + $bound = [':foo' => 'some value']; // Test binding an array of values $this->assertSame($validation, $validation->bind($bound)); @@ -157,7 +167,9 @@ public function test_bind_adds_and_overwrites_multiple_variables_and_returns_thi // Test binding one value $this->assertSame($validation, $validation->bind(':foo', 'some other value')); - $this->assertAttributeSame(array(':foo' => 'some other value'), '_bound', $validation); + $this->assertAttributeSame([ + ':foo' => 'some other value' + ], '_bound', $validation); } /** @@ -168,14 +180,14 @@ public function test_bind_adds_and_overwrites_multiple_variables_and_returns_thi */ public function test_bound_callback() { - $data = array( + $data = [ 'kung fu' => 'fighting', 'fast' => 'cheetah', - ); + ]; $validation = new Validation($data); $validation->bind(':class', 'Valid') // Use the bound value in a callback - ->rule('fast', array(':class', 'max_length'), array(':value', 2)); + ->rule('fast', [':class', 'max_length'], [':value', 2]); // The rule should have run and check() should fail $this->assertSame($validation->check(), FALSE); @@ -189,77 +201,76 @@ public function test_bound_callback() public function provider_check() { // $data_array, $rules, $labels, $first_expected, $expected_error - return array( - array( - array('foo' => 'bar'), - array('foo' => array(array('not_empty', NULL))), - array(), + return [ + [ + ['foo' => 'bar'], + ['foo' => [['not_empty', NULL]]], + [], TRUE, - array(), - ), - array( - array('unit' => 'test'), - array( - 'foo' => array(array('not_empty', NULL)), - 'unit' => array(array('min_length', array(':value', 6)) - ), - ), - array(), + [] + ], + [ + ['unit' => 'test'], + [ + 'foo' => [['not_empty', NULL]], + 'unit' => [['min_length', [':value', 6]]] + ], + [], FALSE, - array( + [ 'foo' => 'foo must not be empty', 'unit' => 'unit must be at least 6 characters long' - ), - ), - array( - array('foo' => 'bar'), - array( + ] + ], + [ + ['foo' => 'bar'], + [ // Tests wildcard rules - TRUE => array(array('min_length', array(':value', 4))), - 'foo' => array( - array('not_empty', NULL), + TRUE => [['min_length', [':value', 4]]], + 'foo' => [ + ['not_empty', NULL], // Tests the array syntax for callbacks - array(array('Valid', 'exact_length'), array(':value', 3)), + [['Valid', 'exact_length'], [':value', 3]], // Tests the Class::method syntax for callbacks - array('Valid::exact_length', array(':value', 3)), + ['Valid::exact_length', [':value', 3]], // Tests the lambda function syntax for callbacks // Commented out for PHP 5.2 support - // array(function($value){return TRUE;}, array(':value')), + // [function($value){return TRUE;}, [':value']], // Tests using a function as a rule - array('is_string', array(':value')), - ), + ['is_string', [':value']] + ], // Tests that rules do not run on empty fields unless they are in _empty_rules - 'unit' => array(array('exact_length', array(':value', 4))), - ), - array(), + 'unit' => [['exact_length', [':value', 4]]] + ], + [], FALSE, - array('foo' => 'foo must be at least 4 characters long'), - ), + ['foo' => 'foo must be at least 4 characters long'] + ], // Switch things around and make :value an array - array( - array('foo' => array('test', 'data')), - array('foo' => array(array('in_array', array('kohana', ':value')))), - array(), + [ + ['foo' => ['test', 'data']], + ['foo' => [['in_array', ['kohana', ':value']]]], + [], FALSE, - array('foo' => 'foo must be one of the available options'), - ), + ['foo' => 'foo must be one of the available options'] + ], // Test wildcard rules with no other rules - array( - array('foo' => array('test')), - array(TRUE => array(array('is_string', array(':value')))), - array('foo' => 'foo'), + [ + ['foo' => ['test']], + [TRUE => [['is_string', [':value']]]], + ['foo' => 'foo'], FALSE, - array('foo' => '1.foo.is_string'), - ), + ['foo' => '1.foo.is_string'] + ], // Test array rules use method as error name - array( - array('foo' => 'test'), - array('foo' => array(array(array('Valid', 'min_length'), array(':value', 10)))), - array(), + [ + ['foo' => 'test'], + ['foo' => [[['Valid', 'min_length'], [':value', 10]]]], + [], FALSE, - array('foo' => 'foo must be at least 10 characters long'), - ), - ); + ['foo' => 'foo must be at least 10 characters long'] + ], + ]; } /** @@ -313,24 +324,19 @@ public function test_check($array, $rules, $labels, $expected, $expected_errors) */ public function test_check_stops_when_error_added_by_callback() { - $validation = new Validation(array( - 'foo' => 'foo', - )); + $validation = new Validation(['foo' => 'foo']); $validation - ->rule('foo', array($this, '_validation_callback'), array(':validation')) + ->rule('foo', [$this, '_validation_callback'], [':validation']) // This rule should never run - ->rule('foo', 'min_length', array(':value', 20)); + ->rule('foo', 'min_length', [':value', 20]); $validation->check(); $errors = $validation->errors(); - $expected = array( - 'foo' => array( - 0 => '_validation_callback', - 1 => NULL, - ), - ); + $expected = [ + 'foo' => [0 => '_validation_callback', 1 => NULL], + ]; $this->assertSame($errors, $expected); } @@ -349,26 +355,26 @@ public function _validation_callback(Validation $object) public function provider_errors() { // [data, rules, expected], ... - return array( + return [ // No Error - array( - array('username' => 'frank'), - array('username' => array(array('not_empty', NULL))), - array(), - ), + [ + ['username' => 'frank'], + ['username' => [['not_empty', NULL]]], + [] + ], // Error from message file - array( - array('username' => ''), - array('username' => array(array('not_empty', NULL))), - array('username' => 'username must not be empty'), - ), + [ + ['username' => ''], + ['username' => [['not_empty', NULL]]], + ['username' => 'username must not be empty'] + ], // No error message exists, display the path expected - array( - array('username' => 'John'), - array('username' => array(array('strpos', array(':value', 'Kohana')))), - array('username' => 'Validation.username.strpos'), - ), - ); + [ + ['username' => 'John'], + ['username' => [['strpos', [':value', 'Kohana']]]], + ['username' => 'Validation.username.strpos'] + ], + ]; } /** @@ -404,15 +410,15 @@ public function test_errors($array, $rules, $expected) public function provider_translated_errors() { // [data, rules, expected], ... - return array( - array( - array('Spanish' => ''), - array('Spanish' => array(array('not_empty', NULL))), + return [ + [ + ['Spanish' => ''], + ['Spanish' => [['not_empty', NULL]]], // Errors are not translated yet so only the label will translate - array('Spanish' => 'Español must not be empty'), - array('Spanish' => 'Spanish must not be empty'), - ), - ); + ['Spanish' => 'Español must not be empty'], + ['Spanish' => 'Spanish must not be empty'] + ], + ]; } /** @@ -459,8 +465,8 @@ public function test_translated_errors($data, $rules, $translated_expected, $unt */ public function test_parameter_labels() { - $validation = Validation::factory(array('foo' => 'bar')) - ->rule('foo', 'equals', array(':value', 'something')) + $validation = Validation::factory(['foo' => 'bar']) + ->rule('foo', 'equals', [':value', 'something']) ->label('something', 'Spanish'); $current = i18n::lang(); @@ -468,8 +474,8 @@ public function test_parameter_labels() $validation->check(); - $translated_expected = array('foo' => 'foo must equal Español'); - $untranslated_expected = array('foo' => 'foo must equal Spanish'); + $translated_expected = ['foo' => 'foo must equal Español']; + $untranslated_expected = ['foo' => 'foo must equal Spanish']; $result_1 = $validation->errors('Validation', TRUE); $result_2 = $validation->errors('Validation', 'en'); @@ -491,12 +497,12 @@ public function test_parameter_labels() */ public function test_arrays_in_parameters() { - $validation = Validation::factory(array('foo' => 'bar')) - ->rule('foo', 'equals', array(':value', array('one', 'two'))); + $validation = Validation::factory(['foo' => 'bar']) + ->rule('foo', 'equals', [':value', ['one', 'two']]); $validation->check(); - $expected = array('foo' => 'foo must equal one, two'); + $expected = ['foo' => 'foo must equal one, two']; $this->assertSame($expected, $validation->errors('Validation', FALSE)); } @@ -509,14 +515,14 @@ public function test_arrays_in_parameters() */ public function test_data_stays_unaltered() { - $validation = Validation::factory(array('foo' => 'bar')) + $validation = Validation::factory(['foo' => 'bar']) ->rule('something', 'not_empty'); $before = $validation->data(); $validation->check(); $after = $validation->data(); - $expected = array('foo' => 'bar'); + $expected = ['foo' => 'bar']; $this->assertSame($expected, $before); $this->assertSame($expected, $after); @@ -530,12 +536,12 @@ public function test_data_stays_unaltered() */ public function test_object_parameters_not_in_messages() { - $validation = Validation::factory(array('foo' => 'foo')) - ->rule('bar', 'matches', array(':validation', ':field', 'foo')); + $validation = Validation::factory(['foo' => 'foo']) + ->rule('bar', 'matches', [':validation', ':field', 'foo']); $validation->check(); $errors = $validation->errors('validation'); - $expected = array('bar' => 'bar must be the same as foo'); + $expected = ['bar' => 'bar must be the same as foo']; $this->assertSame($expected, $errors); } @@ -548,11 +554,7 @@ public function test_object_parameters_not_in_messages() */ public function test_as_array_returns_original_array() { - $data = array( - 'one' => 'hello', - 'two' => 'world', - 'ten' => '', - ); + $data = ['one' => 'hello', 'two' => 'world', 'ten' => '']; $validation = Validation::factory($data); @@ -567,11 +569,7 @@ public function test_as_array_returns_original_array() */ public function test_data_returns_original_array() { - $data = array( - 'one' => 'hello', - 'two' => 'world', - 'ten' => '', - ); + $data = ['one' => 'hello', 'two' => 'world', 'ten' => '']; $validation = Validation::factory($data); @@ -582,11 +580,7 @@ public function test_data_returns_original_array() public function test_offsetExists() // @codingStandardsIgnoreEnd { - $array = array( - 'one' => 'Hello', - 'two' => 'World', - 'ten' => NULL, - ); + $array = ['one' => 'Hello', 'two' => 'World', 'ten' => NULL]; $validation = Validation::factory($array); @@ -601,7 +595,7 @@ public function test_offsetSet_throws_exception() { $this->setExpectedException('Kohana_Exception'); - $validation = Validation::factory(array()); + $validation = Validation::factory([]); // Validation is read-only $validation['field'] = 'something'; @@ -611,11 +605,7 @@ public function test_offsetSet_throws_exception() public function test_offsetGet() // @codingStandardsIgnoreEnd { - $array = array( - 'one' => 'Hello', - 'two' => 'World', - 'ten' => NULL, - ); + $array = ['one' => 'Hello', 'two' => 'World', 'ten' => NULL]; $validation = Validation::factory($array); @@ -630,9 +620,7 @@ public function test_offsetUnset() { $this->setExpectedException('Kohana_Exception'); - $validation = Validation::factory(array( - 'one' => 'Hello, World!', - )); + $validation = Validation::factory(['one' => 'Hello, World!']); // Validation is read-only unset($validation['one']); @@ -646,9 +634,7 @@ public function test_offsetUnset() */ public function test_error_type_check() { - $array = array( - 'email' => 'not an email address', - ); + $array = ['email' => 'not an email address']; $validation = Validation::factory($array) ->rule('email', 'not_empty') @@ -670,22 +656,14 @@ public function test_error_type_check() public function provider_rule_label_regex() { // $data, $field, $rules, $expected - return array( - array( - array( - 'email1' => '', - ), + return [ + [ + ['email1' => ''], 'email1', - array( - array( - 'not_empty' - ) - ), - array( - 'email1' => 'email1 must not be empty' - ), - ) - ); + [['not_empty']], + ['email1' => 'email1 must not be empty'] + ], + ]; } /** diff --git a/system/tests/kohana/ViewTest.php b/system/tests/kohana/ViewTest.php index 6e3669d..2abe0cb 100644 --- a/system/tests/kohana/ViewTest.php +++ b/system/tests/kohana/ViewTest.php @@ -17,7 +17,7 @@ */ class Kohana_ViewTest extends Unittest_TestCase { - protected static $old_modules = array(); + protected static $old_modules = []; /** * Setups the filesystem for test view files @@ -30,9 +30,9 @@ public static function setupBeforeClass() { self::$old_modules = Kohana::modules(); - $new_modules = self::$old_modules + array( + $new_modules = self::$old_modules + [ 'test_views' => realpath(dirname(__FILE__) . '/../test_data/') - ); + ]; Kohana::modules($new_modules); } @@ -55,11 +55,11 @@ public static function teardownAfterClass() */ public function provider_instantiate() { - return array( - array('kohana/error', FALSE), - array('test.css', FALSE), - array('doesnt_exist', TRUE), - ); + return [ + ['kohana/error', FALSE], + ['test.css', FALSE], + ['doesnt_exist', TRUE], + ]; } /** @@ -69,11 +69,11 @@ public function provider_instantiate() */ public function provider_set() { - return array( - array('foo', 'bar', 'foo', 'bar'), - array(array('foo' => 'bar'), NULL, 'foo', 'bar'), - array(new ArrayIterator(array('foo' => 'bar')), NULL, 'foo', 'bar'), - ); + return [ + ['foo', 'bar', 'foo', 'bar'], + [['foo' => 'bar'], NULL, 'foo', 'bar'], + [new ArrayIterator(['foo' => 'bar']), NULL, 'foo', 'bar'], + ]; } /** diff --git a/system/tests/kohana/request/ClientTest.php b/system/tests/kohana/request/ClientTest.php index e004056..7e0e039 100644 --- a/system/tests/kohana/request/ClientTest.php +++ b/system/tests/kohana/request/ClientTest.php @@ -39,9 +39,11 @@ public static function setUpBeforeClass() self::$_original_routes = $routes_prop->getValue('Route'); - $routes = array( - 'ko_request_clienttest' => new Route('//', array('data' => '.+')) - ) + self::$_original_routes; + $routes = [ + 'ko_request_clienttest' => new Route('//', [ + 'data' => '.+' + ]) + ] + self::$_original_routes; $routes_prop->setValue('Route', $routes); } @@ -91,11 +93,11 @@ public function tearDown() */ protected function _dummy_uri($status, $headers, $body) { - $data = array( + $data = [ 'status' => $status, 'header' => $headers, 'body' => $body - ); + ]; return "/requestclientdummy/fake" . '/' . urlencode(http_build_query($data)); } @@ -111,7 +113,7 @@ protected function _dummy_uri($status, $headers, $body) */ protected function _dummy_redirect_uri($status) { - return $this->_dummy_uri($status, array('Location' => $this->_dummy_uri(200, NULL, 'followed')), 'not-followed'); + return $this->_dummy_uri($status, ['Location' => $this->_dummy_uri(200, NULL, 'followed')], 'not-followed'); } /** @@ -120,12 +122,27 @@ protected function _dummy_redirect_uri($status) */ public function provider_follows_redirects() { - return array( - array(TRUE, $this->_dummy_uri(200, NULL, 'not-followed'), 'not-followed'), - array(TRUE, $this->_dummy_redirect_uri(200), 'not-followed'), - array(TRUE, $this->_dummy_redirect_uri(302), 'followed'), - array(FALSE, $this->_dummy_redirect_uri(302), 'not-followed'), - ); + return [ + [ + TRUE, + $this->_dummy_uri(200, NULL, 'not-followed'), + 'not-followed' + ], + [ + TRUE, + $this->_dummy_redirect_uri(200), + 'not-followed' + ], + [ + TRUE, + $this->_dummy_redirect_uri(302), + 'followed'], + [ + FALSE, + $this->_dummy_redirect_uri(302), + 'not-followed' + ], + ]; } /** @@ -139,7 +156,7 @@ public function provider_follows_redirects() */ public function test_follows_redirects($follow, $request_url, $expect_body) { - $response = Request::factory($request_url, array('follow' => $follow)) + $response = Request::factory($request_url, ['follow' => $follow]) ->execute(); $data = json_decode($response->body(), TRUE); @@ -151,16 +168,15 @@ public function test_follows_redirects($follow, $request_url, $expect_body) */ public function test_follows_with_headers() { - $response = Request::factory( - $this->_dummy_redirect_uri(301), array( + $response = Request::factory($this->_dummy_redirect_uri(301), [ 'follow' => TRUE, - 'follow_headers' => array('Authorization', 'X-Follow-With-Value') - )) - ->headers(array( + 'follow_headers' => ['Authorization', 'X-Follow-With-Value'] + ]) + ->headers([ 'Authorization' => 'follow', 'X-Follow-With-Value' => 'follow', 'X-Not-In-Follow' => 'no-follow' - )) + ]) ->execute(); $data = json_decode($response->body(), TRUE); @@ -179,12 +195,11 @@ public function test_follows_with_headers() */ public function test_follow_does_not_add_extra_headers() { - $response = Request::factory( - $this->_dummy_redirect_uri(301), array( + $response = Request::factory($this->_dummy_redirect_uri(301), [ 'follow' => TRUE, - 'follow_headers' => array('Authorization') - )) - ->headers(array()) + 'follow_headers' => ['Authorization'] + ]) + ->headers([]) ->execute(); $data = json_decode($response->body(), TRUE); @@ -200,14 +215,14 @@ public function test_follow_does_not_add_extra_headers() */ public function provider_follows_with_strict_method() { - return array( - array(201, NULL, Request::POST, Request::GET), - array(301, NULL, Request::GET, Request::GET), - array(302, TRUE, Request::POST, Request::POST), - array(302, FALSE, Request::POST, Request::GET), - array(303, NULL, Request::POST, Request::GET), - array(307, NULL, Request::POST, Request::POST), - ); + return [ + [201, NULL, Request::POST, Request::GET], + [301, NULL, Request::GET, Request::GET], + [302, TRUE, Request::POST, Request::POST], + [302, FALSE, Request::POST, Request::GET], + [303, NULL, Request::POST, Request::GET], + [307, NULL, Request::POST, Request::POST], + ]; } /** @@ -223,10 +238,10 @@ public function provider_follows_with_strict_method() */ public function test_follows_with_strict_method($status_code, $strict_redirect, $orig_method, $expect_method) { - $response = Request::factory($this->_dummy_redirect_uri($status_code), array( + $response = Request::factory($this->_dummy_redirect_uri($status_code), [ 'follow' => TRUE, 'strict_redirect' => $strict_redirect - )) + ]) ->method($orig_method) ->execute(); @@ -243,11 +258,11 @@ public function test_follows_with_strict_method($status_code, $strict_redirect, */ public function provider_follows_with_body_if_not_get() { - return array( - array('GET', '301', NULL), - array('POST', '303', NULL), - array('POST', '307', 'foo-bar') - ); + return [ + ['GET', '301', NULL], + ['POST', '303', NULL], + ['POST', '307', 'foo-bar'], + ]; } /** @@ -264,7 +279,9 @@ public function provider_follows_with_body_if_not_get() */ public function test_follows_with_body_if_not_get($original_method, $status, $expect_body) { - $response = Request::factory($this->_dummy_redirect_uri($status), array('follow' => TRUE)) + $response = Request::factory($this->_dummy_redirect_uri($status), [ + 'follow' => TRUE + ]) ->method($original_method) ->body('foo-bar') ->execute(); @@ -282,72 +299,74 @@ public function test_follows_with_body_if_not_get($original_method, $status, $ex */ public function provider_triggers_header_callbacks() { - return array( + return [ // Straightforward response manipulation - array( - array('X-test-1' => - function($request, $response, $client) { - $response->body(json_encode(array('body' => 'test1-body-changed'))); + [ + [ + 'X-test-1' => function($request, $response, $client) { + $response->body(json_encode(['body' => 'test1-body-changed'])); return $response; - }), - $this->_dummy_uri(200, array('X-test-1' => 'foo'), 'test1-body'), + } + ], + $this->_dummy_uri(200, ['X-test-1' => 'foo'], 'test1-body'), 'test1-body-changed' - ), + ], // Subsequent request execution - array( - array('X-test-2' => - function($request, $response, $client) { + [ + [ + 'X-test-2' => function($request, $response, $client) { return Request::factory($response->headers('X-test-2')); - }), - $this->_dummy_uri(200, array('X-test-2' => $this->_dummy_uri(200, NULL, 'test2-subsequent-body')), 'test2-orig-body'), + } + ], + $this->_dummy_uri(200, [ + 'X-test-2' => $this->_dummy_uri(200, NULL, 'test2-subsequent-body') + ], 'test2-orig-body'), 'test2-subsequent-body' - ), + ], // No callbacks triggered - array( - array('X-test-3' => - function ($request, $response, $client) { + [ + [ + 'X-test-3' => function ($request, $response, $client) { throw new Exception("Unexpected execution of X-test-3 callback"); - }), - $this->_dummy_uri(200, array('X-test-1' => 'foo'), 'test3-body'), + } + ], + $this->_dummy_uri(200, ['X-test-1' => 'foo'], 'test3-body'), 'test3-body' - ), + ], // Callbacks not triggered once a previous callback has created a new response - array( - array( - 'X-test-1' => - function($request, $response, $client) { + [ + [ + 'X-test-1' => function($request, $response, $client) { return Request::factory($response->headers('X-test-1')); }, - 'X-test-2' => - function($request, $response, $client) { + 'X-test-2' => function($request, $response, $client) { return Request::factory($response->headers('X-test-2')); } - ), - $this->_dummy_uri(200, array( + ], + $this->_dummy_uri(200, [ 'X-test-1' => $this->_dummy_uri(200, NULL, 'test1-subsequent-body'), 'X-test-2' => $this->_dummy_uri(200, NULL, 'test2-subsequent-body') - ), 'test2-orig-body'), + ], 'test2-orig-body'), 'test1-subsequent-body' - ), + ], // Nested callbacks are supported if callback creates new request - array( - array( - 'X-test-1' => - function($request, $response, $client) { + [ + [ + 'X-test-1' => function($request, $response, $client) { return Request::factory($response->headers('X-test-1')); }, - 'X-test-2' => - function($request, $response, $client) { + 'X-test-2' => function($request, $response, $client) { return Request::factory($response->headers('X-test-2')); } - ), - $this->_dummy_uri(200, array( - 'X-test-1' => $this->_dummy_uri( - 200, array('X-test-2' => $this->_dummy_uri(200, NULL, 'test2-subsequent-body')), 'test1-subsequent-body'), - ), 'test-orig-body'), + ], + $this->_dummy_uri(200, [ + 'X-test-1' => $this->_dummy_uri(200, [ + 'X-test-2' => $this->_dummy_uri(200, NULL, 'test2-subsequent-body') + ], 'test1-subsequent-body') + ], 'test-orig-body'), 'test2-subsequent-body' - ), - ); + ], + ]; } /** @@ -362,7 +381,7 @@ function($request, $response, $client) { */ public function test_triggers_header_callbacks($callbacks, $uri, $expect_body) { - $response = Request::factory($uri, array('header_callbacks' => $callbacks)) + $response = Request::factory($uri, ['header_callbacks' => $callbacks]) ->execute(); $data = json_decode($response->body(), TRUE); @@ -377,26 +396,25 @@ public function test_triggers_header_callbacks($callbacks, $uri, $expect_body) */ public function test_deep_recursive_callbacks_are_aborted() { - $uri = $this->_dummy_uri('200', array('x-cb' => '1'), 'body'); + $uri = $this->_dummy_uri('200', ['x-cb' => '1'], 'body'); // Temporary property to track requests $this->requests_executed = 0; try { - $response = Request::factory( - $uri, array( - 'header_callbacks' => array( - 'x-cb' => - function ($request, $response, $client) { + $response = Request::factory($uri, [ + 'header_callbacks' => [ + 'x-cb' => function ($request, $response, $client) { $client->callback_params('testcase')->requests_executed++; // Recurse into a new request return Request::factory($request->uri()); - }), + } + ], 'max_callback_depth' => 2, - 'callback_params' => array( - 'testcase' => $this, - ) - )) + 'callback_params' => [ + 'testcase' => $this + ] + ]) ->execute(); } catch (Request_Client_Recursion_Exception $e) { // Verify that two requests were executed @@ -429,18 +447,20 @@ public function callback_assert_params($request, $response, $client) public function test_client_can_hold_params_for_callbacks() { // Test with param in constructor - $request = Request::factory( - $this->_dummy_uri( - 302, array('Location' => $this->_dummy_uri('200', array('X-cb' => '1'), 'followed')), 'not-followed'), array( + $request = Request::factory($this->_dummy_uri(302, [ + 'Location' => $this->_dummy_uri('200', [ + 'X-cb' => '1' + ], 'followed') + ], 'not-followed'), [ 'follow' => TRUE, - 'header_callbacks' => array( - 'x-cb' => array($this, 'callback_assert_params'), + 'header_callbacks' => [ + 'x-cb' => [$this, 'callback_assert_params'], 'location' => 'Request_Client::on_header_location', - ), - 'callback_params' => array( + ], + 'callback_params' => [ 'constructor_param' => 'foo' - ) - )); + ] + ]); // Test passing param to setter $request->client()->callback_params('setter_param', 'bar'); @@ -469,13 +489,13 @@ public function action_fake() { parse_str(urldecode($this->request->param('data')), $data); $this->response->status(Arr::get($data, 'status', 200)); - $this->response->headers(Arr::get($data, 'header', array())); - $this->response->body(json_encode(array( + $this->response->headers(Arr::get($data, 'header', [])); + $this->response->body(json_encode([ 'body' => Arr::get($data, 'body', 'ok'), 'rq_headers' => $this->request->headers(), 'rq_body' => $this->request->body(), 'rq_method' => $this->request->method(), - ))); + ])); } } diff --git a/system/tests/kohana/request/client/ExternalTest.php b/system/tests/kohana/request/client/ExternalTest.php index 74e582a..1c7edd3 100644 --- a/system/tests/kohana/request/client/ExternalTest.php +++ b/system/tests/kohana/request/client/ExternalTest.php @@ -27,33 +27,17 @@ public function provider_factory() { Request_Client_External::$client = 'Request_Client_Stream'; - $return = array( - array( - array(), - NULL, - 'Request_Client_Stream' - ), - array( - array(), - 'Request_Client_Stream', - 'Request_Client_Stream' - ) - ); + $return = [ + [[], NULL, 'Request_Client_Stream'], + [[], 'Request_Client_Stream', 'Request_Client_Stream'], + ]; if (extension_loaded('curl')) { - $return[] = array( - array(), - 'Request_Client_Curl', - 'Request_Client_Curl' - ); + $return[] = [[], 'Request_Client_Curl', 'Request_Client_Curl']; } if (extension_loaded('http')) { - $return[] = array( - array(), - 'Request_Client_HTTP', - 'Request_Client_HTTP' - ); + $return[] = [[], 'Request_Client_HTTP', 'Request_Client_HTTP']; } return $return; @@ -61,12 +45,12 @@ public function provider_factory() /** * Tests the [Request_Client_External::factory()] method - * + * * @dataProvider provider_factory * - * @param array $params params - * @param string $client client - * @param Request_Client_External $expected expected + * @param array $params params + * @param string $client client + * @param Request_Client_External $expected expected * @return void */ public function test_factory($params, $client, $expected) @@ -81,38 +65,38 @@ public function test_factory($params, $client, $expected) */ public function provider_options() { - return array( - array( + return [ + [ NULL, NULL, - array() - ), - array( - array('foo' => 'bar', 'stfu' => 'snafu'), + [] + ], + [ + ['foo' => 'bar', 'stfu' => 'snafu'], NULL, - array('foo' => 'bar', 'stfu' => 'snafu') - ), - array( + ['foo' => 'bar', 'stfu' => 'snafu'] + ], + [ 'foo', 'bar', - array('foo' => 'bar') - ), - array( - array('foo' => 'bar'), + ['foo' => 'bar'] + ], + [ + ['foo' => 'bar'], 'foo', - array('foo' => 'bar') - ) - ); + ['foo' => 'bar'] + ], + ]; } /** * Tests the [Request_Client_External::options()] method * * @dataProvider provider_options - * - * @param mixed $key key - * @param mixed $value value - * @param array $expected expected + * + * @param mixed $key key + * @param mixed $value value + * @param array $expected expected * @return void */ public function test_options($key, $value, $expected) @@ -132,35 +116,35 @@ public function test_options($key, $value, $expected) public function provider_execute() { $json = '{"foo": "bar", "snafu": "stfu"}'; - $post = array('foo' => 'bar', 'snafu' => 'stfu'); + $post = ['foo' => 'bar', 'snafu' => 'stfu']; - return array( - array( + return [ + [ 'application/json', $json, - array(), - array( + [], + [ 'content-type' => 'application/json', 'body' => $json - ) - ), - array( + ] + ], + [ 'application/json', $json, $post, - array( + [ 'content-type' => 'application/x-www-form-urlencoded; charset=' . Kohana::$charset, 'body' => http_build_query($post, NULL, '&') - ) - ) - ); + ] + ], + ]; } /** * Tests the [Request_Client_External::_send_message()] method * * @dataProvider provider_execute - * + * * @return void */ public function test_execute($content_type, $body, $post, $expected) diff --git a/system/tests/kohana/request/client/InternalTest.php b/system/tests/kohana/request/client/InternalTest.php index f2c988e..62fc175 100644 --- a/system/tests/kohana/request/client/InternalTest.php +++ b/system/tests/kohana/request/client/InternalTest.php @@ -44,11 +44,29 @@ public function tearDown() public function provider_response_failure_status() { - return array( - array('', 'Welcome', 'missing_action', 'Welcome/missing_action', 404), - array('kohana3', 'missing_controller', 'index', 'kohana3/missing_controller/index', 404), - array('', 'Template', 'missing_action', 'kohana3/Template/missing_action', 500), - ); + return [ + [ + '', + 'Welcome', + 'missing_action', + 'Welcome/missing_action', + 404 + ], + [ + 'kohana3', + 'missing_controller', + 'index', + 'kohana3/missing_controller/index', + 404 + ], + [ + '', + 'Template', + 'missing_action', + 'kohana3/Template/missing_action', + 500 + ], + ]; } /** diff --git a/system/tests/test_data/callback_routes.php b/system/tests/test_data/callback_routes.php index 32a285a..8a1f082 100644 --- a/system/tests/test_data/callback_routes.php +++ b/system/tests/test_data/callback_routes.php @@ -17,7 +17,7 @@ class Route_Holder */ public static function default_callback($uri) { - + } /** @@ -27,8 +27,7 @@ public static function default_callback($uri) */ public static function default_return_callback($uri) { - return array( - ); + return []; } /** @@ -38,10 +37,10 @@ public static function default_return_callback($uri) */ public static function matches_returns_array_of_parameters_on_successful_match($uri) { - return array( + return [ 'controller' => 'welcome', 'action' => 'index', - ); + ]; } /** @@ -52,10 +51,10 @@ public static function matches_returns_array_of_parameters_on_successful_match($ public static function required_parameters_are_needed($uri) { if (substr($uri, 0, 5) == 'admin') { - return array( + return [ 'controller' => 'foo', 'action' => 'bar', - ); + ]; } } @@ -67,8 +66,7 @@ public static function required_parameters_are_needed($uri) public static function reverse_routing_returns_routes_uri_if_route_is_static($uri) { if ($uri == 'info/about_us') { - return array( - ); + return []; } } diff --git a/system/tests/test_data/message_tests/bottom_module/messages/kohana_core_message_tests.php b/system/tests/test_data/message_tests/bottom_module/messages/kohana_core_message_tests.php index 8eec4f0..63a1c21 100644 --- a/system/tests/test_data/message_tests/bottom_module/messages/kohana_core_message_tests.php +++ b/system/tests/test_data/message_tests/bottom_module/messages/kohana_core_message_tests.php @@ -1,7 +1,7 @@ 'inherited bottom message', 'cfs_replaced' => 'inherited cfs_replaced message', -); +]; diff --git a/system/tests/test_data/message_tests/top_module/messages/kohana_core_message_tests.php b/system/tests/test_data/message_tests/top_module/messages/kohana_core_message_tests.php index 1348926..5a166c0 100644 --- a/system/tests/test_data/message_tests/top_module/messages/kohana_core_message_tests.php +++ b/system/tests/test_data/message_tests/top_module/messages/kohana_core_message_tests.php @@ -1,7 +1,7 @@ 'top only message', 'cfs_replaced' => 'overriding cfs_replaced message', -); +];