Skip to content

Commit

Permalink
Dumper: support enums (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: David Grudl <david@grudl.com>
  • Loading branch information
iggyvolz and dg committed Aug 24, 2021
1 parent dbfd812 commit b524a3b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/PhpGenerator/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ private function dumpObject(&$var, array $parents, int $level): string
{
if ($var instanceof \Serializable) {
return 'unserialize(' . $this->dumpString(serialize($var)) . ')';

} elseif ($var instanceof \UnitEnum) {
return get_class($var) . '::' . $var->name;
} elseif ($var instanceof \Closure) {
throw new Nette\InvalidArgumentException('Cannot dump closure.');
}
Expand Down
26 changes: 26 additions & 0 deletions tests/PhpGenerator/Dumper.dump().enum.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Test: Nette\PhpGenerator\Dumper::dump() enum
* @phpVersion 8.1
*/

declare(strict_types=1);

use Nette\PhpGenerator\Dumper;
use Nette\PhpGenerator\PhpLiteral;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


enum Suit {
case Clubs;
case Diamonds;
case Hearts;
case Spades;
}

$dumper = new Dumper;
Assert::same('Suit::Clubs', $dumper->dump(Suit::Clubs));

0 comments on commit b524a3b

Please sign in to comment.