1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 11:12:43 +01:00
invoiceninja/tests/Unit/RecurringDueDatesTest.php

155 lines
3.7 KiB
PHP
Raw Normal View History

2020-09-14 13:11:46 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-09-14 13:11:46 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Unit;
use App\Utils\Traits\Recurring\HasRecurrence;
use Illuminate\Support\Carbon;
use Tests\TestCase;
/**
* @test
* @covers App\Utils\Traits\Recurring\HasRecurrence
*/
class RecurringDueDatesTest extends TestCase
{
use HasRecurrence;
2020-09-14 14:13:15 +02:00
public function testFirstDate()
2020-09-14 13:11:46 +02:00
{
2020-09-14 14:13:15 +02:00
$date = Carbon::parse('2020-02-15');
$due_date = $this->calculateFirstDayOfMonth($date);
$this->assertEquals('2020-03-01', $due_date->format('Y-m-d'));
2020-09-14 13:11:46 +02:00
}
2020-09-14 14:13:15 +02:00
public function testFirstOfMonthOnFirst()
2020-09-14 13:11:46 +02:00
{
2020-09-14 14:13:15 +02:00
$date = Carbon::parse('2020-02-01');
2020-09-14 13:11:46 +02:00
$due_date = $this->calculateFirstDayOfMonth($date);
$this->assertEquals('2020-03-01', $due_date->format('Y-m-d'));
2020-11-25 15:19:52 +01:00
}
2020-09-14 14:13:15 +02:00
public function testFirstOfMonthOnLast()
{
$date = Carbon::parse('2020-03-31');
$due_date = $this->calculateFirstDayOfMonth($date);
$this->assertEquals('2020-04-01', $due_date->format('Y-m-d'));
2020-11-25 15:19:52 +01:00
}
2020-09-14 14:13:15 +02:00
public function testLastOfMonth()
{
$date = Carbon::parse('2020-02-15');
$due_date = $this->calculateLastDayOfMonth($date);
$this->assertEquals('2020-02-29', $due_date->format('Y-m-d'));
2020-11-25 15:19:52 +01:00
}
2020-09-14 14:13:15 +02:00
public function testLastOfMonthOnFirst()
{
$date = Carbon::parse('2020-02-1');
$due_date = $this->calculateLastDayOfMonth($date);
$this->assertEquals('2020-02-29', $due_date->format('Y-m-d'));
2020-11-25 15:19:52 +01:00
}
2020-09-14 14:13:15 +02:00
public function testLastOfMonthOnLast()
{
$date = Carbon::parse('2020-02-29');
$due_date = $this->calculateLastDayOfMonth($date);
$this->assertEquals('2020-03-31', $due_date->format('Y-m-d'));
2020-11-25 15:19:52 +01:00
}
2020-09-14 14:13:15 +02:00
public function testDayOfMonth()
{
$date = Carbon::parse('2020-02-01');
$due_date = $this->setDayOfMonth($date, '15');
$this->assertEquals('2020-02-15', $due_date->format('Y-m-d'));
2020-09-14 13:11:46 +02:00
}
2020-09-14 14:13:15 +02:00
public function testDayOfMonthInFuture()
{
$date = Carbon::parse('2020-02-16');
$due_date = $this->setDayOfMonth($date, '15');
$this->assertEquals('2020-03-15', $due_date->format('Y-m-d'));
}
public function testDayOfMonthSameDay()
{
$date = Carbon::parse('2020-02-01');
$due_date = $this->setDayOfMonth($date, '1');
$this->assertEquals('2020-03-01', $due_date->format('Y-m-d'));
}
public function testDayOfMonthWithOverflow()
{
$date = Carbon::parse('2020-1-31');
$due_date = $this->setDayOfMonth($date, '31');
$this->assertEquals('2020-02-29', $due_date->format('Y-m-d'));
}
public function testDayOfMonthWithOverflow2()
{
$date = Carbon::parse('2020-02-29');
$due_date = $this->setDayOfMonth($date, '31');
$this->assertEquals('2020-03-31', $due_date->format('Y-m-d'));
}
public function testDayOfMonthWithOverflow3()
{
$date = Carbon::parse('2020-01-30');
$due_date = $this->setDayOfMonth($date, '30');
$this->assertEquals('2020-02-29', $due_date->format('Y-m-d'));
}
public function testDayOfMonthWithOverflow4()
{
$date = Carbon::parse('2019-02-28');
$due_date = $this->setDayOfMonth($date, '31');
$this->assertEquals('2019-03-31', $due_date->format('Y-m-d'));
}
public function testDayOfMonthWithOverflow5()
{
$date = Carbon::parse('2019-1-31');
$due_date = $this->setDayOfMonth($date, '31');
$this->assertEquals('2019-02-28', $due_date->format('Y-m-d'));
}
2020-09-14 13:11:46 +02:00
}