This repository was archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Provide NotEmpty::IS_EMPTY validation message for required input #61
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3f6c09b
Merge pull request #60 from Maks3w/hotfix/not-set-error-message-if-wa…
weierophinney edc58cb
Rewrote test from #60 to satisfy reported expectations
weierophinney ff81186
Fixed validation failure messages for required input
weierophinney ff75895
Better assertion for required message
weierophinney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,14 @@ | |
|
||
use PHPUnit_Framework_MockObject_MockObject as MockObject; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
use ReflectionProperty; | ||
use stdClass; | ||
use Zend\Filter; | ||
use Zend\Filter\FilterChain; | ||
use Zend\InputFilter\Input; | ||
use Zend\InputFilter\InputInterface; | ||
use Zend\Validator; | ||
use Zend\Validator\NotEmpty; | ||
use Zend\Validator\ValidatorChain; | ||
|
||
/** | ||
|
@@ -175,17 +177,33 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFail() | |
$this->assertEquals(['Value is required'], $input->getMessages(), 'getMessages() value not match'); | ||
} | ||
|
||
public function testRequiredWithoutFallbackAndValueNotSetThenFailWithCustomErrorMessage() | ||
/** | ||
* @group 28 | ||
* @group 60 | ||
*/ | ||
public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage() | ||
{ | ||
$input = $this->input; | ||
$input->setRequired(true); | ||
$input->setErrorMessage('fooErrorMessage'); | ||
|
||
$this->assertFalse( | ||
$input->isValid(), | ||
'isValid() should be return always false when no fallback value, is required, and not data is set.' | ||
'isValid() should always return false when no fallback value is present, ' | ||
. 'the input is required, and no data is set.' | ||
); | ||
$messages = $input->getMessages(); | ||
$this->assertInternalType('array', $messages); | ||
$this->assertArrayHasKey(NotEmpty::IS_EMPTY, $messages); | ||
|
||
$notEmpty = new NotEmpty(); | ||
$r = new ReflectionProperty($notEmpty, 'messageTemplates'); | ||
$r->setAccessible(true); | ||
$messageTemplates = $r->getValue($notEmpty); | ||
$this->assertEquals( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about |
||
$messageTemplates[NotEmpty::IS_EMPTY], | ||
$messages[NotEmpty::IS_EMPTY], | ||
'getMessages() values do not match' | ||
); | ||
$this->assertEquals(['fooErrorMessage'], $input->getMessages(), 'getMessages() value not match'); | ||
} | ||
|
||
public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer compare against the whole
getMessages
return. By this way we are sure any other message appears