Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd4c849

Browse files
committed
feature#25332 [VarDumper] Allow VarDumperTestTrait expectation to be non-scalar (romainneutron)
This PR was merged into the 4.1-dev branch.Discussion----------[VarDumper] Allow VarDumperTestTrait expectation to be non-scalar| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| License | MITAt the moment, when using the `VarDumperTestTrait` in unit test, expecting data object is as follow:```phpclass Toto{ private $foo; public function __construct($foo) { $this->foo = $foo; }}class MyTest extends \PHPUnit_Framework_TestCase{ use Symfony\Component\VarDumper\Test\VarDumperTestTrait; public function dummyTest() { $expected = <<<EOEXPECTEDProfiler\Tests\Model\CallGraph\Toto { -foo: "baz"}EOEXPECTED; $this->assertDumpEquals($expected, new Toto('baz')); }}```The same test could be easily written like this with this change:```php public function dummyTest() { $this->assertDumpEquals(new Toto('baz'), new Toto('baz')); }```Commits-------6b5ab90 [VarDumper] Allow VarDumperTestTrait expectation to be non-scalar
2 parents8a12eb3 +6b5ab90 commitcd4c849

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-
publicfunctionassertDumpEquals($dump,$data,$filter =0,$message ='')
22+
publicfunctionassertDumpEquals($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-
publicfunctionassertDumpMatchesFormat($dump,$data,$filter =0,$message ='')
27+
publicfunctionassertDumpMatchesFormat($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
protectedfunctiongetDump($data,$key =null,$filter =0)
@@ -45,4 +45,13 @@ protected function getDump($data, $key = null, $filter = 0)
4545

4646
returnrtrim($dumper->dump($data,true));
4747
}
48+
49+
privatefunctionprepareExpectation($expected,$filter)
50+
{
51+
if (!is_string($expected)) {
52+
$expected =$this->getDump($expected,null,$filter);
53+
}
54+
55+
returnrtrim($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+
publicfunctiontestAllowsNonScalarExpectation()
43+
{
44+
$this->assertDumpEquals(new \ArrayObject(array('bim' =>'bam')),new \ArrayObject(array('bim' =>'bam')));
45+
}
4146
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp