Skip to content

Commit 5c4f5ec

Browse files
committed
Dumper: uses short array syntax []
1 parent 590de09 commit 5c4f5ec

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

src/Framework/Dumper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public static function toLine($var)
7070
break;
7171
}
7272
$out .= ($k === $counter ? '' : self::toLine($k) . ' => ')
73-
. (is_array($v) && $v ? 'array(...)' : self::toLine($v));
73+
. (is_array($v) && $v ? '[...]' : self::toLine($v));
7474
$counter = is_int($k) ? max($k + 1, $counter) : $counter;
7575
}
76-
return "array($out)";
76+
return "[$out]";
7777

7878
} elseif ($var instanceof \Exception || $var instanceof \Throwable) {
7979
return 'Exception ' . get_class($var) . ': ' . ($var->getCode() ? '#' . $var->getCode() . ' ' : '') . $var->getMessage();
@@ -190,7 +190,7 @@ private static function _toPhp(&$var, & $list = [], $level = 0, & $line = 1)
190190
$out = $outShort;
191191
}
192192
}
193-
return 'array(' . $out . ')';
193+
return '[' . $out . ']';
194194

195195
} elseif ($var instanceof \Closure) {
196196
$rc = new \ReflectionFunction($var);
@@ -229,8 +229,8 @@ private static function _toPhp(&$var, & $list = [], $level = 0, & $line = 1)
229229
}
230230
$hash = self::hash($var);
231231
return $class === 'stdClass'
232-
? "(object) /* $hash */ array($out)"
233-
: "$class::__set_state(/* $hash */ array($out))";
232+
? "(object) /* $hash */ [$out]"
233+
: "$class::__set_state(/* $hash */ [$out])";
234234

235235
} elseif (is_resource($var)) {
236236
return '/* resource ' . get_resource_type($var) . ' */';

src/Framework/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function runTest($method, array $args = NULL)
166166
}
167167

168168
} catch (AssertException $e) {
169-
throw $e->setMessage("$e->origMessage in {$method->getName()}" . (substr(Dumper::toLine($params), 5)));
169+
throw $e->setMessage("$e->origMessage in {$method->getName()}(" . (substr(Dumper::toLine($params), 1, -1)) . ')');
170170
}
171171
}
172172
}

tests/Framework/Assert.type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $cases = [
2525
['list', NULL, 'NULL should be list'],
2626
['list', []],
2727
['list', [1]],
28-
['list', [4 => 1], 'array(4 => 1) should be list'],
28+
['list', [4 => 1], '[4 => 1] should be list'],
2929
];
3030

