8000 [VarDumper] Allow VarDumperTestTrait expectation to be non-scalar · symfony/symfony@5b04647 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b04647

Browse files
committed
[VarDumper] Allow VarDumperTestTrait expectation to be non-scalar
1 parent 3ce9c29 commit 5b04647

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
*/
2020
trait VarDumperTestTrait
2121
{
22-
public function assertDumpEquals($dump, $data, $filter = 0, $message = '')
22+
public function assertDumpEquals($expected, $data, $filter = 0, $message = '')
2323
{
24-
$this->assertSame(rtrim($dump), $this->getDump($data, null, $filter), $message);
24+
$this->assertSame($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message);
2525
}
2626

27-
public function assertDumpMatchesFormat($dump, $data, $filter = 0, $message = '')
27+
public function assertDumpMatchesFormat($expected, $data, $filter = 0, $message = '')
2828
{
29-
$this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data, null, $filter), $message);
29+
$this->assertStringMatchesFormat($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message);
3030
}
3131

3232
protected function getDump($data, $key = null, $filter = 0)
@@ -45,4 +45,13 @@ protected function getDump($data, $key = null, $filter = 0)
4545

4646
return rtrim($dumper->dump($data, true));
4747
}
48+
49+
private function prepareExpectation($expected, $filter)
50+
{
51+
if (!is_string($expected)) {
52+
$expected = $this->getDump($expected, null, $filter);
53+
}
54+
55+
return rtrim($expected);
56+
}
4857
}

src/Symfony/Component/VarDumper/Tests/Test/VarDumperTestTraitTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ public function testItComparesLargeData()
3838

3939
$this->assertDumpEquals($expected, $data);
4040
}
41+
42+
public function testAllowsNonScalarExpectation()
43+
{
44+
$this->assertDumpEquals(new \ArrayObject(['bim' => 'bam']), new \ArrayObject(['bim' => 'bam']));
45+
}
4146
}

0 commit comments

Comments
 (0)
0