Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a3abf5

Browse files
feature #22588 [VarDumper] Add filter in VarDumperTestTrait (maidmaid)
This PR was merged into the 3.4 branch. Discussion ---------- [VarDumper] Add filter in VarDumperTestTrait | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | / | License | MIT | Doc PR | / Many casters uses ``EXCLUDE_*`` flags in their cast method. It would be usefull to use this flags directly with ``VarDumperTestTrait`` to tests many cases. Commits ------- 1da8e71 Add filter in VarDumperTestTrait
2 parents 73d3d40 + 1da8e71 commit 5a3abf5

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

UPGRADE-4.0.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,39 @@ Validator
567567
changed to `true` as of 4.0. If you need the previous behaviour ensure to
568568
set the option to `false`.
569569

570+
VarDumper
571+
---------
572+
573+
* The `VarDumperTestTrait::assertDumpEquals()` method expects a 3rd `$context = null`
574+
argument and moves `$message = ''` argument at 4th position.
575+
576+
Before:
577+
578+
```php
579+
VarDumperTestTrait::assertDumpEquals($dump, $data, $message = '');
580+
```
581+
582+
After:
583+
584+
```php
585+
VarDumperTestTrait::assertDumpEquals($dump, $data, $filter = 0, $message = '');
586+
```
587+
588+
* The `VarDumperTestTrait::assertDumpMatchesFormat()` method expects a 3rd `$context = null`
589+
argument and moves `$message = ''` argument at 4th position.
590+
591+
Before:
592+
593+
```php
594+
VarDumperTestTrait::assertDumpMatchesFormat($dump, $data, $message = '');
595+
```
596+
597+
After:
598+
599+
```php
600+
VarDumperTestTrait::assertDumpMatchesFormat($dump, $data, $filter = 0, $message = '');
601+
```
602+
570603
Workflow
571604
--------
572605

src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@
1919
*/
2020
trait VarDumperTestTrait
2121
{
22-
public function assertDumpEquals($dump, $data, $message = '')
22+
public function assertDumpEquals($dump, $data, $filter = 0, $message = '')
2323
{
24-
$this->assertSame(rtrim($dump), $this->getDump($data), $message);
24+
if (is_string($filter)) {
25+
@trigger_error(sprintf('The $message argument of the "%s()" method at 3rd position is deprecated since version 3.4 and will be moved at 4th position in 4.0.', __METHOD__), E_USER_DEPRECATED);
26+
$message = $filter;
27+
$filter = 0;
28+
}
29+
30+
$this->assertSame(rtrim($dump), $this->getDump($data, null, $filter), $message);
2531
}
2632

27-
public function assertDumpMatchesFormat($dump, $data, $message = '')
33+
public function assertDumpMatchesFormat($dump, $data, $filter = 0, $message = '')
2834
{
29-
$this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data), $message);
35+
if (is_string($filter)) {
36+
@trigger_error(sprintf('The $message argument of the "%s()" method at 3rd position is deprecated since version 3.4 and will be moved at 4th position in 4.0.', __METHOD__), E_USER_DEPRECATED);
37+
$message = $filter;
38+
$filter = 0;
39+
}
40+
41+
$this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data, null, $filter), $message);
3042
}
3143

32-
protected function getDump($data, $key = null)
44+
protected function getDump($data, $key = null, $filter = 0)
3345
{
3446
$flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
3547
$flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
@@ -38,7 +50,7 @@ protected function getDump($data, $key = null)
3850
$cloner->setMaxItems(-1);
3951
$dumper = new CliDumper(null, null, $flags);
4052
$dumper->setColors(false);
41-
$data = $cloner->cloneVar($data)->withRefHandles(false);
53+
$data = $cloner->cloneVar($data, $filter)->withRefHandles(false);
4254
if (null !== $key && null === $data = $data->seek($key)) {
4355
return;
4456
}

0 commit comments

Comments
 (0)