3131
foreach ($cases as $case) {

tests/Framework/Dumper.dumpException.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ require __DIR__ . '/../bootstrap.php';
66

77

88
$cases = [
9-
'Failed: array(TRUE) should contain 1' => function () { Assert::contains(1, [TRUE]); },
10-
"Failed: array('') should not contain ''" => function () { Assert::notContains('', ['']); },
9+
'Failed: [TRUE] should contain 1' => function () { Assert::contains(1, [TRUE]); },
10+
"Failed: [''] should not contain ''" => function () { Assert::notContains('', ['']); },
1111
'Failed: 1.0 should be equal to 1' => function () { Assert::equal(1, 1.0); },
1212
'Failed: 0.33%d% should not be equal to 0.33%d%' => function () { Assert::notEqual(1 / 3, 1 - 2 / 3); },
1313
'Failed: NULL should be FALSE' => function () { Assert::false(NULL); },
1414
'Failed: FALSE should be TRUE' => function () { Assert::true(FALSE); },
1515
'Failed: 0 should be NULL' => function () { Assert::null(0); },
16-
"Failed: array('b' => FALSE, 'a' => TRUE) should be falsey" => function () { Assert::falsey(['b' => FALSE, 'a' => TRUE]); },
16+
"Failed: ['b' => FALSE, 'a' => TRUE] should be falsey" => function () { Assert::falsey(['b' => FALSE, 'a' => TRUE]); },
1717
'Failed: SimpleXMLElement(#%a%) should be truthy' => function () { Assert::truthy(new SimpleXMLElement('<xml></xml>')); },
1818
'Failed: stdClass(#%a%) should be stdClass(#%a%)' => function () { Assert::same(new stdClass, new stdClass); },
1919
'Failed: NULL should not be NULL' => function () { Assert::notSame(NULL, NULL); },

tests/Framework/Dumper.toLine.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ if (PHP_VERSION_ID >= 50500) {
3131
Assert::match('DateTimeImmutable(2014-02-13 12:34:56 +0300)(#%a%)', Dumper::toLine(new DateTimeImmutable('2014-02-13 12:34:56 +0300')));
3232
}
3333

34-
Assert::match('array()', Dumper::toLine([]));
35-
Assert::match("array(1, 2, 3, 4, 'x')", Dumper::toLine([1, 2, 3, 4, 'x']));
36-
Assert::match('array(1 => 1, 2, 3)', Dumper::toLine([1 => 1, 2, 3]));
37-
Assert::match("array('a' => array(...))", Dumper::toLine(['a' => [1, 2]]));
38-
Assert::match("array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', ...)", Dumper::toLine(['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']));
34+
Assert::match('[]', Dumper::toLine([]));
35+
Assert::match("[1, 2, 3, 4, 'x']", Dumper::toLine([1, 2, 3, 4, 'x']));
36+
Assert::match('[1 => 1, 2, 3]', Dumper::toLine([1 => 1, 2, 3]));
37+
Assert::match("['a' => [...]]", Dumper::toLine(['a' => [1, 2]]));
38+
Assert::match("['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', ...]", Dumper::toLine(['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']));

tests/Framework/Dumper.toPhp.phpt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ Assert::match("' '", Dumper::toPhp("\t"));
2929
Assert::match('"\\xff"', Dumper::toPhp("\xFF"));
3030
Assert::match('"multi\nline"', Dumper::toPhp("multi\nline"));
3131
Assert::match("'Iñtërnâtiônàlizætiøn'", Dumper::toPhp("I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3\xb8n"));
32-
Assert::match('array(
32+
Assert::match('[
3333
1,
3434
\'hello\',
35-
"\r" => array(),
36-
array(1, 2),
37-
array(1 => 1, 2, 3, 4, 5, 6, 7),
38-
)', Dumper::toPhp([1, 'hello', "\r" => [], [1, 2], [1 => 1, 2, 3, 4, 5, 6, 7]]));
35+
"\r" => [],
36+
[1, 2],
37+
[1 => 1, 2, 3, 4, 5, 6, 7, \'abcdefgh\'],
38+
]', Dumper::toPhp([1, 'hello', "\r" => [], [1, 2], [1 => 1, 2, 3, 4, 5, 6, 7, 'abcdefgh']]));
3939

4040
Assert::match('/* resource stream */', Dumper::toPhp(fopen(__FILE__, 'r')));
41-
Assert::match('(object) /* #%a% */ array()', Dumper::toPhp((object) NULL));
42-
Assert::match("(object) /* #%a% */ array(
41+
Assert::match('(object) /* #%a% */ []', Dumper::toPhp((object) NULL));
42+
Assert::match("(object) /* #%a% */ [
4343
'a' => 'b',
44-
)", Dumper::toPhp((object) ['a' => 'b']));
44+
]", Dumper::toPhp((object) ['a' => 'b']));
4545

46-
Assert::match("Test::__set_state(/* #%a% */ array(
47-
'x' => array(10, NULL),
46+
Assert::match("Test::__set_state(/* #%a% */ [
47+
'x' => [10, NULL],
4848
'y' => 'hello',
4949
'z' => 30.0,
50-
))", Dumper::toPhp(new Test));
50+
])", Dumper::toPhp(new Test));
5151

5252
Assert::match('/* Closure defined in file %a% on line %d% */', Dumper::toPhp(function () {}));

tests/Framework/Dumper.toPhp.recursion.phpt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ require __DIR__ . '/../bootstrap.php';
88

99
$arr = [1, 2, 3];
1010
$arr[] = & $arr;
11-
Assert::match('array(
11+
Assert::match('[
1212
1,
1313
2,
1414
3,
15-
array(1, 2, 3, /* Nesting level too deep or recursive dependency */),
16-
)', Dumper::toPhp($arr));
15+
[1, 2, 3, /* Nesting level too deep or recursive dependency */],
16+
]', Dumper::toPhp($arr));
1717

1818

1919
$obj = (object) ['x' => 1, 'y' => 2];
2020
$obj->z = & $obj;
21-
Assert::match("(object) /* #%a% */ array(
21+
Assert::match("(object) /* #%a% */ [
2222
'x' => 1,
2323
'y' => 2,
2424
'z' => /* stdClass dumped on line 1 */,
25-
)", Dumper::toPhp($obj));
25+
]", Dumper::toPhp($obj));
2626

2727

2828
$var = [
@@ -32,19 +32,19 @@ $var = [
3232
$empty,
3333
$obj,
3434
];
35-
Assert::match("array(
36-
array(
35+
Assert::match("[
36+
[
3737
1,
3838
2,
3939
3,
40-
array(1, 2, 3, /* Nesting level too deep or recursive dependency */),
41-
),
42-
(object) /* #%a% */ array(),
43-
(object) /* #%a% */ array(
40+
[1, 2, 3, /* Nesting level too deep or recursive dependency */],
41+
],
42+
(object) /* #%a% */ [],
43+
(object) /* #%a% */ [
4444
'x' => 1,
4545
'y' => 2,
4646
'z' => /* stdClass dumped on line 9 */,
47-
),
48-
(object) /* #%a% */ array(),
47+
],
48+
(object) /* #%a% */ [],
4949
/* stdClass dumped on line 9 */,
50-
)", Dumper::toPhp($var));
50+
]", Dumper::toPhp($var));

0 commit comments

Comments
 (0)