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

Appearance settings

Commit 49a2a27

Browse filesBrowse files
committed
feature #5127 [VarDumper] Add doc for assertDump* assertions (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [VarDumper] Add doc for assertDump* assertions | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | 2.7 | Fixed tickets | - Commits ------- 328e481 [VarDumper] Add doc for assertDump* assertions
2 parents 1cb47ab + 328e481 commit 49a2a27
Copy full SHA for 49a2a27

File tree

Expand file treeCollapse file tree

1 file changed

+47
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+47
-0
lines changed

‎components/var_dumper/introduction.rst

Copy file name to clipboardExpand all lines: components/var_dumper/introduction.rst
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,53 @@ original value. You can configure the limits in terms of:
122122
<config max-items="250" max-string-length="-1" />
123123
</container>
124124
125+
Using the VarDumper Component in your PHPUnit Test Suite
126+
--------------------------------------------------------
127+
128+
.. versionadded:: 2.7
129+
The :class:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait` was
130+
introduced in Symfony 2.7.
131+
132+
The VarDumper component provides
133+
:class:`a trait <Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait>`
134+
that can help writing some of your tests for PHPUnit.
135+
136+
This will provide you with two new assertions:
137+
138+
:method:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait::assertDumpEquals`
139+
verifies that the dump of the variable given as the second argument matches
140+
the expected dump provided as a string in the first argument.
141+
142+
:method:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait::assertDumpMatchesFormat`
143+
is like the previous method but accepts placeholders in the expected dump,
144+
based on the ``assertStringMatchesFormat`` method provided by PHPUnit.
145+
146+
Example::
147+
148+
class ExampleTest extends \PHPUnit_Framework_TestCase
149+
{
150+
use \Symfony\Component\VarDumper\Test\VarDumperTestTrait;
151+
152+
public function testWithDumpEquals()
153+
{
154+
$testedVar = array(123, 'foo');
155+
156+
$expectedDump = <<<EOTXT
157+
array:2 [
158+
0 => 123
159+
1 => "foo"
160+
]
161+
EOTXT;
162+
163+
$this->assertDumpEquals($expectedDump, $testedVar);
164+
}
165+
}
166+
167+
.. tip::
168+
169+
If you still use PHP 5.3, you can extend the
170+
:class:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestClass` instead.
171+
125172
Dump Examples and Output
126173
------------------------
127174

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.