From 4c9d98fa2ce003ee20b02660e96887eaacbdbc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mos=CC=8Cna?= Date: Fri, 4 Feb 2022 00:12:24 +0100 Subject: [PATCH] add DateFormatter and Calculator tests --- src/DateFormatter.php | 4 +-- tests/CalculatorTest.php | 54 +++++++++++++++++++++++++++++++++++++ tests/DateFormatterTest.php | 32 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 tests/CalculatorTest.php create mode 100644 tests/DateFormatterTest.php diff --git a/src/DateFormatter.php b/src/DateFormatter.php index 24e9af0..7f06d2a 100644 --- a/src/DateFormatter.php +++ b/src/DateFormatter.php @@ -9,11 +9,11 @@ class DateFormatter /** * Get current part of the day * + * @param DateTime $dateTime * @return string */ - public function getPartOfDay() : string + public function getPartOfDay(DateTime $dateTime) : string { - $dateTime = new DateTime(); $currentHour = $dateTime->format('G'); if ($currentHour >= 0 && $currentHour < 6) diff --git a/tests/CalculatorTest.php b/tests/CalculatorTest.php new file mode 100644 index 0000000..aeb2b7d --- /dev/null +++ b/tests/CalculatorTest.php @@ -0,0 +1,54 @@ +assertEquals($expected, self::$calculator->add($a, $b)); + } + + public function additionProvider(): array + { + return [ + [0, 0, 0], + [-1, 1, 0], + [40, 2, 42], + [PHP_INT_MIN, PHP_INT_MAX, 0] + ]; + } + + /** + * @dataProvider divisionProvider + */ + public function testDivide(float $a, float $b, float $expected) + { + $this->assertEquals($expected, self::$calculator->divide($a, $b)); + $this->expectException(\InvalidArgumentException::class); + + self::$calculator->divide(1, 0); + } + + public function divisionProvider(): array + { + return [ + [1, 1, 1], + [0, 1, 0] + ]; + } + + protected function setUp() + { + parent::setUp(); + self::$calculator = new Calculator(); + } +} diff --git a/tests/DateFormatterTest.php b/tests/DateFormatterTest.php new file mode 100644 index 0000000..8fae0bd --- /dev/null +++ b/tests/DateFormatterTest.php @@ -0,0 +1,32 @@ +assertEquals(self::$dateFormatter->getPartOfDay($line[0]), $line[1]); + }, $sampleData); + } + + protected function setUp() + { + parent::setUp(); + self::$dateFormatter = new DateFormatter(); + } +}