Fix phpunit tests

This commit is contained in:
James Cole
2025-05-24 06:07:59 +02:00
parent 3716b50616
commit d26d1b4b87
13 changed files with 77 additions and 52 deletions

View File

@@ -27,6 +27,7 @@ namespace Tests\unit\Support\Calendar;
use FireflyIII\Exceptions\IntervalException;
use FireflyIII\Support\Calendar\Calculator;
use FireflyIII\Support\Calendar\Periodicity;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
use Tests\unit\Support\Calendar\Periodicity\BimonthlyTest;
use Tests\unit\Support\Calendar\Periodicity\DailyTest;
@@ -65,10 +66,11 @@ final class CalculatorTest extends TestCase
}
/**
* @dataProvider provideAllPeriodicity
*
*
* @throws IntervalException
*/
#[DataProvider('provideAllPeriodicity')]
public function testGivenADailyPeriodicityWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider): void
{
$calculator = new Calculator();
@@ -95,10 +97,11 @@ final class CalculatorTest extends TestCase
}
/**
* @dataProvider provideSkippedIntervals
*
*
* @throws IntervalException
*/
#[DataProvider('provideSkippedIntervals')]
public function testGivenAnEpochWithSkipIntervalNumberWhenCallTheNextDateBySkippedIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider): void
{
$calculator = new Calculator();

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace Tests\unit\Support\Calendar\Periodicity;
use FireflyIII\Support\Calendar\Periodicity\Interval;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
abstract class IntervalTestCase extends TestCase
@@ -32,8 +33,9 @@ abstract class IntervalTestCase extends TestCase
abstract public static function provideIntervals(): array;
/**
* @dataProvider provider
*
*/
#[DataProvider('provider')]
public function testGivenAnEpochWhenCallTheNextDateThenReturnsTheExpectedDateSuccessful(IntervalProvider $provider): void
{
$period = static::factory()->nextDate($provider->epoch);

View File

@@ -27,6 +27,7 @@ namespace Tests\unit\Support;
use Carbon\Carbon;
use FireflyIII\Support\Calendar\Periodicity;
use FireflyIII\Support\Navigation;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -40,17 +41,18 @@ use Tests\integration\TestCase;
*/
final class NavigationAddPeriodTest extends TestCase
{
private readonly Navigation $navigation;
private Navigation $navigation;
public function __construct(string $name)
public function setUp(): void
{
parent::__construct($name);
parent::setUp();
$this->navigation = new Navigation();
}
/**
* @dataProvider providePeriodsWithSkippingParam
*
*/
#[DataProvider('providePeriodsWithSkippingParam')]
public function testGivenAFrequencyAndSkipIntervalWhenCalculateTheDateThenReturnsTheSkippedDateSuccessful(int $skip, string $frequency, Carbon $from, Carbon $expected): void
{
$period = $this->navigation->addPeriod($from, $frequency, $skip);
@@ -103,8 +105,9 @@ final class NavigationAddPeriodTest extends TestCase
}
/**
* @dataProvider providePeriods
*
*/
#[DataProvider('providePeriods')]
public function testGivenAFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void
{
$period = $this->navigation->addPeriod($from, $frequency, 0);
@@ -138,8 +141,9 @@ final class NavigationAddPeriodTest extends TestCase
}
/**
* @dataProvider provideFrequencies
*
*/
#[DataProvider('provideFrequencies')]
public function testGivenAIntervalWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(Periodicity $periodicity, Carbon $from, Carbon $expected): void
{
$period = $this->navigation->nextDateByInterval($from, $periodicity);
@@ -175,8 +179,9 @@ final class NavigationAddPeriodTest extends TestCase
}
/**
* @dataProvider provideMonthPeriods
*
*/
#[DataProvider('provideMonthPeriods')]
public function testGivenAMonthFrequencyWhenCalculateTheDateThenReturnsTheLastDayOfMonthSuccessful(string $frequency, Carbon $from, Carbon $expected): void
{
$period = $this->navigation->addPeriod($from, $frequency, 0);

View File

@@ -26,6 +26,7 @@ namespace Tests\unit\Support;
use Carbon\Carbon;
use FireflyIII\Support\Navigation;
use Illuminate\Support\Facades\Log;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -39,17 +40,18 @@ use Tests\integration\TestCase;
*/
final class NavigationEndOfPeriodTest extends TestCase
{
private readonly Navigation $navigation;
private Navigation $navigation;
public function __construct(string $name)
public function setUp(): void
{
parent::__construct($name);
parent::setUp();
$this->navigation = new Navigation();
}
/**
* @dataProvider provideDates
*
*/
#[DataProvider('provideDates')]
public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void
{
$period = clone $this->navigation->endOfPeriod($from, $frequency);
@@ -88,8 +90,9 @@ final class NavigationEndOfPeriodTest extends TestCase
}
/**
* @dataProvider provideUnknownFrequencies
*
*/
#[DataProvider('provideUnknownFrequencies')]
public function testGivenADateAndUnknownFrequencyWhenCalculateTheDateThenReturnsTheSameDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void
{
Log::spy();

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace Tests\unit\Support;
use FireflyIII\Support\Navigation;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -38,17 +39,18 @@ use Tests\integration\TestCase;
*/
final class NavigationPreferredCarbonFormatByPeriodTest extends TestCase
{
private readonly Navigation $navigation;
private Navigation $navigation;
public function __construct(string $name)
public function setUp(): void
{
parent::__construct($name);
parent::setUp();
$this->navigation = new Navigation();
}
/**
* @dataProvider providePeriods
*
*/
#[DataProvider('providePeriods')]
public function testGivenAPeriodWhenCallPreferredCarbonFormatByPeriodThenReturnsExpectedFormat(string $period, string $expected): void
{
$formatPeriod = $this->navigation->preferredCarbonFormatByPeriod($period);

View File

@@ -26,6 +26,7 @@ namespace Tests\unit\Support;
use Carbon\Carbon;
use FireflyIII\Support\Navigation;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -39,17 +40,18 @@ use Tests\integration\TestCase;
*/
final class NavigationPreferredCarbonFormatTest extends TestCase
{
private readonly Navigation $navigation;
private Navigation $navigation;
public function __construct(string $name)
public function setUp(): void
{
parent::__construct($name);
parent::setUp();
$this->navigation = new Navigation();
}
/**
* @dataProvider providePeriods
*
*/
#[DataProvider('providePeriods')]
public function testGivenStartAndEndDatesWhenCallPreferredCarbonFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void
{
$carbonFormat = $this->navigation->preferredCarbonFormat($start, $end);

View File

@@ -26,6 +26,7 @@ namespace Tests\unit\Support;
use Carbon\Carbon;
use FireflyIII\Support\Navigation;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -39,17 +40,18 @@ use Tests\integration\TestCase;
*/
final class NavigationPreferredEndOfPeriodTest extends TestCase
{
private readonly Navigation $navigation;
private Navigation $navigation;
public function __construct(string $name)
public function setUp(): void
{
parent::__construct($name);
parent::setUp();
$this->navigation = new Navigation();
}
/**
* @dataProvider providePeriods
*
*/
#[DataProvider('providePeriods')]
public function testGivenStartAndEndDatesWhenCallPreferredEndOfPeriodThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void
{
$formatPeriod = $this->navigation->preferredEndOfPeriod($start, $end);

View File

@@ -26,6 +26,7 @@ namespace Tests\unit\Support;
use Carbon\Carbon;
use FireflyIII\Support\Navigation;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -39,17 +40,17 @@ use Tests\integration\TestCase;
*/
final class NavigationPreferredRangeFormatTest extends TestCase
{
private readonly Navigation $navigation;
private Navigation $navigation;
public function __construct(string $name)
public function setUp(): void
{
parent::__construct($name);
parent::setUp();
$this->navigation = new Navigation();
}
/**
* @dataProvider providePeriods
*
*/
#[DataProvider('providePeriods')]
public function testGivenStartAndEndDatesWhenCallPreferredRangeFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void
{
$formatPeriod = $this->navigation->preferredRangeFormat($start, $end);

View File

@@ -26,6 +26,7 @@ namespace Tests\unit\Support;
use Carbon\Carbon;
use FireflyIII\Support\Navigation;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -39,17 +40,18 @@ use Tests\integration\TestCase;
*/
final class NavigationPreferredSqlFormatTest extends TestCase
{
private readonly Navigation $navigation;
public function __construct(string $name)
private Navigation $navigation;
public function setUp(): void
{
parent::__construct($name);
parent::setUp();
$this->navigation = new Navigation();
}
/**
* @dataProvider provideDates
*
*/
#[DataProvider('provideDates')]
public function testGivenStartAndEndDatesWhenCallPreferredSqlFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void
{
$formatPeriod = $this->navigation->preferredSqlFormat($start, $end);

View File

@@ -27,6 +27,7 @@ namespace Tests\unit\Support;
use Carbon\Carbon;
use FireflyIII\Support\Navigation;
use Illuminate\Support\Facades\Log;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -40,17 +41,17 @@ use Tests\integration\TestCase;
*/
final class NavigationStartOfPeriodTest extends TestCase
{
private readonly Navigation $navigation;
private Navigation $navigation;
public function __construct(string $name)
public function setUp(): void
{
parent::__construct($name);
parent::setUp();
$this->navigation = new Navigation();
}
/**
* @dataProvider provideDates
*
*/
#[DataProvider('provideDates')]
public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void
{
$period = $this->navigation->startOfPeriod($from, $frequency);
@@ -88,8 +89,9 @@ final class NavigationStartOfPeriodTest extends TestCase
}
/**
* @dataProvider provideUnknownFrequencies
*
*/
#[DataProvider('provideUnknownFrequencies')]
public function testGivenADateAndUnknownFrequencyWhenCalculateTheDateThenReturnsTheSameDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void
{
Log::spy();

View File

@@ -9,6 +9,7 @@ use FireflyIII\Support\Search\QueryParser\QueryParserInterface;
use FireflyIII\Support\Search\QueryParser\StringNode;
use FireflyIII\Support\Search\QueryParser\NodeGroup;
use FireflyIII\Support\Search\QueryParser\Node;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
abstract class AbstractQueryParserInterfaceParseQueryTester extends TestCase
@@ -16,11 +17,12 @@ abstract class AbstractQueryParserInterfaceParseQueryTester extends TestCase
abstract protected function createParser(): QueryParserInterface;
/**
* @dataProvider queryDataProvider
*
*
* @param string $query The query string to parse
* @param Node $expected The expected parse result
*/
#[DataProvider('queryDataProvider')]
public function testQueryParsing(string $query, Node $expected): void
{
$actual = $this->createParser()->parse($query);