Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LeanMapper/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ protected function set($property, $value)
if ($value !== null) {
settype($value, $property->getType());
}
if ($property->containsEnumeration() and !$property->isValueFromEnum($value)) {
if ($value !== null and $property->containsEnumeration() and !$property->isValueFromEnum($value)) {
throw new InvalidValueException(
"Given value is not from possible values enumeration in property '{$property->getName()}' in entity " . get_called_class() . '.'
);
Expand Down
44 changes: 44 additions & 0 deletions tests/LeanMapper/Entity.enum.3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use PDO as DbLayer;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

//////////

/**
* @property int $id
* @property string|null $state m:enum(self::STATE_*)
* @property string $finalState m:enum(self::STATE_*)
*/
class Author extends LeanMapper\Entity
{

const STATE_ACTIVE = 'active';

const STATE_INACTIVE = 'inactive';

const STATE_DELETED = 'deleted';

}


//////////

$author = new Author;

$author->state = Author::STATE_ACTIVE;
Assert::equal(Author::STATE_ACTIVE, $author->state);

$author->state = NULL;
Assert::equal(NULL, $author->state);

$author->finalState = Author::STATE_DELETED;
Assert::equal(Author::STATE_DELETED, $author->finalState);

Assert::exception(function () use ($author) {

$author->finalState = NULL;

}, 'LeanMapper\Exception\InvalidValueException', "Property 'finalState' in entity Author cannot be null.");