From 77fe53a758c211bf248fc2d2bb6a079a92858682 Mon Sep 17 00:00:00 2001 From: Diego Ananias Date: Sun, 31 Dec 2023 18:29:29 -0300 Subject: [PATCH] test: adding tests --- phpunit.xml.bak | 38 +++++----- .../Anonymizers/BirthDateAnonymizerTest.php | 72 +++++++++--------- .../Anonymizers/CreditCardAnonymizerTest.php | 70 +++++++++--------- .../Unit/Anonymizers/EmailAnonymizerTest.php | 72 +++++++++--------- .../Unit/Anonymizers/PhoneAnonymizerTest.php | 72 +++++++++--------- .../Unit/Detectors/BirthDateDetectorTest.php | 70 +++++++++--------- .../Unit/Detectors/CreditCardDetectorTest.php | 74 +++++++++---------- tests/Unit/Detectors/EmailDetectorTest.php | 70 +++++++++--------- tests/Unit/Detectors/PhoneDetectorTest.php | 72 +++++++++--------- 9 files changed, 305 insertions(+), 305 deletions(-) diff --git a/phpunit.xml.bak b/phpunit.xml.bak index 89d49c2..5183c6e 100644 --- a/phpunit.xml.bak +++ b/phpunit.xml.bak @@ -1,19 +1,19 @@ - - - - ./tests - - - - - - ./src - - - - - - - + + + + ./tests + + + + + + ./src + + + + + + + diff --git a/tests/Unit/Anonymizers/BirthDateAnonymizerTest.php b/tests/Unit/Anonymizers/BirthDateAnonymizerTest.php index 0ced4cf..0b4064f 100644 --- a/tests/Unit/Anonymizers/BirthDateAnonymizerTest.php +++ b/tests/Unit/Anonymizers/BirthDateAnonymizerTest.php @@ -1,36 +1,36 @@ -anonymizer = new BirthDateAnonymizer(); - } - - public function testAnonymizeWithDashedDateFormat() - { - $originalMessage = "User's birth date is 1990-01-01."; - $expectedMessage = "User's birth date is XXXX-XX-XX."; - $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); - } - - public function testAnonymizeWithSlashedDateFormat() - { - $originalMessage = "User's birth date is 01/01/1990."; - $expectedMessage = "User's birth date is XX/XX/XXXX."; - $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); - } - - public function testAnonymizeWithoutDate() - { - $originalMessage = "No date in this message."; - $this->assertEquals($originalMessage, $this->anonymizer->anonymize($originalMessage)); - } -} +anonymizer = new BirthDateAnonymizer(); + } + + public function testAnonymizeWithDashedDateFormat() + { + $originalMessage = "User's birth date is 1990-01-01."; + $expectedMessage = "User's birth date is XXXX-XX-XX."; + $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); + } + + public function testAnonymizeWithSlashedDateFormat() + { + $originalMessage = "User's birth date is 01/01/1990."; + $expectedMessage = "User's birth date is XX/XX/XXXX."; + $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); + } + + public function testAnonymizeWithoutDate() + { + $originalMessage = "No date in this message."; + $this->assertEquals($originalMessage, $this->anonymizer->anonymize($originalMessage)); + } +} diff --git a/tests/Unit/Anonymizers/CreditCardAnonymizerTest.php b/tests/Unit/Anonymizers/CreditCardAnonymizerTest.php index 1e47933..3b83dbc 100644 --- a/tests/Unit/Anonymizers/CreditCardAnonymizerTest.php +++ b/tests/Unit/Anonymizers/CreditCardAnonymizerTest.php @@ -1,36 +1,36 @@ -anonymizer = new CreditCardAnonymizer(); - } - - public function testAnonymizeCreditCardNumber() - { - $originalMessage = "The credit card number is 1234-5678-9012-3456."; - $expectedMessage = "The credit card number is 1234-XXXX-XXXX-XXXX."; - $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); - } - - public function testAnonymizeWithDifferentSeparators() - { - $originalMessage = "Cards: 1234 5678 9012 3456, 1234.5678.9012.3456."; - $expectedMessage = "Cards: 1234-XXXX-XXXX-XXXX, 1234-XXXX-XXXX-XXXX."; - $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); - } - - public function testAnonymizeWithoutCreditCardNumber() - { - $originalMessage = "This message does not contain a credit card number."; - $this->assertEquals($originalMessage, $this->anonymizer->anonymize($originalMessage)); - } +anonymizer = new CreditCardAnonymizer(); + } + + public function testAnonymizeCreditCardNumber() + { + $originalMessage = "The credit card number is 1234-5678-9012-3456."; + $expectedMessage = "The credit card number is 1234-XXXX-XXXX-XXXX."; + $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); + } + + public function testAnonymizeWithDifferentSeparators() + { + $originalMessage = "Cards: 1234 5678 9012 3456, 1234.5678.9012.3456."; + $expectedMessage = "Cards: 1234-XXXX-XXXX-XXXX, 1234-XXXX-XXXX-XXXX."; + $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); + } + + public function testAnonymizeWithoutCreditCardNumber() + { + $originalMessage = "This message does not contain a credit card number."; + $this->assertEquals($originalMessage, $this->anonymizer->anonymize($originalMessage)); + } } \ No newline at end of file diff --git a/tests/Unit/Anonymizers/EmailAnonymizerTest.php b/tests/Unit/Anonymizers/EmailAnonymizerTest.php index df18387..68318fe 100644 --- a/tests/Unit/Anonymizers/EmailAnonymizerTest.php +++ b/tests/Unit/Anonymizers/EmailAnonymizerTest.php @@ -1,36 +1,36 @@ -anonymizer = new EmailAnonymizer(); - } - - public function testAnonymizeEmailAddress() - { - $originalMessage = "Contact me at john.doe@example.com."; - $expectedMessage = "Contact me at j***.d**@example.com."; - $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); - } - - public function testAnonymizeMultipleEmailAddresses() - { - $originalMessage = "Emails: alice@example.com and bob@example.com."; - $expectedMessage = "Emails: a****@example.com and b**@example.com."; - $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); - } - - public function testAnonymizeWithoutEmailAddress() - { - $originalMessage = "This message does not contain an email address."; - $this->assertEquals($originalMessage, $this->anonymizer->anonymize($originalMessage)); - } -} +anonymizer = new EmailAnonymizer(); + } + + public function testAnonymizeEmailAddress() + { + $originalMessage = "Contact me at john.doe@example.com."; + $expectedMessage = "Contact me at j***.d**@example.com."; + $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); + } + + public function testAnonymizeMultipleEmailAddresses() + { + $originalMessage = "Emails: alice@example.com and bob@example.com."; + $expectedMessage = "Emails: a****@example.com and b**@example.com."; + $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); + } + + public function testAnonymizeWithoutEmailAddress() + { + $originalMessage = "This message does not contain an email address."; + $this->assertEquals($originalMessage, $this->anonymizer->anonymize($originalMessage)); + } +} diff --git a/tests/Unit/Anonymizers/PhoneAnonymizerTest.php b/tests/Unit/Anonymizers/PhoneAnonymizerTest.php index 2f311fd..aef448e 100644 --- a/tests/Unit/Anonymizers/PhoneAnonymizerTest.php +++ b/tests/Unit/Anonymizers/PhoneAnonymizerTest.php @@ -1,36 +1,36 @@ -anonymizer = new PhoneAnonymizer(); - } - - public function testAnonymizePhoneNumber() - { - $originalMessage = "Contact number is +123 4567 8901."; - $expectedMessage = "Contact number is +123 4567 XXXX."; - $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); - } - - public function testAnonymizeMultiplePhoneNumbers() - { - $originalMessage = "Numbers are (123) 456-7890 and 123.456.7890."; - $expectedMessage = "Numbers are (123) 456-XXXX and 123.456.XXXX."; - $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); - } - - public function testAnonymizeWithoutPhoneNumber() - { - $originalMessage = "This message does not contain a phone number."; - $this->assertEquals($originalMessage, $this->anonymizer->anonymize($originalMessage)); - } -} +anonymizer = new PhoneAnonymizer(); + } + + public function testAnonymizePhoneNumber() + { + $originalMessage = "Contact number is +123 4567 8901."; + $expectedMessage = "Contact number is +123 4567 XXXX."; + $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); + } + + public function testAnonymizeMultiplePhoneNumbers() + { + $originalMessage = "Numbers are (123) 456-7890 and 123.456.7890."; + $expectedMessage = "Numbers are (123) 456-XXXX and 123.456.XXXX."; + $this->assertEquals($expectedMessage, $this->anonymizer->anonymize($originalMessage)); + } + + public function testAnonymizeWithoutPhoneNumber() + { + $originalMessage = "This message does not contain a phone number."; + $this->assertEquals($originalMessage, $this->anonymizer->anonymize($originalMessage)); + } +} diff --git a/tests/Unit/Detectors/BirthDateDetectorTest.php b/tests/Unit/Detectors/BirthDateDetectorTest.php index 7acccd6..233d6d9 100644 --- a/tests/Unit/Detectors/BirthDateDetectorTest.php +++ b/tests/Unit/Detectors/BirthDateDetectorTest.php @@ -1,35 +1,35 @@ -detector = new BirthDateDetector(); - } - - /** - * @dataProvider dateMessageProvider - */ - public function testDetectsDate(string $message, bool $expectedResult) - { - $this->assertEquals($expectedResult, $this->detector->detect($message)); - } - - public static function dateMessageProvider() - { - return [ - "with pt-br date" => ["A data de nascimento é 01/01/1990.", true], - "with iso date" => ["The birth date is 1990-01-01.", true], - - "without date" => ["Este texto não tem uma data.", false], - "without iso date" => ["This text doesn't have a date.", false], - ]; - } -} +detector = new BirthDateDetector(); + } + + /** + * @dataProvider dateMessageProvider + */ + public function testDetectsDate(string $message, bool $expectedResult) + { + $this->assertEquals($expectedResult, $this->detector->detect($message)); + } + + public static function dateMessageProvider() + { + return [ + "with pt-br date" => ["A data de nascimento é 01/01/1990.", true], + "with iso date" => ["The birth date is 1990-01-01.", true], + + "without date" => ["Este texto não tem uma data.", false], + "without iso date" => ["This text doesn't have a date.", false], + ]; + } +} diff --git a/tests/Unit/Detectors/CreditCardDetectorTest.php b/tests/Unit/Detectors/CreditCardDetectorTest.php index b4bc03e..01ae41d 100644 --- a/tests/Unit/Detectors/CreditCardDetectorTest.php +++ b/tests/Unit/Detectors/CreditCardDetectorTest.php @@ -1,38 +1,38 @@ -detector = new CreditCardDetector(); - } - - /** - * @dataProvider creditCardMessageProvider - */ - public function testDetectsCreditCard(string $message, bool $expectedResult) - { - $this->assertEquals($expectedResult, $this->detector->detect($message)); - } - - public static function creditCardMessageProvider() - { - return [ - ["Credit card number is 1234-5678-9012-3456", true], - ["Another card: 1234567890123456", true], - ["Card with spaces: 1234 5678 9012 3456", true], - ["Card with dots: 1234.5678.9012.3456", true], - - ["No card number here", false], - ["Random numbers: 1234-5678", false], - ["Incomplete card number: 1234-5678-9012", false], - ]; - } +detector = new CreditCardDetector(); + } + + /** + * @dataProvider creditCardMessageProvider + */ + public function testDetectsCreditCard(string $message, bool $expectedResult) + { + $this->assertEquals($expectedResult, $this->detector->detect($message)); + } + + public static function creditCardMessageProvider() + { + return [ + ["Credit card number is 1234-5678-9012-3456", true], + ["Another card: 1234567890123456", true], + ["Card with spaces: 1234 5678 9012 3456", true], + ["Card with dots: 1234.5678.9012.3456", true], + + ["No card number here", false], + ["Random numbers: 1234-5678", false], + ["Incomplete card number: 1234-5678-9012", false], + ]; + } } \ No newline at end of file diff --git a/tests/Unit/Detectors/EmailDetectorTest.php b/tests/Unit/Detectors/EmailDetectorTest.php index a43b32f..6e9cc78 100644 --- a/tests/Unit/Detectors/EmailDetectorTest.php +++ b/tests/Unit/Detectors/EmailDetectorTest.php @@ -1,35 +1,35 @@ -detector = new EmailDetector(); - } - - /** - * @dataProvider emailMessageProvider - */ - public function testDetectsEmail(string $message, bool $expectedResult) - { - $this->assertEquals($expectedResult, $this->detector->detect($message)); - } - - public static function emailMessageProvider() - { - return [ - ["Contact me at john.doe@example.com", true], - ["Email: jane_doe123@subdomain.example.co.uk", true], - - ["This is a plain text without email.", false], - ["Just a website www.example.com, no email here.", false], - ]; - } -} +detector = new EmailDetector(); + } + + /** + * @dataProvider emailMessageProvider + */ + public function testDetectsEmail(string $message, bool $expectedResult) + { + $this->assertEquals($expectedResult, $this->detector->detect($message)); + } + + public static function emailMessageProvider() + { + return [ + ["Contact me at john.doe@example.com", true], + ["Email: jane_doe123@subdomain.example.co.uk", true], + + ["This is a plain text without email.", false], + ["Just a website www.example.com, no email here.", false], + ]; + } +} diff --git a/tests/Unit/Detectors/PhoneDetectorTest.php b/tests/Unit/Detectors/PhoneDetectorTest.php index 0c9a93e..514557f 100644 --- a/tests/Unit/Detectors/PhoneDetectorTest.php +++ b/tests/Unit/Detectors/PhoneDetectorTest.php @@ -1,37 +1,37 @@ -detector = new PhoneDetector(); - } - - /** - * @dataProvider phoneMessageProvider - */ - public function testDetectsPhone(string $message, bool $expectedResult) - { - $this->assertEquals($expectedResult, $this->detector->detect($message)); - } - - public static function phoneMessageProvider() - { - return [ - ["Call me at +123 4567 8901", true], - ["Phone: (123) 456-7890", true], - ["Mobile: 123.456.7890", true], - ["Contact: 1234567890", true], - - ["No phone number here", false], - ["Random numbers: 1234-5678", false], - ]; - } +detector = new PhoneDetector(); + } + + /** + * @dataProvider phoneMessageProvider + */ + public function testDetectsPhone(string $message, bool $expectedResult) + { + $this->assertEquals($expectedResult, $this->detector->detect($message)); + } + + public static function phoneMessageProvider() + { + return [ + ["Call me at +123 4567 8901", true], + ["Phone: (123) 456-7890", true], + ["Mobile: 123.456.7890", true], + ["Contact: 1234567890", true], + + ["No phone number here", false], + ["Random numbers: 1234-5678", false], + ]; + } } \ No newline at end of file