Skip to content

Firefly III: a personal finances manager

Fix phpunit tests

James Coled26d1b4b873a
diff --git a/tests/integration/Support/Models/BillDateCalculatorTest.php b/tests/integration/Support/Models/BillDateCalculatorTest.php
index 0120555ba5..3305bdff49 100644
--- a/tests/integration/Support/Models/BillDateCalculatorTest.php
+++ b/tests/integration/Support/Models/BillDateCalculatorTest.php
@@ -26,6 +26,7 @@ namespace Tests\integration\Support\Models;
use Carbon\Carbon;
use FireflyIII\Support\Models\BillDateCalculator;
+use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;
/**
@@ -37,19 +38,21 @@ use Tests\integration\TestCase;
*/
final class BillDateCalculatorTest extends TestCase
{
- private readonly BillDateCalculator $calculator;
+ private BillDateCalculator $calculator;
- public function __construct(string $name)
+
+ public function setUp(): void
{
- parent::__construct($name);
+ parent::setUp();
$this->calculator = new BillDateCalculator();
}
/**
* Stupid long method names I'm not going to do that.
*
- * @dataProvider provideDates
+ *
*/
+ #[DataProvider('provideDates')]
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);
diff --git a/tests/integration/Support/NavigationCustomEndOfPeriodTest.php b/tests/integration/Support/NavigationCustomEndOfPeriodTest.php
index 7cc4e9d3d8..352eb6bc3d 100644
--- a/tests/integration/Support/NavigationCustomEndOfPeriodTest.php
+++ b/tests/integration/Support/NavigationCustomEndOfPeriodTest.php
@@ -35,10 +35,6 @@ use Tests\integration\TestCase;
*/
final class NavigationCustomEndOfPeriodTest extends TestCase
{
- public function __construct(string $name)
- {
- parent::__construct($name);
- }
/**
* @preserveGlobalState disabled
diff --git a/tests/unit/Support/Calendar/CalculatorTest.php b/tests/unit/Support/Calendar/CalculatorTest.php
index 4f127bf767..abcb94ef63 100644
--- a/tests/unit/Support/Calendar/CalculatorTest.php
+++ b/tests/unit/Support/Calendar/CalculatorTest.php
@@ -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();
diff --git a/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php b/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php
index 7e4cc812bc..411191ffc4 100644
--- a/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php
+++ b/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php
@@ -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);
diff --git a/tests/unit/Support/NavigationAddPeriodTest.php b/tests/unit/Support/NavigationAddPeriodTest.php
index 4b1f301e64..0820f8c880 100644
--- a/tests/unit/Support/NavigationAddPeriodTest.php
+++ b/tests/unit/Support/NavigationAddPeriodTest.php
@@ -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);
diff --git a/tests/unit/Support/NavigationEndOfPeriodTest.php b/tests/unit/Support/NavigationEndOfPeriodTest.php
index e58b78061d..ee7e4c562f 100644
--- a/tests/unit/Support/NavigationEndOfPeriodTest.php
+++ b/tests/unit/Support/NavigationEndOfPeriodTest.php
@@ -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();
diff --git a/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php b/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php
index 34f20b66e1..7534d38a80 100644
--- a/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php
+++ b/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php
@@ -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);
diff --git a/tests/unit/Support/NavigationPreferredCarbonFormatTest.php b/tests/unit/Support/NavigationPreferredCarbonFormatTest.php
index 4c8dcef46f..a99e4952e0 100644
--- a/tests/unit/Support/NavigationPreferredCarbonFormatTest.php
+++ b/tests/unit/Support/NavigationPreferredCarbonFormatTest.php
@@ -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);
diff --git a/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php b/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php
index ba3d68d90a..2edea8324a 100644
--- a/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php
+++ b/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php
@@ -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);
diff --git a/tests/unit/Support/NavigationPreferredRangeFormatTest.php b/tests/unit/Support/NavigationPreferredRangeFormatTest.php
index 48941ef4de..5ace068d0b 100644
--- a/tests/unit/Support/NavigationPreferredRangeFormatTest.php
+++ b/tests/unit/Support/NavigationPreferredRangeFormatTest.php
@@ -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);
diff --git a/tests/unit/Support/NavigationPreferredSqlFormatTest.php b/tests/unit/Support/NavigationPreferredSqlFormatTest.php
index a2127f9d14..27a6a2ab12 100644
--- a/tests/unit/Support/NavigationPreferredSqlFormatTest.php
+++ b/tests/unit/Support/NavigationPreferredSqlFormatTest.php
@@ -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);
diff --git a/tests/unit/Support/NavigationStartOfPeriodTest.php b/tests/unit/Support/NavigationStartOfPeriodTest.php
index a1c060003c..4958003cf0 100644
--- a/tests/unit/Support/NavigationStartOfPeriodTest.php
+++ b/tests/unit/Support/NavigationStartOfPeriodTest.php
@@ -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();
diff --git a/tests/unit/Support/Search/QueryParser/AbstractQueryParserInterfaceParseQueryTester.php b/tests/unit/Support/Search/QueryParser/AbstractQueryParserInterfaceParseQueryTester.php
index 0081ac0b19..c45eca06f2 100644
--- a/tests/unit/Support/Search/QueryParser/AbstractQueryParserInterfaceParseQueryTester.php
+++ b/tests/unit/Support/Search/QueryParser/AbstractQueryParserInterfaceParseQueryTester.php
@@ -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);