diff --git a/composer.json b/composer.json index 1f960dc..3474a76 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ "twig/twig": ">=1.35" }, "require-dev": { - "phpunit/phpunit": "~6.0", "php-coveralls/php-coveralls": "^1.0", + "phpunit/phpunit": "^6.5", "squizlabs/php_codesniffer": "*" }, "autoload": { diff --git a/src/Fields/ChoiceField.php b/src/Fields/ChoiceField.php index f17581d..7313139 100644 --- a/src/Fields/ChoiceField.php +++ b/src/Fields/ChoiceField.php @@ -41,7 +41,7 @@ public function validate($value) { parent::validate($value); - if (!$this->validValue($value)) { + if (!$this->isEmpty($value) && !$this->validValue($value)) { if (is_array($value)) { $value_diff = array_diff($value, array_keys($this->choices)); $value = implode(', ', $value_diff); diff --git a/tests/unit/Fields/ChoiceFieldTest.php b/tests/unit/Fields/ChoiceFieldTest.php index 4fa6fcb..7ac4bf4 100644 --- a/tests/unit/Fields/ChoiceFieldTest.php +++ b/tests/unit/Fields/ChoiceFieldTest.php @@ -61,16 +61,6 @@ public function testValidateChoiceUnexistent() $this->field->validate("option2"); } - /** - * @expectedException PHPForm\Exceptions\ValidationError - * @expectedExceptionMessage Select a valid choice. "empty string" is not one of the available choices. - */ - public function testValidateChoiceEmpty() - { - $field = new ChoiceField(["choices" => array("option1" => "Option1")]); - $field->validate(""); - } - public function testValidateValidValue() { $this->assertNull($this->field->validate("option1"));