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

32 lines
1.4 KiB
PHP

<?php
namespace com\fwdekker\deathnotifier\validator;
use com\fwdekker\deathnotifier\IllegalArgumentError;
use PHPUnit\Framework\TestCase;
/**
* Unit tests for {@see IsEmailRule}.
*/
class IsEmailRuleTest extends RuleTest
{
public function check_provider(): array
{
$error = IllegalArgumentError::class;
$exception = InvalidInputException::class;
return [
["error if input is not set", null, $error, "Required input 'key' not set."],
["error if input is not string", 491, $error, "Input 'key' should be string, but is integer."],
["exception if input starts with space", " valid@example.com", $exception, "Remove the spaces at the start."],
["exception if input ends with space", "valid@example.com ", $exception, "Remove the spaces at the end."],
["exception if input is empty", "", $exception, "Enter an email address."],
["exception if input misses the '@' symbol", "invalid", $exception, "Don't forget to add an '@' symbol."],
["exception if input misses the domain part", "invalid@", $exception, "Add a domain name after the '@'."],
["exception if input is invalid in a complex way", "invalid@example", $exception, "Enter a valid email address."],
["no exception if input is valid", "valid@example.com", null, null],
];
}
}