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

Commit

Permalink
Test improvements for #167
Browse files Browse the repository at this point in the history
- Renames `testRequiredWithoutFallbackAndValueIsEmptyArrayThenFail` to
  `testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEmptyArrays`.
- Adds `testArrayInputMarkedRequiredWithoutAFallbackUsesProvidedErrorMessageOnFailureDueToEmptyArray`
  to validate that if an error message is set on the input, that value
  is used instead of the defaults.
  • Loading branch information
weierophinney committed Dec 13, 2018
1 parent 0b13ad5 commit 2bf3c6e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions test/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,33 @@ public function testDefaultGetValue()
$this->assertCount(0, $this->input->getValue());
}

public function testRequiredWithoutFallbackAndValueIsEmptyArrayThenFail()
public function testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEmptyArrays()
{
$input = $this->input;
$input->setRequired(true);
$input->setValue([]);
$this->assertFalse(
$input->isValid(),
'isValid() should be return always false when no fallback value, is required, and value is empty array.'
);

$this->assertFalse($input->isValid());
$this->assertRequiredValidationErrorMessage($input);
}

public function testArrayInputMarkedRequiredWithoutAFallbackUsesProvidedErrorMessageOnFailureDueToEmptyArray()
{
$expected = 'error message';

$input = $this->input;
$input->setRequired(true);
$input->setErrorMessage($expected);
$input->setValue([]);

$this->assertFalse($input->isValid());

$messages = $input->getMessages();
$this->assertCount(1, $messages);
$message = array_pop($messages);
$this->assertEquals($expected, $message);
}

public function testSetValueWithInvalidInputTypeThrowsInvalidArgumentException()
{
$this->expectException(InvalidArgumentException::class);
Expand Down

0 comments on commit 2bf3c6e

Please sign in to comment.