From ab6a4fb8a6675fdcfbc3e2af2959d853cb563bf3 Mon Sep 17 00:00:00 2001 From: Eduardo Gulias Davis Date: Mon, 20 Apr 2020 23:57:29 +0200 Subject: [PATCH] Initial approach to avoiding exceptions and better results. Failing test to remember to implement tokens --- EmailValidator/Result/InvalidEmail.php | 33 +++++++++++++++++++ .../Result/Reason/CharNotAllowed.php | 17 ++++++++++ EmailValidator/Result/Reason/Reason.php | 9 +++++ EmailValidator/Result/Result.php | 10 ++++++ EmailValidator/Result/ValidEmail.php | 22 +++++++++++++ Tests/EmailValidator/LexerTokensTest.php | 11 +++++++ Tests/EmailValidator/Result/ResultTest.php | 33 +++++++++++++++++++ 7 files changed, 135 insertions(+) create mode 100644 EmailValidator/Result/InvalidEmail.php create mode 100644 EmailValidator/Result/Reason/CharNotAllowed.php create mode 100644 EmailValidator/Result/Reason/Reason.php create mode 100644 EmailValidator/Result/Result.php create mode 100644 EmailValidator/Result/ValidEmail.php create mode 100644 Tests/EmailValidator/LexerTokensTest.php create mode 100644 Tests/EmailValidator/Result/ResultTest.php diff --git a/EmailValidator/Result/InvalidEmail.php b/EmailValidator/Result/InvalidEmail.php new file mode 100644 index 0000000..30bc859 --- /dev/null +++ b/EmailValidator/Result/InvalidEmail.php @@ -0,0 +1,33 @@ +token = $token; + $this->reason = $reason; + } + + public function isValid(): bool + { + return false; + } + + public function description(): string + { + return $this->reason->description() . " in char " . $this->token; + } + + public function code(): int + { + return $this->reason->code(); + } + +} \ No newline at end of file diff --git a/EmailValidator/Result/Reason/CharNotAllowed.php b/EmailValidator/Result/Reason/CharNotAllowed.php new file mode 100644 index 0000000..d174e5c --- /dev/null +++ b/EmailValidator/Result/Reason/CharNotAllowed.php @@ -0,0 +1,17 @@ +fail("implement"); + } +} \ No newline at end of file diff --git a/Tests/EmailValidator/Result/ResultTest.php b/Tests/EmailValidator/Result/ResultTest.php new file mode 100644 index 0000000..5f0c792 --- /dev/null +++ b/Tests/EmailValidator/Result/ResultTest.php @@ -0,0 +1,33 @@ +assertTrue($result->isValid()); + $this->assertEquals($expectedCode, $result->code()); + $this->assertEquals($expectedDescription, $result->description()); + } + + public function testResultIsInvalidEmail() + { + $reason = new CharNotAllowed(); + $token = "T"; + $result = new InvalidEmail($reason, $token); + $expectedCode = $reason->code(); + $expectedDescription = $reason->description() . " in char " . $token; + + $this->assertFalse($result->isValid()); + $this->assertEquals($expectedCode, $result->code()); + $this->assertEquals($expectedDescription, $result->description()); + } +} \ No newline at end of file