Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/DateFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 54 additions & 0 deletions tests/CalculatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace IW\Tests\Workshop;

use IW\Workshop\Calculator;
use PHPUnit\Framework\TestCase;

class CalculatorTest extends TestCase
{
protected static $calculator;

/**
* @dataProvider additionProvider
*/
public function testAdd(float $a, float $b, float $expected)
{
$this->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();
}
}
32 changes: 32 additions & 0 deletions tests/DateFormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace IW\Tests\Workshop;

use IW\Workshop\DateFormatter;
use PHPUnit\Framework\TestCase;

class DateFormatterTest extends TestCase
{

protected static $dateFormatter;

public function testGetPartOfDay()
{
$sampleData = [
[new \DateTime("2022-01-01T00:00:00+01:00"), "Night"],
[new \DateTime("2022-01-01T08:00:00+01:00"), "Morning"],
[new \DateTime("2022-01-01T14:00:00+01:00"), "Afternoon"],
[new \DateTime("2022-01-01T22:00:00+01:00"), "Evening"]
];

array_map(function (array $line) {
$this->assertEquals(self::$dateFormatter->getPartOfDay($line[0]), $line[1]);
}, $sampleData);
}

protected function setUp()
{
parent::setUp();
self::$dateFormatter = new DateFormatter();
}
}