Files
firefly-iii/tests/integration/Support/Models/BillDateCalculatorTest.php

83 lines
3.3 KiB
PHP
Raw Normal View History

2023-11-26 07:19:57 +01:00
<?php
2023-11-26 07:19:57 +01:00
/*
* BillDateCalculatorTest.php
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\integration\Support\Models;
2025-05-27 17:09:35 +02:00
use Override;
2023-11-26 07:19:57 +01:00
use Carbon\Carbon;
use FireflyIII\Support\Models\BillDateCalculator;
2025-05-24 06:07:59 +02:00
use PHPUnit\Framework\Attributes\DataProvider;
2023-11-26 07:19:57 +01:00
use Tests\integration\TestCase;
/**
* Class BillDateCalculatorTest
2023-12-20 19:45:12 +01:00
*
* @internal
*
* @coversNothing
2023-11-26 07:19:57 +01:00
*/
2023-12-20 19:45:12 +01:00
final class BillDateCalculatorTest extends TestCase
2023-11-26 07:19:57 +01:00
{
private BillDateCalculator $calculator;
2023-11-26 07:19:57 +01:00
2025-05-27 17:09:35 +02:00
#[Override]
protected function setUp(): void
2023-11-26 07:19:57 +01:00
{
2025-05-24 06:07:59 +02:00
parent::setUp();
2023-11-26 07:19:57 +01:00
$this->calculator = new BillDateCalculator();
}
2025-02-23 12:28:27 +01:00
/**
* Stupid long method names I'm not going to do that.
*/
2025-05-24 06:07:59 +02:00
#[DataProvider('provideDates')]
2025-02-23 12:28:27 +01:00
public function testGivenSomeDataItWorks(Carbon $earliest, Carbon $latest, Carbon $billStart, string $period, int $skip, ?Carbon $lastPaid, array $expected): void
{
$result = $this->calculator->getPayDates($earliest, $latest, $billStart, $period, $skip, $lastPaid);
$this->assertSame($expected, $result);
2025-02-23 12:28:27 +01:00
}
public static function provideDates(): iterable
2023-11-26 07:19:57 +01:00
{
// Carbon $earliest, Carbon $latest, Carbon $billStart, string $period, int $skip, ?Carbon $lastPaid
2025-05-27 17:09:35 +02:00
// basic monthly bill.x
yield '1Ma' => [Carbon::parse('2023-11-01'), Carbon::parse('2023-11-30'), Carbon::parse('2023-01-01'), 'monthly', 0, null, ['2023-11-01']];
2023-11-26 12:10:42 +01:00
2025-05-27 17:09:35 +02:00
// already paid on the first, expect it next month.
yield '1Mb' => [Carbon::parse('2023-11-01'), Carbon::parse('2023-11-30'), Carbon::parse('2023-01-01'), 'monthly', 0, Carbon::parse('2023-11-01'), ['2023-12-01']];
2025-05-27 17:09:35 +02:00
// already paid on the 12th, expect it next month.
yield '1Mc' => [Carbon::parse('2023-11-01'), Carbon::parse('2023-11-30'), Carbon::parse('2023-01-01'), 'monthly', 0, Carbon::parse('2023-11-12'), ['2023-12-01']];
2025-05-27 17:09:35 +02:00
// every month, start on 2024-01-30, view is quarterly
yield '1Md' => [Carbon::parse('2023-01-01'), Carbon::parse('2023-03-31'), Carbon::parse('2023-01-29'), 'monthly', 0, null, ['2023-01-29', '2023-02-28', '2023-03-29']];
// every month, start on 2024-01-30, view is quarterly
yield '1Me' => [Carbon::parse('2024-01-01'), Carbon::parse('2024-03-31'), Carbon::parse('2023-01-30'), 'monthly', 0, null, ['2024-01-30', '2024-02-29', '2024-03-30']];
// yearly not due this month. Should jump to next year.
yield '1Ya' => [Carbon::parse('2023-11-01'), Carbon::parse('2023-11-30'), Carbon::parse('2021-05-01'), 'yearly', 0, Carbon::parse('2023-05-02'), ['2024-05-01']];
2023-11-26 07:19:57 +01:00
}
}