Skip to content

Commit 6bd5e6e

Browse files
weaverryanjaviereguiluz
authored andcommitted
[symfony#4243] Tweaks to the new var-dumper component
1 parent 8335f4d commit 6bd5e6e

File tree

2 files changed

+72
-20
lines changed

2 files changed

+72
-20
lines changed

components/var_dumper/advanced.rst

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,33 @@ corresponding Data object could represent only a subset of the cloned variable.
5050
Before calling :method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::cloneVar`,
5151
you can configure these limits:
5252

53-
* :method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::setMaxItems`
54-
configures the maximum number of items that will be cloned
55-
*past the first nesting level*. Items are counted using a breadth-first
56-
algorithm so that lower level items have higher priority than deeply nested
57-
items;
58-
* :method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::setMaxString`
59-
configures the maximum number of characters that will be cloned before
60-
cutting overlong strings;
61-
* in both cases, specifying `-1` removes any limit.
53+
:method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::setMaxItems`
54+
configures the maximum number of items that will be cloned
55+
*past the first nesting level*. Items are counted using a breadth-first
56+
algorithm so that lower level items have higher priority than deeply nested
57+
items;
58+
59+
:method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::setMaxString`
60+
configures the maximum number of characters that will be cloned before
61+
cutting overlong strings;
62+
63+
In both cases, specifying ``-1`` removes any limit.
6264

6365
Before dumping it, you can further limit the resulting
64-
:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object by calling its
65-
:method:`Symfony\\Component\\VarDumper\\Cloner\\Data::getLimitedClone`
66-
method:
67-
68-
* the first ``$maxDepth`` argument allows limiting dumps in the depth dimension,
69-
* the second ``$maxItemsPerDepth`` limits the number of items per depth level,
70-
* and the last ``$useRefHandles`` defaults to ``true``, but allows removing
71-
internal objects' handles for sparser output,
72-
* but unlike the previous limits on cloners that remove data on purpose,
73-
these can be changed back and forth before dumping since they do not affect
74-
the intermediate representation internally.
66+
:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object using the following methods:
67+
68+
:method:`Symfony\\Component\\VarDumper\\Cloner\\Data::withMaxDepth`
69+
Allows limiting dumps in the depth dimension.
70+
71+
:method:`Symfony\\Component\\VarDumper\\Cloner\\Data::withMaxItemsPerDepth`
72+
Limits the number of items per depth level.
73+
74+
:method:`Symfony\\Component\\VarDumper\\Cloner\\Data::withRefHandles`
75+
Allows removing internal objects' handles for sparser output (useful for tests).
76+
77+
Unlike the previous limits on cloners that remove data on purpose, these can
78+
be changed back and forth before dumping since they do not affect the
79+
intermediate representation internally.
7580

7681
.. note::
7782

components/var_dumper/introduction.rst

Lines 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)