Files
firefly-iii/tests/Unit/Helpers/Fiscal/FiscalHelperTest.php

178 lines
5.1 KiB
PHP
Raw Normal View History

<?php
/**
* FiscalHelperTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 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);
2019-06-21 19:10:02 +02:00
namespace Tests\Unit\Helpers\Fiscal;
use Carbon\Carbon;
2019-06-21 19:10:02 +02:00
use FireflyIII\Helpers\Fiscal\FiscalHelper;
use FireflyIII\Models\Preference;
use Log;
use Preferences;
use Tests\TestCase;
/**
*
* Class FiscalHelperTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FiscalHelperTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
2020-07-30 20:49:40 +02:00
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Fiscal year starts on April 1st.
* Current date is June 6th.
*
* Fiscal year ends next year on Mar 31.
*
2019-06-21 19:10:02 +02:00
* @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
*/
public function testEndOfFiscalYear(): void
{
$pref = new Preference;
$pref->data = true;
$datePref = new Preference;
$datePref->data = '04-01';
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
$helper = new FiscalHelper;
$date = new Carbon('2018-06-06');
$result = $helper->endOfFiscalYear($date);
$this->assertEquals('2019-03-31', $result->format('Y-m-d'));
}
/**
* No fiscal year
* Current date is June 6th.
*
* Fiscal year ends next year on Dec 31.
*
2019-06-21 19:10:02 +02:00
* @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
*/
public function testEndOfFiscalYearNoPref(): void
{
$pref = new Preference;
$pref->data = false;
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
$helper = new FiscalHelper;
$date = new Carbon('2018-06-06');
$result = $helper->endOfFiscalYear($date);
$this->assertEquals('2018-12-31', $result->format('Y-m-d'));
}
/**
* Fiscal year starts on April 1st.
* Current date is June 6th.
*
* Fiscal year starts in current year.
*
2019-06-21 19:10:02 +02:00
* @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
*/
public function testStartOfFiscalYear(): void
{
$pref = new Preference;
$pref->data = true;
$datePref = new Preference;
$datePref->data = '04-01';
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
$helper = new FiscalHelper;
$date = new Carbon('2018-06-06');
$result = $helper->startOfFiscalYear($date);
$this->assertEquals('2018-04-01', $result->format('Y-m-d'));
}
/**
* No fiscal year
* Current date is June 6th.
*
* Fiscal year starts Jan 1st.
*
2019-06-21 19:10:02 +02:00
* @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
*/
public function testStartOfFiscalYearNoPref(): void
{
$pref = new Preference;
$pref->data = false;
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
$helper = new FiscalHelper;
$date = new Carbon('2018-06-06');
$result = $helper->startOfFiscalYear($date);
$this->assertEquals('2018-01-01', $result->format('Y-m-d'));
}
/**
* Fiscal year starts on April 1st.
* Current date is Feb 6th.
*
* Fiscal year starts in previous year.
*
2019-06-21 19:10:02 +02:00
* @covers \FireflyIII\Helpers\Fiscal\FiscalHelper
*/
public function testStartOfFiscalYearPrev(): void
{
$pref = new Preference;
$pref->data = true;
$datePref = new Preference;
$datePref->data = '04-01';
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($pref)->once();
Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->andReturn($datePref)->once();
$helper = new FiscalHelper;
$date = new Carbon('2018-02-06');
$result = $helper->startOfFiscalYear($date);
$this->assertEquals('2017-04-01', $result->format('Y-m-d'));
}
2018-12-31 07:48:23 +01:00
}