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

Ensure custom error messages are used for required missing inputs #63

Merged
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
31 changes: 31 additions & 0 deletions test/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFail()
$this->assertRequiredValidationErrorMessage($input);
}

public function testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomErrorMessageWhenSet()
{
$input = $this->input;
$input->setRequired(true);
$input->setErrorMessage('FAILED TO VALIDATE');

$this->assertFalse(
$input->isValid(),
'isValid() should be return always false when no fallback value, is required, and not data is set.'
);
$this->assertSame(['FAILED TO VALIDATE'], $input->getMessages());
}

/**
* @group 28
* @group 60
Expand All @@ -208,6 +221,24 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat
$this->assertRequiredValidationErrorMessage($input);
}

/**
* @group 28
* @group 60
*/
public function testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMessageWhenSet()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the difference with testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomErrorMessageWhenSet

Both have the same body. The only difference is the PHPUnit error message for assertFalse

{
$input = $this->input;
$input->setRequired(true);
$input->setErrorMessage('FAILED TO VALIDATE');

$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->assertSame(['FAILED TO VALIDATE'], $input->getMessages());
}

public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid()
{
$input = $this->input;
Expand Down