death-notifier/src/test/php/com/fwdekker/deathnotifier/validator/LengthRuleTest.php

72 lines
1.6 KiB
PHP

<?php
namespace com\fwdekker\deathnotifier\validator;
/**
* Unit tests for `LengthRule`.
*/
class LengthRuleTest extends RuleTest
{
function get_rule(?string $override = null): Rule
{
return new LengthRule(1, 6, $override);
}
function get_valid_input(): ?string
{
return "valid";
}
function get_invalid_input(): ?string
{
return "too-long";
}
public function test_returns_null_if_input_is_exactly_minimum_length(): void
{
$rule = new LengthRule(1, 3);
$is_valid = $rule->check(["input" => "a"], "input");
$this->assertNull($is_valid);
}
public function test_returns_null_if_input_is_exactly_maximum_length(): void
{
$rule = new LengthRule(1, 3);
$is_valid = $rule->check(["input" => "123"], "input");
$this->assertNull($is_valid);
}
public function test_returns_null_if_input_is_strictly_inside_range(): void
{
$rule = new LengthRule(1, 3);
$is_valid = $rule->check(["input" => "12"], "input");
$this->assertNull($is_valid);
}
public function test_returns_not_null_if_input_is_strictly_below_minimum(): void
{
$rule = new LengthRule(1, 3);
$is_valid = $rule->check(["input" => ""], "input");
$this->assertNotNull($is_valid);
}
public function test_returns_not_null_if_input_is_strictly_above_maximum(): void
{
$rule = new LengthRule(1, 3);
$is_valid = $rule->check(["input" => "1234"], "input");
$this->assertNotNull($is_valid);
}
}