File tree Expand file tree Collapse file tree 4 files changed +101
-0
lines changed
Expand file tree Collapse file tree 4 files changed +101
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ Provides helper traits for PHPUnit.
2323 - [ ` $this->getPrivateProperty() ` ] ( #this-getprivateproperty )
2424 - [ ` $this->setPrivateProperty() ` ] ( #this-setprivateproperty )
2525 - [ ` $this->getPrivateMethodInvoker() ` ] ( #this-getprivatemethodinvoker )
26+ - [ ` DebugHelper ` ] ( #debughelper )
2627- [ License] ( #license )
2728
2829<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -339,6 +340,28 @@ $this->assertEquals(
339340);
340341~~~
341342
343+ ### ` DebugHelper `
344+
345+ This trait provides helper functions, ` dd() ` and ` d() ` to dump variables.
346+
347+ Import the ` Kenjis\PhpUnitHelper\DebugHelper ` trait into your test class:
348+
349+ ``` php
350+ <?php
351+
352+ declare(strict_types=1);
353+
354+ namespace Foo\Bar\Test\Unit;
355+
356+ use Kenjis\PhpUnitHelper\DebugHelper;
357+ use PHPUnit\Framework;
358+
359+ final class BazTest extends Framework\TestCase
360+ {
361+ use DebugHelper;
362+ }
363+ ```
364+
342365## License
343366
344367This package is licensed using the MIT License.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Kenjis \PhpUnitHelper ;
6+
7+ require_once __DIR__ . '/functions.php ' ; // @codeCoverageIgnore
8+
9+ trait DebugHelper
10+ {
11+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Helper Functions
5+ */
6+
7+ declare (strict_types=1 );
8+
9+ /**
10+ * @SuppressWarnings(PHPMD.ExitExpression)
11+ * Does not work if I move to the function annotation
12+ * See https://github.com/phpmd/phpmd/issues/337
13+ */
14+ if (! function_exists ('dd ' )) { // @codeCoverageIgnore
15+
16+ /**
17+ * Alias of var_dump() and exit()
18+ *
19+ * @param mixed ...$vars
20+ *
21+ * @psalm-suppress ForbiddenCode Unsafe var_dump
22+ * @codeCoverageIgnore
23+ */
24+ function dd (...$ vars ): void
25+ {
26+ var_dump (...$ vars );
27+ exit ;
28+ }
29+ }
30+
31+ if (! function_exists ('d ' )) { // @codeCoverageIgnore
32+
33+ /**
34+ * Alias of var_dump()
35+ *
36+ * @param mixed ...$vars
37+ *
38+ * @psalm-suppress ForbiddenCode Unsafe var_dump
39+ */
40+ function d (...$ vars ): void
41+ {
42+ var_dump (...$ vars );
43+ }
44+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Kenjis \PhpUnitHelper ;
6+
7+ use PHPUnit \Framework \TestCase ;
8+
9+ class DebugHelperTest extends TestCase
10+ {
11+ use DebugHelper;
12+
13+ public function test_d (): void
14+ {
15+ $ this ->expectOutputRegex (
16+ '/string\(4\) "var1"\n*.*\nint\(100\)\n/ '
17+ );
18+
19+ $ var1 = 'var1 ' ;
20+ $ var2 = 100 ;
21+ d ($ var1 , $ var2 );
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments