Skip to content

Commit edc58cb

Browse files
committed
Rewrote test from zendframework#60 to satisfy reported expectations
- `getMessages()` is expected to return the `NotEmpty::IS_EMPTY` message template.
1 parent 3f6c09b commit edc58cb

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

test/InputTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1313
use PHPUnit_Framework_TestCase as TestCase;
14+
use ReflectionProperty;
1415
use stdClass;
1516
use Zend\Filter;
1617
use Zend\Filter\FilterChain;
1718
use Zend\InputFilter\Input;
1819
use Zend\InputFilter\InputInterface;
1920
use Zend\Validator;
21+
use Zend\Validator\NotEmpty;
2022
use Zend\Validator\ValidatorChain;
2123

2224
/**
@@ -175,17 +177,33 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFail()
175177
$this->assertEquals(['Value is required'], $input->getMessages(), 'getMessages() value not match');
176178
}
177179

178-
public function testRequiredWithoutFallbackAndValueNotSetThenFailWithCustomErrorMessage()
180+
/**
181+
* @group 28
182+
* @group 60
183+
*/
184+
public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage()
179185
{
180186
$input = $this->input;
181187
$input->setRequired(true);
182-
$input->setErrorMessage('fooErrorMessage');
183188

184189
$this->assertFalse(
185190
$input->isValid(),
186-
'isValid() should be return always false when no fallback value, is required, and not data is set.'
191+
'isValid() should always return false when no fallback value is present, '
192+
. 'the input is required, and no data is set.'
193+
);
194+
$messages = $input->getMessages();
195+
$this->assertInternalType('array', $messages);
196+
$this->assertArrayHasKey(NotEmpty::IS_EMPTY, $messages);
197+
198+
$notEmpty = new NotEmpty();
199+
$r = new ReflectionProperty($notEmpty, 'messageTemplates');
200+
$r->setAccessible(true);
201+
$messageTemplates = $r->getValue($notEmpty);
202+
$this->assertEquals(
203+
$messageTemplates[NotEmpty::IS_EMPTY],
204+
$messages[NotEmpty::IS_EMPTY],
205+
'getMessages() values do not match'
187206
);
188-
$this->assertEquals(['fooErrorMessage'], $input->getMessages(), 'getMessages() value not match');
189207
}
190208

191209
public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid()

0 commit comments

Comments
 (0)