File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
tests/Domain/ValueObjects Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -31,9 +31,20 @@ class DateTimeValue extends CarbonImmutable implements ValueObject
3131 public function __construct ($ time = null , $ tz = null )
3232 {
3333 parent ::__construct ($ time , $ tz );
34+ $ this ->initializeDefaultStringFormat ();
35+ }
36+
37+ private function initializeDefaultStringFormat (): void
38+ {
3439 $ this ->settings (['toStringFormat ' => 'c ' ]);
3540 }
3641
42+ public function __wakeup ()
43+ {
44+ parent ::__wakeup ();
45+ $ this ->initializeDefaultStringFormat ();
46+ }
47+
3748 /**
3849 * Return the value as string.
3950 *
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace OtherCode \ComplexHeart \Tests \Domain \ValueObjects ;
6+
7+ use Mockery \Adapter \Phpunit \MockeryTestCase ;
8+ use OtherCode \ComplexHeart \Domain \ValueObjects \DateTimeValue ;
9+
10+ /**
11+ * Class DateTimeValueTest
12+ * @author Dmytro <dmytro@2amigos.us>
13+ * @package OtherCode\ComplexHeart\Tests\Domain\ValueObjects
14+ */
15+ class DateTimeValueTest extends MockeryTestCase
16+ {
17+ public function testShouldInitializeStringFormatWhenWakesUp (): void
18+ {
19+ $ instance = new DateTimeValue ();
20+ $ serialized = serialize ($ instance );
21+ $ wakedUp = unserialize ($ serialized );
22+ $ this ->assertSame ($ instance ->__toString (), $ wakedUp ->__toString ());
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments