From 7436f94feba59addab49885bdd19de1669f4a71c Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 4 Nov 2023 14:26:35 +0100 Subject: [PATCH] Fix code quality and run. --- .ci/php-cs-fixer/.php-cs-fixer.php | 3 +- app/Models/TransactionCurrency.php | 6 +- .../NavigationCustomEndOfPeriodTest.php | 2 +- tests/integration/TestCase.php | 2 +- .../Support/Calendar/CalculatorProvider.php | 114 +++++++++--------- .../unit/Support/Calendar/CalculatorTest.php | 8 +- .../Calendar/Periodicity/IntervalTestCase.php | 4 +- .../unit/Support/NavigationAddPeriodTest.php | 16 +-- .../Support/NavigationEndOfPeriodTest.php | 8 +- ...ationPreferredCarbonFormatByPeriodTest.php | 4 +- .../NavigationPreferredCarbonFormatTest.php | 4 +- .../NavigationPreferredEndOfPeriodTest.php | 4 +- .../NavigationPreferredRangeFormatTest.php | 4 +- .../NavigationPreferredSqlFormatTest.php | 4 +- .../Support/NavigationStartOfPeriodTest.php | 8 +- 15 files changed, 96 insertions(+), 95 deletions(-) diff --git a/.ci/php-cs-fixer/.php-cs-fixer.php b/.ci/php-cs-fixer/.php-cs-fixer.php index a6af9177fd..0b8f9d46a0 100644 --- a/.ci/php-cs-fixer/.php-cs-fixer.php +++ b/.ci/php-cs-fixer/.php-cs-fixer.php @@ -41,6 +41,7 @@ return $config->setRules([ 'declare_strict_types' => true, 'strict_param' => true, 'array_syntax' => ['syntax' => 'short'], - 'native_function_invocation' => false, + 'native_function_invocation' => false, // annoying + 'php_unit_data_provider_name' => false, // bloody annoying long test names ]) ->setFinder($finder); diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php index 7aa407fe5c..7a77c887eb 100644 --- a/app/Models/TransactionCurrency.php +++ b/app/Models/TransactionCurrency.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Models; +use Carbon\Carbon; use Eloquent; use FireflyIII\User; use Illuminate\Database\Eloquent\Collection; @@ -31,7 +32,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Query\Builder; -use Carbon\Carbon; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -42,8 +42,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property Carbon|null $updated_at * @property Carbon|null $deleted_at * @property bool $enabled - * @property bool $userDefault - * @property bool $userEnabled + * @property bool|null $userDefault + * @property bool|null $userEnabled * @property string $code * @property string $name * @property string $symbol diff --git a/tests/integration/Support/NavigationCustomEndOfPeriodTest.php b/tests/integration/Support/NavigationCustomEndOfPeriodTest.php index bdada89779..6afb052577 100644 --- a/tests/integration/Support/NavigationCustomEndOfPeriodTest.php +++ b/tests/integration/Support/NavigationCustomEndOfPeriodTest.php @@ -42,6 +42,6 @@ class NavigationCustomEndOfPeriodTest extends TestCase $navigation = new Navigation(); $period = $navigation->endOfPeriod($from, 'custom'); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); } } diff --git a/tests/integration/TestCase.php b/tests/integration/TestCase.php index e0990a65b6..6ad60b6aab 100644 --- a/tests/integration/TestCase.php +++ b/tests/integration/TestCase.php @@ -31,8 +31,8 @@ use Tests\integration\Traits\CollectsValues; */ abstract class TestCase extends BaseTestCase { - use CreatesApplication; use CollectsValues; + use CreatesApplication; protected const MAX_ITERATIONS = 2; diff --git a/tests/unit/Support/Calendar/CalculatorProvider.php b/tests/unit/Support/Calendar/CalculatorProvider.php index 50b39a315c..5ce4f90828 100644 --- a/tests/unit/Support/Calendar/CalculatorProvider.php +++ b/tests/unit/Support/Calendar/CalculatorProvider.php @@ -48,69 +48,69 @@ readonly class CalculatorProvider public static function providePeriodicityWithSkippedIntervals(): Generator { $intervals = [ - CalculatorProvider::from(Periodicity::Daily, new IntervalProvider(Carbon::now(), Carbon::now()->addDays(2)), 1), - CalculatorProvider::from(Periodicity::Daily, new IntervalProvider(Carbon::now(), Carbon::now()->addDays(3)), 2), - CalculatorProvider::from(Periodicity::Daily, new IntervalProvider(Carbon::parse('2023-01-31'), Carbon::parse('2023-02-11')), 10), + self::from(Periodicity::Daily, new IntervalProvider(Carbon::now(), Carbon::now()->addDays(2)), 1), + self::from(Periodicity::Daily, new IntervalProvider(Carbon::now(), Carbon::now()->addDays(3)), 2), + self::from(Periodicity::Daily, new IntervalProvider(Carbon::parse('2023-01-31'), Carbon::parse('2023-02-11')), 10), - CalculatorProvider::from(Periodicity::Weekly, new IntervalProvider(Carbon::now(), Carbon::now()->addWeeks(3)), 2), - CalculatorProvider::from(Periodicity::Weekly, new IntervalProvider(Carbon::parse('2023-01-31'), Carbon::parse('2023-02-14')), 1), + self::from(Periodicity::Weekly, new IntervalProvider(Carbon::now(), Carbon::now()->addWeeks(3)), 2), + self::from(Periodicity::Weekly, new IntervalProvider(Carbon::parse('2023-01-31'), Carbon::parse('2023-02-14')), 1), - CalculatorProvider::from(Periodicity::Fortnightly, new IntervalProvider(Carbon::now(), Carbon::now()->addWeeks(4)), 1), - CalculatorProvider::from(Periodicity::Fortnightly, new IntervalProvider(Carbon::parse('2023-01-29'), Carbon::parse('2023-02-26')), 1), - CalculatorProvider::from(Periodicity::Fortnightly, new IntervalProvider(Carbon::parse('2023-01-30'), Carbon::parse('2023-02-27')), 1), - CalculatorProvider::from(Periodicity::Fortnightly, new IntervalProvider(Carbon::parse('2023-01-31'), Carbon::parse('2023-02-28')), 1), + self::from(Periodicity::Fortnightly, new IntervalProvider(Carbon::now(), Carbon::now()->addWeeks(4)), 1), + self::from(Periodicity::Fortnightly, new IntervalProvider(Carbon::parse('2023-01-29'), Carbon::parse('2023-02-26')), 1), + self::from(Periodicity::Fortnightly, new IntervalProvider(Carbon::parse('2023-01-30'), Carbon::parse('2023-02-27')), 1), + self::from(Periodicity::Fortnightly, new IntervalProvider(Carbon::parse('2023-01-31'), Carbon::parse('2023-02-28')), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(2)), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2019-12-30'), Carbon::parse('2020-02-29')), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2019-12-31'), Carbon::parse('2020-02-29')), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-01-29'), Carbon::parse('2020-03-29')), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-01-31'), Carbon::parse('2020-09-30')), 7), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-12-29'), Carbon::parse('2021-02-28')), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-12-30'), Carbon::parse('2021-02-28')), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-12-31'), Carbon::parse('2021-02-28')), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-03-31'), Carbon::parse('2023-11-30')), 7), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-05-31'), Carbon::parse('2023-08-31')), 2), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-07-31'), Carbon::parse('2023-09-30')), 1), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-10-30'), Carbon::parse('2024-02-29')), 3), - CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-10-31'), Carbon::parse('2024-02-29')), 3), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(2)), 1), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2019-12-30'), Carbon::parse('2020-02-29')), 1), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2019-12-31'), Carbon::parse('2020-02-29')), 1), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-01-29'), Carbon::parse('2020-03-29')), 1), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-01-31'), Carbon::parse('2020-09-30')), 7), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-12-29'), Carbon::parse('2021-02-28')), 1), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-12-30'), Carbon::parse('2021-02-28')), 1), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2020-12-31'), Carbon::parse('2021-02-28')), 1), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-03-31'), Carbon::parse('2023-11-30')), 7), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-05-31'), Carbon::parse('2023-08-31')), 2), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-07-31'), Carbon::parse('2023-09-30')), 1), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-10-30'), Carbon::parse('2024-02-29')), 3), + self::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-10-31'), Carbon::parse('2024-02-29')), 3), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(6)), 2), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-29'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-30'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-31'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-10-30'), Carbon::parse('2020-02-29')), 1), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-10-31'), Carbon::parse('2020-02-29')), 1), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2021-02-28')), 5), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-29'), Carbon::parse('2021-02-28')), 2), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-30'), Carbon::parse('2021-02-28')), 2), - CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-31'), Carbon::parse('2021-02-28')), 2), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(6)), 2), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-29'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-30'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-31'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-10-30'), Carbon::parse('2020-02-29')), 1), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-10-31'), Carbon::parse('2020-02-29')), 1), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2021-02-28')), 5), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-29'), Carbon::parse('2021-02-28')), 2), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-30'), Carbon::parse('2021-02-28')), 2), + self::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-31'), Carbon::parse('2021-02-28')), 2), - CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(9)), 2), - CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-29'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-30'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-31'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2021-02-28')), 3), - CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2020-08-29'), Carbon::parse('2021-02-28')), 1), - CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2020-08-30'), Carbon::parse('2021-02-28')), 1), - CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2020-08-31'), Carbon::parse('2021-02-28')), 1), + self::from(Periodicity::Quarterly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(9)), 2), + self::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-29'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-30'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-31'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2021-02-28')), 3), + self::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2020-08-29'), Carbon::parse('2021-02-28')), 1), + self::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2020-08-30'), Carbon::parse('2021-02-28')), 1), + self::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2020-08-31'), Carbon::parse('2021-02-28')), 1), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(12)), 1), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(18)), 2), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(24)), 3), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2018-08-29'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2018-08-30'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2018-08-31'), Carbon::parse('2020-02-29')), 2), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2019-01-31'), Carbon::parse('2021-01-31')), 3), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2019-02-28'), Carbon::parse('2021-08-28')), 4), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-01-31'), Carbon::parse('2021-01-31')), 1), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2021-02-28')), 1), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-08-29'), Carbon::parse('2022-02-28')), 2), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-08-30'), Carbon::parse('2022-02-28')), 2), - CalculatorProvider::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-08-31'), Carbon::parse('2022-02-28')), 2), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(12)), 1), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(18)), 2), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(24)), 3), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2018-08-29'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2018-08-30'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2018-08-31'), Carbon::parse('2020-02-29')), 2), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2019-01-31'), Carbon::parse('2021-01-31')), 3), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2019-02-28'), Carbon::parse('2021-08-28')), 4), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-01-31'), Carbon::parse('2021-01-31')), 1), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2021-02-28')), 1), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-08-29'), Carbon::parse('2022-02-28')), 2), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-08-30'), Carbon::parse('2022-02-28')), 2), + self::from(Periodicity::HalfYearly, new IntervalProvider(Carbon::parse('2020-08-31'), Carbon::parse('2022-02-28')), 2), - CalculatorProvider::from(Periodicity::Yearly, new IntervalProvider(Carbon::now(), Carbon::now()->addYearsNoOverflow(3)), 2), - CalculatorProvider::from(Periodicity::Yearly, new IntervalProvider(Carbon::parse('2019-01-29'), Carbon::parse('2025-01-29')), 5), - CalculatorProvider::from(Periodicity::Yearly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2031-02-28')), 10), + self::from(Periodicity::Yearly, new IntervalProvider(Carbon::now(), Carbon::now()->addYearsNoOverflow(3)), 2), + self::from(Periodicity::Yearly, new IntervalProvider(Carbon::parse('2019-01-29'), Carbon::parse('2025-01-29')), 5), + self::from(Periodicity::Yearly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2031-02-28')), 10), ]; /** @var IntervalProvider $interval */ @@ -119,7 +119,7 @@ readonly class CalculatorProvider } } - public static function from(Periodicity $periodicity, IntervalProvider $interval, int $skip = 0): CalculatorProvider + public static function from(Periodicity $periodicity, IntervalProvider $interval, int $skip = 0): self { return new self($interval, $periodicity, $skip); } diff --git a/tests/unit/Support/Calendar/CalculatorTest.php b/tests/unit/Support/Calendar/CalculatorTest.php index 0b96509464..afff0e9986 100644 --- a/tests/unit/Support/Calendar/CalculatorTest.php +++ b/tests/unit/Support/Calendar/CalculatorTest.php @@ -48,7 +48,7 @@ use Tests\unit\Support\Calendar\Periodicity\YearlyTest; */ class CalculatorTest extends TestCase { - public static function provideAllPeriodicity(): Generator + public static function provideAllPeriodicity(): iterable { $intervals = []; $intervals = array_merge($intervals, self::convert(Periodicity::Daily, DailyTest::provideIntervals())); @@ -78,7 +78,7 @@ class CalculatorTest extends TestCase return $periodicityIntervals; } - public static function provideSkippedIntervals(): Generator + public static function provideSkippedIntervals(): iterable { return CalculatorProvider::providePeriodicityWithSkippedIntervals(); } @@ -91,7 +91,7 @@ class CalculatorTest extends TestCase { $calculator = new Calculator(); $period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity); - $this->assertEquals($provider->expected()->toDateString(), $period->toDateString()); + self::assertSame($provider->expected()->toDateString(), $period->toDateString()); } /** @@ -102,6 +102,6 @@ class CalculatorTest extends TestCase { $calculator = new Calculator(); $period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity, $provider->skip); - $this->assertEquals($provider->expected()->toDateString(), $period->toDateString()); + self::assertSame($provider->expected()->toDateString(), $period->toDateString()); } } diff --git a/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php b/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php index 29f6679a44..f1a909ff42 100644 --- a/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php +++ b/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php @@ -31,7 +31,7 @@ use PHPUnit\Framework\TestCase; abstract class IntervalTestCase extends TestCase { - public static function provider(): Generator + public static function provider(): iterable { $intervals = static::provideIntervals(); /** @var IntervalProvider $interval */ @@ -52,7 +52,7 @@ abstract class IntervalTestCase extends TestCase public function testGivenAnEpochWhenCallTheNextDateThenReturnsTheExpectedDateSuccessful(IntervalProvider $provider): void { $period = static::factory()->nextDate($provider->epoch); - $this->assertEquals($provider->expected->toDateString(), $period->toDateString()); + self::assertSame($provider->expected->toDateString(), $period->toDateString()); } abstract public static function factory(): Interval; diff --git a/tests/unit/Support/NavigationAddPeriodTest.php b/tests/unit/Support/NavigationAddPeriodTest.php index a74be42f73..fa321ca07c 100644 --- a/tests/unit/Support/NavigationAddPeriodTest.php +++ b/tests/unit/Support/NavigationAddPeriodTest.php @@ -45,7 +45,7 @@ class NavigationAddPeriodTest extends TestCase $this->navigation = new Navigation(); } - public static function provideFrequencies(): array + public static function provideFrequencies(): iterable { return [ Periodicity::Daily->name => ['periodicity' => Periodicity::Daily, 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], @@ -73,7 +73,7 @@ class NavigationAddPeriodTest extends TestCase ]; } - public static function provideMonthPeriods(): array + public static function provideMonthPeriods(): iterable { return [ '1M' => ['frequency' => '1M', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonthsNoOverflow(1)], @@ -89,7 +89,7 @@ class NavigationAddPeriodTest extends TestCase ]; } - public static function providePeriods(): array + public static function providePeriods(): iterable { return [ '1D' => ['frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], @@ -115,7 +115,7 @@ class NavigationAddPeriodTest extends TestCase ]; } - public static function providePeriodsWithSkippingParam(): Generator + public static function providePeriodsWithSkippingParam(): iterable { $intervals = [ '2019-01-31 to 2019-02-11' => ['skip' => 10, 'frequency' => 'daily', 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-02-11')], @@ -166,7 +166,7 @@ class NavigationAddPeriodTest extends TestCase public function testGivenAFrequencyAndSkipIntervalWhenCalculateTheDateThenReturnsTheSkippedDateSuccessful(int $skip, string $frequency, Carbon $from, Carbon $expected) { $period = $this->navigation->addPeriod($from, $frequency, $skip); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); } /** @@ -175,7 +175,7 @@ class NavigationAddPeriodTest extends TestCase public function testGivenAFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) { $period = $this->navigation->addPeriod($from, $frequency, 0); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); } /** @@ -184,7 +184,7 @@ class NavigationAddPeriodTest extends TestCase public function testGivenAIntervalWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(Periodicity $periodicity, Carbon $from, Carbon $expected) { $period = $this->navigation->nextDateByInterval($from, $periodicity); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); } /** @@ -193,6 +193,6 @@ class NavigationAddPeriodTest extends TestCase public function testGivenAMonthFrequencyWhenCalculateTheDateThenReturnsTheLastDayOfMonthSuccessful(string $frequency, Carbon $from, Carbon $expected) { $period = $this->navigation->addPeriod($from, $frequency, 0); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); } } diff --git a/tests/unit/Support/NavigationEndOfPeriodTest.php b/tests/unit/Support/NavigationEndOfPeriodTest.php index af86ed7f03..42a71ace03 100644 --- a/tests/unit/Support/NavigationEndOfPeriodTest.php +++ b/tests/unit/Support/NavigationEndOfPeriodTest.php @@ -43,7 +43,7 @@ class NavigationEndOfPeriodTest extends TestCase $this->navigation = new Navigation(); } - public static function provideDates(): array + public static function provideDates(): iterable { return [ '1D' => ['frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::now()->endOfDay()], @@ -79,10 +79,10 @@ class NavigationEndOfPeriodTest extends TestCase public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) { $period = $this->navigation->endOfPeriod($from, $frequency); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); } - public static function provideUnknownFrequencies(): array + public static function provideUnknownFrequencies(): iterable { return [ '1day' => ['frequency' => '1day', 'from' => Carbon::now(), 'expected' => Carbon::now()], @@ -99,7 +99,7 @@ class NavigationEndOfPeriodTest extends TestCase Log::spy(); $period = $this->navigation->endOfPeriod($from, $frequency); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); $expectedMessage = sprintf('Cannot do endOfPeriod for $repeat_freq "%s"', $frequency); Log::shouldHaveReceived('error', [$expectedMessage]); diff --git a/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php b/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php index 62b4c2388d..8919eac544 100644 --- a/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php +++ b/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php @@ -42,7 +42,7 @@ class NavigationPreferredCarbonFormatByPeriodTest extends TestCase $this->navigation = new Navigation(); } - public static function providePeriods(): array + public static function providePeriods(): iterable { return [ 'unknown' => ['period' => '1day', 'expected' => 'Y-m-d'], @@ -60,6 +60,6 @@ class NavigationPreferredCarbonFormatByPeriodTest extends TestCase public function testGivenAPeriodWhenCallPreferredCarbonFormatByPeriodThenReturnsExpectedFormat(string $period, string $expected) { $formatPeriod = $this->navigation->preferredCarbonFormatByPeriod($period); - $this->assertEquals($expected, $formatPeriod); + self::assertSame($expected, $formatPeriod); } } diff --git a/tests/unit/Support/NavigationPreferredCarbonFormatTest.php b/tests/unit/Support/NavigationPreferredCarbonFormatTest.php index ad82ee8548..e0ba35bfa2 100644 --- a/tests/unit/Support/NavigationPreferredCarbonFormatTest.php +++ b/tests/unit/Support/NavigationPreferredCarbonFormatTest.php @@ -43,7 +43,7 @@ class NavigationPreferredCarbonFormatTest extends TestCase $this->navigation = new Navigation(); } - public static function providePeriods(): array + public static function providePeriods(): iterable { return [ '1 week' => ['start' => Carbon::now(), 'end' => Carbon::now()->addWeek(), 'expected' => 'Y-m-d'], @@ -67,6 +67,6 @@ class NavigationPreferredCarbonFormatTest extends TestCase public function testGivenStartAndEndDatesWhenCallPreferredCarbonFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected) { $carbonFormat = $this->navigation->preferredCarbonFormat($start, $end); - $this->assertEquals($expected, $carbonFormat); + self::assertSame($expected, $carbonFormat); } } diff --git a/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php b/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php index f9d74d2aa8..fadfc42414 100644 --- a/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php +++ b/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php @@ -43,7 +43,7 @@ class NavigationPreferredEndOfPeriodTest extends TestCase $this->navigation = new Navigation(); } - public static function providePeriods(): array + public static function providePeriods(): iterable { return [ '1 week' => ['start' => Carbon::now(), 'end' => Carbon::now()->addWeek(), 'expected' => 'endOfDay'], @@ -67,6 +67,6 @@ class NavigationPreferredEndOfPeriodTest extends TestCase public function testGivenStartAndEndDatesWhenCallPreferredEndOfPeriodThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected) { $formatPeriod = $this->navigation->preferredEndOfPeriod($start, $end); - $this->assertEquals($expected, $formatPeriod); + self::assertSame($expected, $formatPeriod); } } diff --git a/tests/unit/Support/NavigationPreferredRangeFormatTest.php b/tests/unit/Support/NavigationPreferredRangeFormatTest.php index 10b18c2544..7280d373ee 100644 --- a/tests/unit/Support/NavigationPreferredRangeFormatTest.php +++ b/tests/unit/Support/NavigationPreferredRangeFormatTest.php @@ -43,7 +43,7 @@ class NavigationPreferredRangeFormatTest extends TestCase $this->navigation = new Navigation(); } - public static function providePeriods(): array + public static function providePeriods(): iterable { return [ '1 week' => ['start' => Carbon::now(), 'end' => Carbon::now()->addWeek(), 'expected' => '1D'], @@ -67,6 +67,6 @@ class NavigationPreferredRangeFormatTest extends TestCase public function testGivenStartAndEndDatesWhenCallPreferredRangeFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected) { $formatPeriod = $this->navigation->preferredRangeFormat($start, $end); - $this->assertEquals($expected, $formatPeriod); + self::assertSame($expected, $formatPeriod); } } diff --git a/tests/unit/Support/NavigationPreferredSqlFormatTest.php b/tests/unit/Support/NavigationPreferredSqlFormatTest.php index 2af197b535..2b2c2942c8 100644 --- a/tests/unit/Support/NavigationPreferredSqlFormatTest.php +++ b/tests/unit/Support/NavigationPreferredSqlFormatTest.php @@ -43,7 +43,7 @@ class NavigationPreferredSqlFormatTest extends TestCase $this->navigation = new Navigation(); } - public static function provideDates(): array + public static function provideDates(): iterable { return [ '1 week' => ['start' => Carbon::now(), 'end' => Carbon::now()->addWeek(), 'expected' => '%Y-%m-%d'], @@ -67,6 +67,6 @@ class NavigationPreferredSqlFormatTest extends TestCase public function testGivenStartAndEndDatesWhenCallPreferredSqlFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected) { $formatPeriod = $this->navigation->preferredSqlFormat($start, $end); - $this->assertEquals($expected, $formatPeriod); + self::assertSame($expected, $formatPeriod); } } diff --git a/tests/unit/Support/NavigationStartOfPeriodTest.php b/tests/unit/Support/NavigationStartOfPeriodTest.php index ca92a8d9ba..ed304ca713 100644 --- a/tests/unit/Support/NavigationStartOfPeriodTest.php +++ b/tests/unit/Support/NavigationStartOfPeriodTest.php @@ -44,7 +44,7 @@ class NavigationStartOfPeriodTest extends TestCase $this->navigation = new Navigation(); } - public static function provideDates(): array + public static function provideDates(): iterable { return [ 'custom' => ['frequency' => 'custom', 'from' => Carbon::now(), 'expected' => Carbon::now()], @@ -74,7 +74,7 @@ class NavigationStartOfPeriodTest extends TestCase ]; } - public static function provideUnknownFrequencies(): array + public static function provideUnknownFrequencies(): iterable { return [ '1day' => ['frequency' => '1day', 'from' => Carbon::now(), 'expected' => Carbon::now()], @@ -89,7 +89,7 @@ class NavigationStartOfPeriodTest extends TestCase public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) { $period = $this->navigation->startOfPeriod($from, $frequency); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); } /** @@ -102,6 +102,6 @@ class NavigationStartOfPeriodTest extends TestCase ->andReturnNull(); $period = $this->navigation->startOfPeriod($from, $frequency); - $this->assertEquals($expected->toDateString(), $period->toDateString()); + self::assertSame($expected->toDateString(), $period->toDateString()); } }