-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kenjis/add-dd
Add dd() and d()
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kenjis\PhpUnitHelper; | ||
|
||
require_once __DIR__ . '/functions.php'; // @codeCoverageIgnore | ||
|
||
trait DebugHelper | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* Helper Functions | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.ExitExpression) | ||
* Does not work if I move to the function annotation | ||
* See https://github.com/phpmd/phpmd/issues/337 | ||
*/ | ||
if (! function_exists('dd')) { // @codeCoverageIgnore | ||
|
||
/** | ||
* Alias of var_dump() and exit() | ||
* | ||
* @param mixed ...$vars | ||
* | ||
* @psalm-suppress ForbiddenCode Unsafe var_dump | ||
* @codeCoverageIgnore | ||
*/ | ||
function dd(...$vars): void | ||
{ | ||
var_dump(...$vars); | ||
exit; | ||
} | ||
} | ||
|
||
if (! function_exists('d')) { // @codeCoverageIgnore | ||
|
||
/** | ||
* Alias of var_dump() | ||
* | ||
* @param mixed ...$vars | ||
* | ||
* @psalm-suppress ForbiddenCode Unsafe var_dump | ||
*/ | ||
function d(...$vars): void | ||
{ | ||
var_dump(...$vars); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kenjis\PhpUnitHelper; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class DebugHelperTest extends TestCase | ||
{ | ||
use DebugHelper; | ||
|
||
public function test_d(): void | ||
{ | ||
$this->expectOutputRegex( | ||
'/string\(4\) "var1"\n*.*\nint\(100\)\n/' | ||
); | ||
|
||
$var1 = 'var1'; | ||
$var2 = 100; | ||
d($var1, $var2); | ||
} | ||
} |