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

Commit af8837d

Browse files
committed
Test that attached NotEmpty validator message is used
1 parent a05fa0b commit af8837d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/InputTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,39 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat
220220
$this->assertRequiredValidationErrorMessage($input);
221221
}
222222

223+
/**
224+
* @group 28
225+
* @group 69
226+
*/
227+
public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage()
228+
{
229+
$input = new Input();
230+
$input->setRequired(true);
231+
232+
$customMessage = [
233+
NotEmptyValidator::IS_EMPTY => "Custom message",
234+
];
235+
236+
$notEmpty = $this->getMockBuilder(NotEmptyValidator::class)
237+
->setMethods(['getOption'])
238+
->getMock();
239+
240+
$notEmpty->expects($this->once())
241+
->method('getOption')
242+
->with('messageTemplates')
243+
->willReturn($customMessage);
244+
245+
$input->getValidatorChain()
246+
->attach($notEmpty);
247+
248+
$this->assertFalse(
249+
$input->isValid(),
250+
'isValid() should always return false when no fallback value is present, '
251+
. 'the input is required, and no data is set.'
252+
);
253+
$this->assertEquals($customMessage, $input->getMessages());
254+
}
255+
223256
/**
224257
* @group 28
225258
* @group 60

0 commit comments

Comments
 (0)