8000 [VarDumper] Allow VarDumperTestTrait expectation to be non-scalar by romainneutron · Pull Request #25332 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] Allow VarDumperTestTrait expectation to be non-scalar #25332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
*/
trait VarDumperTestTrait
{
public function assertDumpEquals($dump, $data, $filter = 0, $message = '')
public function assertDumpEquals($expected, $data, $filter = 0, $message = '')
{
$this->assertSame(rtrim($dump), $this->getDump($data, null, $filter), $message);
$this->assertSame($this->prepareExpectation($expected, $filter), $this->getDump($data, null, $filter), $message);
}

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

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

return rtrim($dumper->dump($data, true));
}

private function prepareExpectation($expected, $filter)
{
if (!is_string($expected)) {
$expected = $this->getDump($expected, null, $filter);
}

return rtrim($expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public function testItComparesLargeData()

$this->assertDumpEquals($expected, $data);
}

public function testAllowsNonScalarExpectation()
{
$this->assertDumpEquals(new \ArrayObject(array('bim' => 'bam')), new \ArrayObject(array('bim' => 'bam')));
}
}
0