-
-
Notifications
You must be signed in to change notification settings - Fork 30
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 #295 from neos/enumNormalization
Add normalization capabilities for backed enums
- Loading branch information
Showing
11 changed files
with
401 additions
and
1 deletion.
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
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,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\EventSourcing\Tests\Unit\EventStore\Fixture; | ||
|
||
final class ArrayValueObject implements \JsonSerializable | ||
{ | ||
private $value; | ||
|
||
private function __construct(array $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function fromArray(array $value): self | ||
{ | ||
return new self($value); | ||
} | ||
|
||
public function equals(self $other): bool | ||
{ | ||
return $other->value === $this->value; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return $this->value; | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\EventSourcing\Tests\Unit\EventStore\Fixture; | ||
|
||
enum BackedEnum: string | ||
{ | ||
case Hearts = 'H'; | ||
case Diamonds = 'D'; | ||
case Clubs = 'C'; | ||
case Spades = 'S'; | ||
} |
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,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\EventSourcing\Tests\Unit\EventStore\Fixture; | ||
|
||
final class BooleanValueObject implements \JsonSerializable | ||
{ | ||
private $value; | ||
|
||
private function __construct(bool $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function fromBoolean(bool $value): self | ||
{ | ||
return new self($value); | ||
} | ||
|
||
public function equals(self $other): bool | ||
{ | ||
return $other->value === $this->value; | ||
} | ||
|
||
public function jsonSerialize(): bool | ||
{ | ||
return $this->value; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\EventSourcing\Tests\Unit\EventStore\Fixture; | ||
|
||
use Neos\EventSourcing\Event\DomainEventInterface; | ||
|
||
final class EventWithBackedEnum implements DomainEventInterface | ||
{ | ||
/** | ||
* @var BackedEnum | ||
*/ | ||
private $enum; | ||
|
||
public function __construct(BackedEnum $enum) | ||
{ | ||
$this->enum = $enum; | ||
} | ||
|
||
public function getEnum(): BackedEnum | ||
{ | ||
return $this->enum; | ||
} | ||
|
||
} |
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,33 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\EventSourcing\Tests\Unit\EventStore\Fixture; | ||
|
||
use Neos\EventSourcing\Event\DomainEventInterface; | ||
|
||
final class EventWithDateTime implements DomainEventInterface | ||
{ | ||
/** | ||
* @var \DateTimeInterface | ||
*/ | ||
private $date; | ||
|
||
public function __construct(\DateTimeInterface $date) | ||
{ | ||
$this->date = $date; | ||
} | ||
|
||
/** | ||
* @return \DateTimeInterface | ||
*/ | ||
public function getDate(): \DateTimeInterface | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function equals(self $other): bool | ||
{ | ||
return $other->date->getTimestamp() === $this->date->getTimestamp(); | ||
} | ||
|
||
} |
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,93 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\EventSourcing\Tests\Unit\EventStore\Fixture; | ||
|
||
use Neos\EventSourcing\Event\DomainEventInterface; | ||
|
||
final class EventWithValueObjects implements DomainEventInterface | ||
{ | ||
/** | ||
* @var ArrayValueObject | ||
*/ | ||
private $array; | ||
|
||
/** | ||
* @var StringValueObject | ||
*/ | ||
private $string; | ||
|
||
/** | ||
* @var IntegerValueObject | ||
*/ | ||
private $integer; | ||
|
||
/** | ||
* @var FloatValueObject | ||
*/ | ||
private $float; | ||
|
||
/** | ||
* @var BooleanValueObject | ||
*/ | ||
private $boolean; | ||
|
||
public function __construct(ArrayValueObject $array, StringValueObject $string, IntegerValueObject $integer, FloatValueObject $float, BooleanValueObject $boolean) | ||
{ | ||
$this->array = $array; | ||
$this->string = $string; | ||
$this->integer = $integer; | ||
$this->float = $float; | ||
$this->boolean = $boolean; | ||
} | ||
|
||
/** | ||
* @return ArrayValueObject | ||
*/ | ||
public function getArray(): ArrayValueObject | ||
{ | ||
return $this->array; | ||
} | ||
|
||
/** | ||
* @return StringValueObject | ||
*/ | ||
public function getString(): StringValueObject | ||
{ | ||
return $this->string; | ||
} | ||
|
||
/** | ||
* @return IntegerValueObject | ||
*/ | ||
public function getInteger(): IntegerValueObject | ||
{ | ||
return $this->integer; | ||
} | ||
|
||
/** | ||
* @return FloatValueObject | ||
*/ | ||
public function getFloat(): FloatValueObject | ||
{ | ||
return $this->float; | ||
} | ||
|
||
/** | ||
* @return BooleanValueObject | ||
*/ | ||
public function getBoolean(): BooleanValueObject | ||
{ | ||
return $this->boolean; | ||
} | ||
|
||
public function equals(self $other): bool | ||
{ | ||
return $other->array->equals($this->array) | ||
&& $other->string->equals($this->string) | ||
&& $other->integer->equals($this->integer) | ||
&& $other->float->equals($this->float) | ||
&& $other->boolean->equals($this->boolean); | ||
} | ||
|
||
} |
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,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\EventSourcing\Tests\Unit\EventStore\Fixture; | ||
|
||
final class FloatValueObject implements \JsonSerializable | ||
{ | ||
private $value; | ||
|
||
private function __construct(float $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function fromFloat(float $value): self | ||
{ | ||
return new self($value); | ||
} | ||
|
||
public function equals(self $other): bool | ||
{ | ||
return $other->value === $this->value; | ||
} | ||
|
||
public function jsonSerialize(): float | ||
{ | ||
return $this->value; | ||
} | ||
} |
Oops, something went wrong.