File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -677,7 +677,7 @@ protected function set($property, $value)
677677 if ($ value !== null ) {
678678 settype ($ value , $ property ->getType ());
679679 }
680- if ($ property ->containsEnumeration () and !$ property ->isValueFromEnum ($ value )) {
680+ if ($ value !== null and $ property ->containsEnumeration () and !$ property ->isValueFromEnum ($ value )) {
681681 throw new InvalidValueException (
682682 "Given value is not from possible values enumeration in property ' {$ property ->getName ()}' in entity " . get_called_class () . '. '
683683 );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use PDO as DbLayer ;
4+ use Tester \Assert ;
5+
6+ require_once __DIR__ . '/../bootstrap.php ' ;
7+
8+ //////////
9+
10+ /**
11+ * @property int $id
12+ * @property string|null $state m:enum(self::STATE_*)
13+ * @property string $finalState m:enum(self::STATE_*)
14+ */
15+ class Author extends LeanMapper \Entity
16+ {
17+
18+ const STATE_ACTIVE = 'active ' ;
19+
20+ const STATE_INACTIVE = 'inactive ' ;
21+
22+ const STATE_DELETED = 'deleted ' ;
23+
24+ }
25+
26+
27+ //////////
28+
29+ $ author = new Author ;
30+
31+ $ author ->state = Author::STATE_ACTIVE ;
32+ Assert::equal (Author::STATE_ACTIVE , $ author ->state );
33+
34+ $ author ->state = NULL ;
35+ Assert::equal (NULL , $ author ->state );
36+
37+ $ author ->finalState = Author::STATE_DELETED ;
38+ Assert::equal (Author::STATE_DELETED , $ author ->finalState );
39+
40+ Assert::exception (function () use ($ author ) {
41+
42+ $ author ->finalState = NULL ;
43+
44+ }, 'LeanMapper\Exception\InvalidValueException ' , "Property 'finalState' in entity Author cannot be null. " );
You can’t perform that action at this time.
0 commit comments