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

[VarDumper] Add doc for assertDump* assertions #5127

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 1 commit into from
May 25, 2015
Merged
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
[VarDumper] Add doc for assertDump* assertions
  • Loading branch information
nicolas-grekas committed May 24, 2015
commit 328e481f98f941bf626077c39af29cd750381014
47 changes: 47 additions & 0 deletions 47 components/var_dumper/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,53 @@ original value. You can configure the limits in terms of:
<config max-items="250" max-string-length="-1" />
</container>

Using the VarDumper Component in your PHPUnit Test Suite
--------------------------------------------------------

.. versionadded:: 2.7
The :class:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait` was
introduced in Symfony 2.7.

The VarDumper component provides
:class:`a trait <Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait>`
that can help writing some of your tests for PHPUnit.

This will provide you with two new assertions:

:method:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait::assertDumpEquals`
verifies that the dump of the variable given as the second argument matches
the expected dump provided as a string in the first argument.

:method:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait::assertDumpMatchesFormat`
is like the previous method but accepts placeholders in the expected dump,
based on the ``assertStringMatchesFormat`` method provided by PHPUnit.

Example::

class ExampleTest extends \PHPUnit_Framework_TestCase
{
use \Symfony\Component\VarDumper\Test\VarDumperTestTrait;

public function testWithDumpEquals()
{
$testedVar = array(123, 'foo');

$expectedDump = <<<EOTXT
array:2 [
0 => 123
1 => "foo"
]
EOTXT;

$this->assertDumpEquals($expectedDump, $testedVar);
}
}

.. tip::

If you still use PHP 5.3, you can extend the
:class:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestClass` instead.

Dump Examples and Output
------------------------

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.