Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Hotfix/69 #73

Merged
merged 2 commits into from
Apr 7, 2016
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
15 changes: 14 additions & 1 deletion src/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,20 @@ protected function injectNotEmptyValidator()
*/
protected function prepareRequiredValidationFailureMessage()
{
$notEmpty = new NotEmpty();
$chain = $this->getValidatorChain();
$validators = $chain->getValidators();

foreach ($validators as $validator) {
if ($validator['instance'] instanceof NotEmpty) {
$notEmpty = $validator['instance'];
break;
}
}

if (!isset($notEmpty)) {
$notEmpty = new NotEmpty();
}

$templates = $notEmpty->getOption('messageTemplates');
return [
NotEmpty::IS_EMPTY => $templates[NotEmpty::IS_EMPTY],
Expand Down
33 changes: 33 additions & 0 deletions test/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,39 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat
$this->assertRequiredValidationErrorMessage($input);
}

/**
* @group 28
* @group 69
*/
public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage()
{
$input = new Input();
$input->setRequired(true);

$customMessage = [
NotEmptyValidator::IS_EMPTY => "Custom message",
];

$notEmpty = $this->getMockBuilder(NotEmptyValidator::class)
->setMethods(['getOption'])
->getMock();

$notEmpty->expects($this->once())
->method('getOption')
->with('messageTemplates')
->willReturn($customMessage);

$input->getValidatorChain()
->attach($notEmpty);

$this->assertFalse(
$input->isValid(),
'isValid() should always return false when no fallback value is present, '
. 'the input is required, and no data is set.'
);
$this->assertEquals($customMessage, $input->getMessages());
}

/**
* @group 28
* @group 60
Expand Down