From 35af07807ea918e16fe7ee690976ef6580c68e4d Mon Sep 17 00:00:00 2001 From: shimonhaga Date: Sun, 19 Sep 2021 14:41:53 +0900 Subject: [PATCH] Add test for utility to get first business day of next month --- src/NextMonthFirstBusinessDay.php | 3 +- test/NextMonthFirstBusinessDayTest.php | 74 ++++++++++++++++++++++++++ test/ThisMonthLastBusinessDayTest.php | 8 ++- 3 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 test/NextMonthFirstBusinessDayTest.php diff --git a/src/NextMonthFirstBusinessDay.php b/src/NextMonthFirstBusinessDay.php index 874b38b..da3fe8c 100644 --- a/src/NextMonthFirstBusinessDay.php +++ b/src/NextMonthFirstBusinessDay.php @@ -21,8 +21,7 @@ public function __invoke(int $hours = 0, int $minutes = 0, int $seconds = 0): Ca // Move day $this->setDate( $this->date->clone() - ->lastOfMonth() // 今月末 - ->addDay() // 翌月 + ->addMonth() // 翌月 ->setDay($this->firstDayOfMonth) // 開始日 ); diff --git a/test/NextMonthFirstBusinessDayTest.php b/test/NextMonthFirstBusinessDayTest.php new file mode 100644 index 0000000..4c063be --- /dev/null +++ b/test/NextMonthFirstBusinessDayTest.php @@ -0,0 +1,74 @@ +assertEquals(2021, $date->year); + $this->assertEquals(8, $date->month); + $this->assertEquals(2, $date->day); + $this->assertEquals(0, $date->hour); + $this->assertEquals(0, $date->minute); + $this->assertEquals(0, $date->second); + } + + public function test20210805_000000() + { + // init + $deadline = new NextMonthFirstBusinessDay(2021, 7, 20); + + // set first days + $deadline->setFirstDayOfMonth(5); + + // get deadline + $date = $deadline(); + $this->assertEquals(2021, $date->year); + $this->assertEquals(8, $date->month); + $this->assertEquals(5, $date->day); + $this->assertEquals(0, $date->hour); + $this->assertEquals(0, $date->minute); + $this->assertEquals(0, $date->second); + } + + public function test20210809_000000() + { + // init + $deadline = new NextMonthFirstBusinessDay(2021, 7, 20); + + // set first days + $deadline->setFirstDayOfMonth(7); + + // get deadline + $date = $deadline(); + $this->assertEquals(2021, $date->year); + $this->assertEquals(8, $date->month); + $this->assertEquals(9, $date->day); + $this->assertEquals(0, $date->hour); + $this->assertEquals(0, $date->minute); + $this->assertEquals(0, $date->second); + } +} diff --git a/test/ThisMonthLastBusinessDayTest.php b/test/ThisMonthLastBusinessDayTest.php index caa853d..55e1306 100644 --- a/test/ThisMonthLastBusinessDayTest.php +++ b/test/ThisMonthLastBusinessDayTest.php @@ -2,7 +2,6 @@ use PHPUnit\Framework\TestCase; use Shimoning\Deadline\ThisMonthLastBusinessDay; -use Carbon\Carbon; class ThisMonthLastBusinessDayTest extends TestCase { @@ -21,7 +20,7 @@ class ThisMonthLastBusinessDayTest extends TestCase public function test20200430_000000() { - // normally + // init $deadline = new ThisMonthLastBusinessDay(2020, 4, 20); // get deadline @@ -36,7 +35,7 @@ public function test20200430_000000() public function test20200429_000000() { - // normally + // init $deadline = new ThisMonthLastBusinessDay(2020, 4, 20); // set sub days @@ -54,11 +53,10 @@ public function test20200429_000000() public function test20200424_000000() { - // normally + // init $deadline = new ThisMonthLastBusinessDay(2020, 4, 20); // set sub days - $deadline->setBehaviorIfNotWeekday(-1); $deadline->setSubDays(4); // get deadline