Skip to content

Commit 675d735

Browse files
author
liutao
committed
support enum fill
1 parent 8574637 commit 675d735

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

tests/Feature/DataTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
->and($b->addressDetail)->toBe($a->addressDetail);
2626

2727
$c = C::from(['name' => '123', 'a' => enumA::A]);
28-
var_dump(serialize($c));
2928
$c1 = unserialize(serialize($c));
30-
var_dump($c1);
3129
expect($c1)->toBeInstanceOf(C::class);
3230
});
3331

@@ -50,13 +48,24 @@
5048
test('enum', function () {
5149
$c = C::from(['name' => '123', 'a' => 'a']);
5250
expect($c->a)->toBe(enumA::A);
51+
$c = serialize($c);
52+
$c = unserialize($c);
53+
expect($c->a)->toBe(enumA::A);
5354

5455
});
5556

5657
it('throws exception', function () {
5758
C::from(['name' => '123', 'a' => 'b']);
5859
})->throws(ValueError::class);
5960

61+
test('construct', function () {
62+
$e = new E('hello');
63+
expect($e->name)->toBe('hello');
64+
$e = serialize($e);
65+
$e = unserialize($e);
66+
expect($e)->toBeInstanceOf(E::class);
67+
});
68+
6069
#[DataAttribute(toSnakeArray: true)]
6170
class A extends Data
6271
{
@@ -89,4 +98,15 @@ enum enumA: string
8998
class D extends Data
9099
{
91100
public string|int $name;
101+
}
102+
103+
class E extends Data
104+
{
105+
public string $name;
106+
107+
public function __construct(string $name)
108+
{
109+
$this->name = $name;
110+
parent::__construct();
111+
}
92112
}

0 commit comments

Comments
 (0)