Skip to content

Commit

Permalink
Add test for utility to get first business day of next month
Browse files Browse the repository at this point in the history
  • Loading branch information
shimonhaga committed Sep 19, 2021
1 parent 44d43c7 commit 35af078
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/NextMonthFirstBusinessDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) // 開始日
);

Expand Down
74 changes: 74 additions & 0 deletions test/NextMonthFirstBusinessDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

use PHPUnit\Framework\TestCase;
use Shimoning\Deadline\NextMonthFirstBusinessDay;

class NextMonthFirstBusinessDayTest extends TestCase
{
/**
* Jul 2021
*
* Su Mo Tu We Th Fr Sa
* 1 2 3
* 4 5 6 7 8 9 10
* 11 12 13 14 15 16 17
* 18 19 20 21 22 23 24
* 25 26 27 28 29 30 31
*
* Aug 2021
*
* Su Mo Tu We Th Fr Sa
* 1 2 3 4 5 6 7
*/

public function test20210802_000000()
{
// init
$deadline = new NextMonthFirstBusinessDay(2021, 7, 20);

// get deadline
$date = $deadline();
$this->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);
}
}
8 changes: 3 additions & 5 deletions test/ThisMonthLastBusinessDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use PHPUnit\Framework\TestCase;
use Shimoning\Deadline\ThisMonthLastBusinessDay;
use Carbon\Carbon;

class ThisMonthLastBusinessDayTest extends TestCase
{
Expand All @@ -21,7 +20,7 @@ class ThisMonthLastBusinessDayTest extends TestCase

public function test20200430_000000()
{
// normally
// init
$deadline = new ThisMonthLastBusinessDay(2020, 4, 20);

// get deadline
Expand All @@ -36,7 +35,7 @@ public function test20200430_000000()

public function test20200429_000000()
{
// normally
// init
$deadline = new ThisMonthLastBusinessDay(2020, 4, 20);

// set sub days
Expand All @@ -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
Expand Down

0 comments on commit 35af078

Please sign in to comment.