This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -491,7 +491,16 @@ protected function injectNotEmptyValidator()
491491 */
492492 protected function prepareRequiredValidationFailureMessage ()
493493 {
494- $ notEmpty = $ this ->getValidatorChain ()->plugin (NotEmpty::class);
494+ $ chain = $ this ->getValidatorChain ();
495+ $ notEmpty = $ chain ->plugin (NotEmpty::class);
496+
497+ foreach ($ chain ->getValidators () as $ validator ) {
498+ if ($ validator ['instance ' ] instanceof NotEmpty) {
499+ $ notEmpty = $ validator ['instance ' ];
500+ break ;
501+ }
502+ }
503+
495504 $ templates = $ notEmpty ->getOption ('messageTemplates ' );
496505 $ message = $ templates [NotEmpty::IS_EMPTY ];
497506 $ translator = $ notEmpty ->getTranslator ();
Original file line number Diff line number Diff line change @@ -227,6 +227,39 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat
227227 $ this ->assertRequiredValidationErrorMessage ($ input );
228228 }
229229
230+ /**
231+ * @group 28
232+ * @group 69
233+ */
234+ public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage ()
235+ {
236+ $ input = new Input ();
237+ $ input ->setRequired (true );
238+
239+ $ customMessage = [
240+ NotEmptyValidator::IS_EMPTY => "Custom message " ,
241+ ];
242+
243+ $ notEmpty = $ this ->getMockBuilder (NotEmptyValidator::class)
244+ ->setMethods (['getOption ' ])
245+ ->getMock ();
246+
247+ $ notEmpty ->expects ($ this ->once ())
248+ ->method ('getOption ' )
249+ ->with ('messageTemplates ' )
250+ ->willReturn ($ customMessage );
251+
252+ $ input ->getValidatorChain ()
253+ ->attach ($ notEmpty );
254+
255+ $ this ->assertFalse (
256+ $ input ->isValid (),
257+ 'isValid() should always return false when no fallback value is present, '
258+ . 'the input is required, and no data is set. '
259+ );
260+ $ this ->assertEquals ($ customMessage , $ input ->getMessages ());
261+ }
262+
230263 /**
231264 * @group 28
232265 * @group 60
You can’t perform that action at this time.
0 commit comments