From 25ebfd6978cf1f5a94f6ba117bed5b809b562485 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 23 Feb 2025 12:28:43 +0100 Subject: [PATCH] php cs cleanup --- .../Controllers/Summary/BasicController.php | 4 +- app/Api/V1/Requests/Data/DestroyRequest.php | 6 +- app/Factory/BillFactory.php | 4 +- .../Transaction/MassController.php | 4 +- app/Http/Middleware/TrustProxies.php | 10 +- .../unit/Support/Calendar/CalculatorTest.php | 62 +++---- .../Calendar/Periodicity/IntervalTestCase.php | 20 +-- .../unit/Support/NavigationAddPeriodTest.php | 152 +++++++++--------- .../Support/NavigationEndOfPeriodTest.php | 36 ++--- ...ationPreferredCarbonFormatByPeriodTest.php | 18 +-- .../NavigationPreferredCarbonFormatTest.php | 18 +-- .../NavigationPreferredEndOfPeriodTest.php | 18 +-- .../NavigationPreferredRangeFormatTest.php | 18 +-- .../NavigationPreferredSqlFormatTest.php | 18 +-- .../Support/NavigationStartOfPeriodTest.php | 36 ++--- ...ctQueryParserInterfaceParseQueryTester.php | 28 ++-- 16 files changed, 226 insertions(+), 226 deletions(-) diff --git a/app/Api/V1/Controllers/Summary/BasicController.php b/app/Api/V1/Controllers/Summary/BasicController.php index addd31b8eb..cb0a7bbb96 100644 --- a/app/Api/V1/Controllers/Summary/BasicController.php +++ b/app/Api/V1/Controllers/Summary/BasicController.php @@ -185,8 +185,8 @@ class BasicController extends Controller 'currency_decimal_places' => $currency->decimal_places, 'value_parsed' => app('amount')->formatAnything($currency, $sums[$currencyId] ?? '0', false), 'local_icon' => 'balance-scale', - 'sub_title' => app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false). - ' + '.app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false), + 'sub_title' => app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false) + .' + '.app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false), ]; $return[] = [ 'key' => sprintf('spent-in-%s', $currency->code), diff --git a/app/Api/V1/Requests/Data/DestroyRequest.php b/app/Api/V1/Requests/Data/DestroyRequest.php index 2f564567d9..082fb00adb 100644 --- a/app/Api/V1/Requests/Data/DestroyRequest.php +++ b/app/Api/V1/Requests/Data/DestroyRequest.php @@ -49,9 +49,9 @@ class DestroyRequest extends FormRequest */ public function rules(): array { - $valid = 'budgets,bills,piggy_banks,rules,recurring,categories,tags,object_groups'. - ',accounts,asset_accounts,expense_accounts,revenue_accounts,liabilities,transactions,withdrawals,deposits,transfers'. - ',not_assets_liabilities'; + $valid = 'budgets,bills,piggy_banks,rules,recurring,categories,tags,object_groups' + .',accounts,asset_accounts,expense_accounts,revenue_accounts,liabilities,transactions,withdrawals,deposits,transfers' + .',not_assets_liabilities'; return [ 'objects' => sprintf('required|max:255|min:1|string|in:%s', $valid), diff --git a/app/Factory/BillFactory.php b/app/Factory/BillFactory.php index 62d1e79805..24aa6a7e7e 100644 --- a/app/Factory/BillFactory.php +++ b/app/Factory/BillFactory.php @@ -48,8 +48,8 @@ class BillFactory { app('log')->debug(sprintf('Now in %s', __METHOD__), $data); $factory = app(TransactionCurrencyFactory::class); - $currency = $factory->find((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null)) ?? - app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); + $currency = $factory->find((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null)) + ?? app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); try { $skip = array_key_exists('skip', $data) ? $data['skip'] : 0; diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index f5d46ec514..67a2fc6add 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -141,8 +141,8 @@ class MassController extends Controller // reverse amounts foreach ($journals as $index => $journal) { $journals[$index]['amount'] = app('steam')->bcround(app('steam')->positive($journal['amount']), $journal['currency_decimal_places']); - $journals[$index]['foreign_amount'] = null === $journal['foreign_amount'] ? - null : app('steam')->positive($journal['foreign_amount']); + $journals[$index]['foreign_amount'] = null === $journal['foreign_amount'] + ? null : app('steam')->positive($journal['foreign_amount']); } $this->rememberPreviousUrl('transactions.mass-edit.url'); diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index d68f3054be..986bb2e5b8 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -33,11 +33,11 @@ class TrustProxies extends Middleware { // After... protected $headers - = Request::HEADER_X_FORWARDED_FOR | - Request::HEADER_X_FORWARDED_HOST | - Request::HEADER_X_FORWARDED_PORT | - Request::HEADER_X_FORWARDED_PROTO | - Request::HEADER_X_FORWARDED_AWS_ELB; + = Request::HEADER_X_FORWARDED_FOR + | Request::HEADER_X_FORWARDED_HOST + | Request::HEADER_X_FORWARDED_PORT + | Request::HEADER_X_FORWARDED_PROTO + | Request::HEADER_X_FORWARDED_AWS_ELB; /** * TrustProxies constructor. diff --git a/tests/unit/Support/Calendar/CalculatorTest.php b/tests/unit/Support/Calendar/CalculatorTest.php index 3830390c3b..4f127bf767 100644 --- a/tests/unit/Support/Calendar/CalculatorTest.php +++ b/tests/unit/Support/Calendar/CalculatorTest.php @@ -50,6 +50,32 @@ use Tests\unit\Support\Calendar\Periodicity\YearlyTest; */ final class CalculatorTest extends TestCase { + private static function convert(Periodicity $periodicity, array $intervals): array + { + $periodicityIntervals = []; + + /** @var IntervalProvider $interval */ + foreach ($intervals as $index => $interval) { + $calculator = CalculatorProvider::from($periodicity, $interval); + + $periodicityIntervals["#{$index} {$calculator->label}"] = [$calculator]; + } + + return $periodicityIntervals; + } + + /** + * @dataProvider provideAllPeriodicity + * + * @throws IntervalException + */ + public function testGivenADailyPeriodicityWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider): void + { + $calculator = new Calculator(); + $period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity); + self::assertSame($provider->expected()->toDateString(), $period->toDateString()); + } + public static function provideAllPeriodicity(): iterable { $intervals = []; @@ -68,37 +94,6 @@ final class CalculatorTest extends TestCase } } - private static function convert(Periodicity $periodicity, array $intervals): array - { - $periodicityIntervals = []; - - /** @var IntervalProvider $interval */ - foreach ($intervals as $index => $interval) { - $calculator = CalculatorProvider::from($periodicity, $interval); - - $periodicityIntervals["#{$index} {$calculator->label}"] = [$calculator]; - } - - return $periodicityIntervals; - } - - public static function provideSkippedIntervals(): iterable - { - return CalculatorProvider::providePeriodicityWithSkippedIntervals(); - } - - /** - * @dataProvider provideAllPeriodicity - * - * @throws IntervalException - */ - public function testGivenADailyPeriodicityWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider): void - { - $calculator = new Calculator(); - $period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity); - self::assertSame($provider->expected()->toDateString(), $period->toDateString()); - } - /** * @dataProvider provideSkippedIntervals * @@ -110,4 +105,9 @@ final class CalculatorTest extends TestCase $period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity, $provider->skip); self::assertSame($provider->expected()->toDateString(), $period->toDateString()); } + + public static function provideSkippedIntervals(): iterable + { + return CalculatorProvider::providePeriodicityWithSkippedIntervals(); + } } diff --git a/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php b/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php index 2153f1b9a0..7e4cc812bc 100644 --- a/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php +++ b/tests/unit/Support/Calendar/Periodicity/IntervalTestCase.php @@ -29,16 +29,6 @@ use Tests\integration\TestCase; abstract class IntervalTestCase extends TestCase { - public static function provider(): iterable - { - $intervals = static::provideIntervals(); - - /** @var IntervalProvider $interval */ - foreach ($intervals as $interval) { - yield "{$interval->label}" => [$interval]; - } - } - abstract public static function provideIntervals(): array; /** @@ -50,5 +40,15 @@ abstract class IntervalTestCase extends TestCase self::assertSame($provider->expected->toDateString(), $period->toDateString()); } + public static function provider(): iterable + { + $intervals = static::provideIntervals(); + + /** @var IntervalProvider $interval */ + foreach ($intervals as $interval) { + yield "{$interval->label}" => [$interval]; + } + } + abstract public static function factory(): Interval; } diff --git a/tests/unit/Support/NavigationAddPeriodTest.php b/tests/unit/Support/NavigationAddPeriodTest.php index cb0cedc1f0..018258d2bf 100644 --- a/tests/unit/Support/NavigationAddPeriodTest.php +++ b/tests/unit/Support/NavigationAddPeriodTest.php @@ -48,74 +48,13 @@ final class NavigationAddPeriodTest extends TestCase $this->navigation = new Navigation(); } - public static function provideFrequencies(): iterable + /** + * @dataProvider providePeriodsWithSkippingParam + */ + public function testGivenAFrequencyAndSkipIntervalWhenCalculateTheDateThenReturnsTheSkippedDateSuccessful(int $skip, string $frequency, Carbon $from, Carbon $expected): void { - return [ - Periodicity::Daily->name => ['periodicity' => Periodicity::Daily, 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], - Periodicity::Weekly->name => ['periodicity' => Periodicity::Weekly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], - Periodicity::Fortnightly->name => ['periodicity' => Periodicity::Fortnightly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(2)], - Periodicity::Monthly->name => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(1)], - '2019-01-01 to 2019-02-01' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2019-01-01'), 'expected' => Carbon::parse('2019-02-01')], - '2019-01-29 to 2019-02-28' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2019-01-29'), 'expected' => Carbon::parse('2019-02-28')], - '2019-01-30 to 2019-02-28' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2019-01-30'), 'expected' => Carbon::parse('2019-02-28')], - '2019-01-31 to 2019-02-28' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-02-28')], - '2023-03-31 to 2023-04-30' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2023-03-31'), 'expected' => Carbon::parse('2023-04-30')], - '2023-05-31 to 2023-06-30' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2023-05-31'), 'expected' => Carbon::parse('2023-06-30')], - '2023-08-31 to 2023-09-30' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2023-08-31'), 'expected' => Carbon::parse('2023-09-30')], - '2023-10-31 to 2023-11-30' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2023-10-31'), 'expected' => Carbon::parse('2023-11-30')], - Periodicity::Quarterly->name => ['periodicity' => Periodicity::Quarterly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], - '2019-01-29 to 2020-04-29' => ['periodicity' => Periodicity::Quarterly, 'from' => Carbon::parse('2019-01-29'), 'expected' => Carbon::parse('2019-04-29')], - '2019-01-30 to 2020-04-30' => ['periodicity' => Periodicity::Quarterly, 'from' => Carbon::parse('2019-01-30'), 'expected' => Carbon::parse('2019-04-30')], - '2019-01-31 to 2020-04-30' => ['periodicity' => Periodicity::Quarterly, 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-04-30')], - Periodicity::HalfYearly->name => ['periodicity' => Periodicity::HalfYearly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)], - '2019-01-31 to 2020-07-29' => ['periodicity' => Periodicity::HalfYearly, 'from' => Carbon::parse('2019-01-29'), 'expected' => Carbon::parse('2019-07-29')], - '2019-01-31 to 2020-07-30' => ['periodicity' => Periodicity::HalfYearly, 'from' => Carbon::parse('2019-01-30'), 'expected' => Carbon::parse('2019-07-30')], - '2019-01-31 to 2020-07-31' => ['periodicity' => Periodicity::HalfYearly, 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-07-31')], - Periodicity::Yearly->name => ['periodicity' => Periodicity::Yearly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], - '2020-02-29 to 2021-02-28' => ['periodicity' => Periodicity::Yearly, 'from' => Carbon::parse('2020-02-29'), 'expected' => Carbon::parse('2021-02-28')], - ]; - } - - public static function provideMonthPeriods(): iterable - { - return [ - '1M' => ['frequency' => '1M', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonthsNoOverflow(1)], - 'month' => ['frequency' => 'month', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonthsNoOverflow(1)], - 'monthly' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonthsNoOverflow(1)], - '2019-01-29 to 2019-02-28' => ['frequency' => 'monthly', 'from' => Carbon::parse('2019-01-29'), 'expected' => Carbon::parse('2019-02-28')], - '2019-01-30 to 2019-02-28' => ['frequency' => 'monthly', 'from' => Carbon::parse('2019-01-30'), 'expected' => Carbon::parse('2019-02-28')], - '2019-01-31 to 2019-02-28' => ['frequency' => 'monthly', 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-02-28')], - '2023-03-31 to 2023-04-30' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-03-31'), 'expected' => Carbon::parse('2023-04-30')], - '2023-05-31 to 2023-06-30' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-05-31'), 'expected' => Carbon::parse('2023-06-30')], - '2023-08-31 to 2023-09-30' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-08-31'), 'expected' => Carbon::parse('2023-09-30')], - '2023-10-31 to 2023-11-30' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-10-31'), 'expected' => Carbon::parse('2023-11-30')], - ]; - } - - public static function providePeriods(): iterable - { - return [ - '1D' => ['frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], - 'daily' => ['frequency' => 'daily', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], - '1W' => ['frequency' => '1W', 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], - 'weekly' => ['frequency' => 'weekly', 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], - 'week' => ['frequency' => 'week', 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], - '3M' => ['frequency' => '3M', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], - 'quarter' => ['frequency' => 'quarter', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], - 'quarterly' => ['frequency' => 'quarterly', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], - '6M' => ['frequency' => '6M', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)], - 'half-year' => ['frequency' => 'half-year', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)], - 'year' => ['frequency' => 'year', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], - 'yearly' => ['frequency' => 'yearly', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], - '1Y' => ['frequency' => '1Y', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], - 'last7' => ['frequency' => 'last7', 'from' => Carbon::now(), 'expected' => Carbon::now()->addDays(7)], - 'last30' => ['frequency' => 'last30', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(1)], - 'last90' => ['frequency' => 'last90', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], - 'last365' => ['frequency' => 'last365', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], - 'MTD' => ['frequency' => 'MTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(1)], - 'QTD' => ['frequency' => 'QTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], - 'YTD' => ['frequency' => 'YTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], - ]; + $period = $this->navigation->addPeriod($from, $frequency, $skip); + self::assertSame($expected->toDateString(), $period->toDateString()); } public static function providePeriodsWithSkippingParam(): iterable @@ -163,15 +102,6 @@ final class NavigationAddPeriodTest extends TestCase } } - /** - * @dataProvider providePeriodsWithSkippingParam - */ - public function testGivenAFrequencyAndSkipIntervalWhenCalculateTheDateThenReturnsTheSkippedDateSuccessful(int $skip, string $frequency, Carbon $from, Carbon $expected): void - { - $period = $this->navigation->addPeriod($from, $frequency, $skip); - self::assertSame($expected->toDateString(), $period->toDateString()); - } - /** * @dataProvider providePeriods */ @@ -181,6 +111,32 @@ final class NavigationAddPeriodTest extends TestCase self::assertSame($expected->toDateString(), $period->toDateString()); } + public static function providePeriods(): iterable + { + return [ + '1D' => ['frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], + 'daily' => ['frequency' => 'daily', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], + '1W' => ['frequency' => '1W', 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], + 'weekly' => ['frequency' => 'weekly', 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], + 'week' => ['frequency' => 'week', 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], + '3M' => ['frequency' => '3M', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], + 'quarter' => ['frequency' => 'quarter', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], + 'quarterly' => ['frequency' => 'quarterly', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], + '6M' => ['frequency' => '6M', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)], + 'half-year' => ['frequency' => 'half-year', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)], + 'year' => ['frequency' => 'year', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], + 'yearly' => ['frequency' => 'yearly', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], + '1Y' => ['frequency' => '1Y', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], + 'last7' => ['frequency' => 'last7', 'from' => Carbon::now(), 'expected' => Carbon::now()->addDays(7)], + 'last30' => ['frequency' => 'last30', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(1)], + 'last90' => ['frequency' => 'last90', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], + 'last365' => ['frequency' => 'last365', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], + 'MTD' => ['frequency' => 'MTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(1)], + 'QTD' => ['frequency' => 'QTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], + 'YTD' => ['frequency' => 'YTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], + ]; + } + /** * @dataProvider provideFrequencies */ @@ -190,6 +146,34 @@ final class NavigationAddPeriodTest extends TestCase self::assertSame($expected->toDateString(), $period->toDateString()); } + public static function provideFrequencies(): iterable + { + return [ + Periodicity::Daily->name => ['periodicity' => Periodicity::Daily, 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], + Periodicity::Weekly->name => ['periodicity' => Periodicity::Weekly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], + Periodicity::Fortnightly->name => ['periodicity' => Periodicity::Fortnightly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(2)], + Periodicity::Monthly->name => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(1)], + '2019-01-01 to 2019-02-01' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2019-01-01'), 'expected' => Carbon::parse('2019-02-01')], + '2019-01-29 to 2019-02-28' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2019-01-29'), 'expected' => Carbon::parse('2019-02-28')], + '2019-01-30 to 2019-02-28' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2019-01-30'), 'expected' => Carbon::parse('2019-02-28')], + '2019-01-31 to 2019-02-28' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-02-28')], + '2023-03-31 to 2023-04-30' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2023-03-31'), 'expected' => Carbon::parse('2023-04-30')], + '2023-05-31 to 2023-06-30' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2023-05-31'), 'expected' => Carbon::parse('2023-06-30')], + '2023-08-31 to 2023-09-30' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2023-08-31'), 'expected' => Carbon::parse('2023-09-30')], + '2023-10-31 to 2023-11-30' => ['periodicity' => Periodicity::Monthly, 'from' => Carbon::parse('2023-10-31'), 'expected' => Carbon::parse('2023-11-30')], + Periodicity::Quarterly->name => ['periodicity' => Periodicity::Quarterly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(3)], + '2019-01-29 to 2020-04-29' => ['periodicity' => Periodicity::Quarterly, 'from' => Carbon::parse('2019-01-29'), 'expected' => Carbon::parse('2019-04-29')], + '2019-01-30 to 2020-04-30' => ['periodicity' => Periodicity::Quarterly, 'from' => Carbon::parse('2019-01-30'), 'expected' => Carbon::parse('2019-04-30')], + '2019-01-31 to 2020-04-30' => ['periodicity' => Periodicity::Quarterly, 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-04-30')], + Periodicity::HalfYearly->name => ['periodicity' => Periodicity::HalfYearly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)], + '2019-01-31 to 2020-07-29' => ['periodicity' => Periodicity::HalfYearly, 'from' => Carbon::parse('2019-01-29'), 'expected' => Carbon::parse('2019-07-29')], + '2019-01-31 to 2020-07-30' => ['periodicity' => Periodicity::HalfYearly, 'from' => Carbon::parse('2019-01-30'), 'expected' => Carbon::parse('2019-07-30')], + '2019-01-31 to 2020-07-31' => ['periodicity' => Periodicity::HalfYearly, 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-07-31')], + Periodicity::Yearly->name => ['periodicity' => Periodicity::Yearly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(1)], + '2020-02-29 to 2021-02-28' => ['periodicity' => Periodicity::Yearly, 'from' => Carbon::parse('2020-02-29'), 'expected' => Carbon::parse('2021-02-28')], + ]; + } + /** * @dataProvider provideMonthPeriods */ @@ -198,4 +182,20 @@ final class NavigationAddPeriodTest extends TestCase $period = $this->navigation->addPeriod($from, $frequency, 0); self::assertSame($expected->toDateString(), $period->toDateString()); } + + public static function provideMonthPeriods(): iterable + { + return [ + '1M' => ['frequency' => '1M', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonthsNoOverflow(1)], + 'month' => ['frequency' => 'month', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonthsNoOverflow(1)], + 'monthly' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonthsNoOverflow(1)], + '2019-01-29 to 2019-02-28' => ['frequency' => 'monthly', 'from' => Carbon::parse('2019-01-29'), 'expected' => Carbon::parse('2019-02-28')], + '2019-01-30 to 2019-02-28' => ['frequency' => 'monthly', 'from' => Carbon::parse('2019-01-30'), 'expected' => Carbon::parse('2019-02-28')], + '2019-01-31 to 2019-02-28' => ['frequency' => 'monthly', 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-02-28')], + '2023-03-31 to 2023-04-30' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-03-31'), 'expected' => Carbon::parse('2023-04-30')], + '2023-05-31 to 2023-06-30' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-05-31'), 'expected' => Carbon::parse('2023-06-30')], + '2023-08-31 to 2023-09-30' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-08-31'), 'expected' => Carbon::parse('2023-09-30')], + '2023-10-31 to 2023-11-30' => ['frequency' => 'monthly', 'from' => Carbon::parse('2023-10-31'), 'expected' => Carbon::parse('2023-11-30')], + ]; + } } diff --git a/tests/unit/Support/NavigationEndOfPeriodTest.php b/tests/unit/Support/NavigationEndOfPeriodTest.php index f9a3b22e8e..278b2e7897 100644 --- a/tests/unit/Support/NavigationEndOfPeriodTest.php +++ b/tests/unit/Support/NavigationEndOfPeriodTest.php @@ -47,6 +47,15 @@ final class NavigationEndOfPeriodTest extends TestCase $this->navigation = new Navigation(); } + /** + * @dataProvider provideDates + */ + public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void + { + $period = clone $this->navigation->endOfPeriod($from, $frequency); + self::assertSame($expected->toDateString(), $period->toDateString()); + } + public static function provideDates(): iterable { return [ @@ -78,24 +87,6 @@ final class NavigationEndOfPeriodTest extends TestCase ]; } - public static function provideUnknownFrequencies(): iterable - { - return [ - '1day' => ['frequency' => '1day', 'from' => Carbon::now(), 'expected' => Carbon::now()], - 'unknown' => ['frequency' => 'unknown', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], - 'empty' => ['frequency' => '', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], - ]; - } - - /** - * @dataProvider provideDates - */ - public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void - { - $period = clone $this->navigation->endOfPeriod($from, $frequency); - self::assertSame($expected->toDateString(), $period->toDateString()); - } - /** * @dataProvider provideUnknownFrequencies */ @@ -109,4 +100,13 @@ final class NavigationEndOfPeriodTest extends TestCase Log::shouldHaveReceived('error', [$expectedMessage]); } + + public static function provideUnknownFrequencies(): iterable + { + return [ + '1day' => ['frequency' => '1day', 'from' => Carbon::now(), 'expected' => Carbon::now()], + 'unknown' => ['frequency' => 'unknown', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], + 'empty' => ['frequency' => '', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], + ]; + } } diff --git a/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php b/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php index fcb0165476..1a6007870d 100644 --- a/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php +++ b/tests/unit/Support/NavigationPreferredCarbonFormatByPeriodTest.php @@ -46,6 +46,15 @@ final class NavigationPreferredCarbonFormatByPeriodTest extends TestCase $this->navigation = new Navigation(); } + /** + * @dataProvider providePeriods + */ + public function testGivenAPeriodWhenCallPreferredCarbonFormatByPeriodThenReturnsExpectedFormat(string $period, string $expected): void + { + $formatPeriod = $this->navigation->preferredCarbonFormatByPeriod($period); + self::assertSame($expected, $formatPeriod); + } + public static function providePeriods(): iterable { return [ @@ -57,13 +66,4 @@ final class NavigationPreferredCarbonFormatByPeriodTest extends TestCase 'yearly' => ['period' => '1Y', 'expected' => 'Y'], ]; } - - /** - * @dataProvider providePeriods - */ - public function testGivenAPeriodWhenCallPreferredCarbonFormatByPeriodThenReturnsExpectedFormat(string $period, string $expected): void - { - $formatPeriod = $this->navigation->preferredCarbonFormatByPeriod($period); - self::assertSame($expected, $formatPeriod); - } } diff --git a/tests/unit/Support/NavigationPreferredCarbonFormatTest.php b/tests/unit/Support/NavigationPreferredCarbonFormatTest.php index 667cd77333..2cb4e0d074 100644 --- a/tests/unit/Support/NavigationPreferredCarbonFormatTest.php +++ b/tests/unit/Support/NavigationPreferredCarbonFormatTest.php @@ -47,6 +47,15 @@ final class NavigationPreferredCarbonFormatTest extends TestCase $this->navigation = new Navigation(); } + /** + * @dataProvider providePeriods + */ + public function testGivenStartAndEndDatesWhenCallPreferredCarbonFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void + { + $carbonFormat = $this->navigation->preferredCarbonFormat($start, $end); + self::assertSame($expected, $carbonFormat); + } + public static function providePeriods(): iterable { return [ @@ -64,13 +73,4 @@ final class NavigationPreferredCarbonFormatTest extends TestCase '2 years' => ['start' => Carbon::now(), 'end' => Carbon::now()->addYears(2), 'expected' => 'Y'], ]; } - - /** - * @dataProvider providePeriods - */ - public function testGivenStartAndEndDatesWhenCallPreferredCarbonFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void - { - $carbonFormat = $this->navigation->preferredCarbonFormat($start, $end); - self::assertSame($expected, $carbonFormat); - } } diff --git a/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php b/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php index d5f56ff678..f951a9a6a2 100644 --- a/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php +++ b/tests/unit/Support/NavigationPreferredEndOfPeriodTest.php @@ -47,6 +47,15 @@ final class NavigationPreferredEndOfPeriodTest extends TestCase $this->navigation = new Navigation(); } + /** + * @dataProvider providePeriods + */ + public function testGivenStartAndEndDatesWhenCallPreferredEndOfPeriodThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void + { + $formatPeriod = $this->navigation->preferredEndOfPeriod($start, $end); + self::assertSame($expected, $formatPeriod); + } + public static function providePeriods(): iterable { return [ @@ -64,13 +73,4 @@ final class NavigationPreferredEndOfPeriodTest extends TestCase '2 years' => ['start' => Carbon::now(), 'end' => Carbon::now()->addYears(2), 'expected' => 'endOfYear'], ]; } - - /** - * @dataProvider providePeriods - */ - public function testGivenStartAndEndDatesWhenCallPreferredEndOfPeriodThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void - { - $formatPeriod = $this->navigation->preferredEndOfPeriod($start, $end); - self::assertSame($expected, $formatPeriod); - } } diff --git a/tests/unit/Support/NavigationPreferredRangeFormatTest.php b/tests/unit/Support/NavigationPreferredRangeFormatTest.php index fede42ff47..21c2dea91d 100644 --- a/tests/unit/Support/NavigationPreferredRangeFormatTest.php +++ b/tests/unit/Support/NavigationPreferredRangeFormatTest.php @@ -47,6 +47,15 @@ final class NavigationPreferredRangeFormatTest extends TestCase $this->navigation = new Navigation(); } + /** + * @dataProvider providePeriods + */ + public function testGivenStartAndEndDatesWhenCallPreferredRangeFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void + { + $formatPeriod = $this->navigation->preferredRangeFormat($start, $end); + self::assertSame($expected, $formatPeriod); + } + public static function providePeriods(): iterable { return [ @@ -64,13 +73,4 @@ final class NavigationPreferredRangeFormatTest extends TestCase '2 years' => ['start' => Carbon::now(), 'end' => Carbon::now()->addYears(2), 'expected' => '1Y'], ]; } - - /** - * @dataProvider providePeriods - */ - public function testGivenStartAndEndDatesWhenCallPreferredRangeFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void - { - $formatPeriod = $this->navigation->preferredRangeFormat($start, $end); - self::assertSame($expected, $formatPeriod); - } } diff --git a/tests/unit/Support/NavigationPreferredSqlFormatTest.php b/tests/unit/Support/NavigationPreferredSqlFormatTest.php index 24a9c174fa..9dce8d5d33 100644 --- a/tests/unit/Support/NavigationPreferredSqlFormatTest.php +++ b/tests/unit/Support/NavigationPreferredSqlFormatTest.php @@ -47,6 +47,15 @@ final class NavigationPreferredSqlFormatTest extends TestCase $this->navigation = new Navigation(); } + /** + * @dataProvider provideDates + */ + public function testGivenStartAndEndDatesWhenCallPreferredSqlFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void + { + $formatPeriod = $this->navigation->preferredSqlFormat($start, $end); + self::assertSame($expected, $formatPeriod); + } + public static function provideDates(): iterable { return [ @@ -64,13 +73,4 @@ final class NavigationPreferredSqlFormatTest extends TestCase '2 years' => ['start' => Carbon::now(), 'end' => Carbon::now()->addYears(2), 'expected' => '%Y'], ]; } - - /** - * @dataProvider provideDates - */ - public function testGivenStartAndEndDatesWhenCallPreferredSqlFormatThenReturnsTheExpectedFormatSuccessful(Carbon $start, Carbon $end, string $expected): void - { - $formatPeriod = $this->navigation->preferredSqlFormat($start, $end); - self::assertSame($expected, $formatPeriod); - } } diff --git a/tests/unit/Support/NavigationStartOfPeriodTest.php b/tests/unit/Support/NavigationStartOfPeriodTest.php index 315cb1695c..fe9f5117b0 100644 --- a/tests/unit/Support/NavigationStartOfPeriodTest.php +++ b/tests/unit/Support/NavigationStartOfPeriodTest.php @@ -48,6 +48,15 @@ final class NavigationStartOfPeriodTest extends TestCase $this->navigation = new Navigation(); } + /** + * @dataProvider provideDates + */ + public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void + { + $period = $this->navigation->startOfPeriod($from, $frequency); + self::assertSame($expected->toDateString(), $period->toDateString()); + } + public static function provideDates(): iterable { return [ @@ -78,24 +87,6 @@ final class NavigationStartOfPeriodTest extends TestCase ]; } - public static function provideUnknownFrequencies(): iterable - { - return [ - '1day' => ['frequency' => '1day', 'from' => Carbon::now(), 'expected' => Carbon::now()], - 'unknown' => ['frequency' => 'unknown', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], - 'empty' => ['frequency' => '', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], - ]; - } - - /** - * @dataProvider provideDates - */ - public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected): void - { - $period = $this->navigation->startOfPeriod($from, $frequency); - self::assertSame($expected->toDateString(), $period->toDateString()); - } - /** * @dataProvider provideUnknownFrequencies */ @@ -111,4 +102,13 @@ final class NavigationStartOfPeriodTest extends TestCase $period = $this->navigation->startOfPeriod($from, $frequency); self::assertSame($expected->toDateString(), $period->toDateString()); } + + public static function provideUnknownFrequencies(): iterable + { + return [ + '1day' => ['frequency' => '1day', 'from' => Carbon::now(), 'expected' => Carbon::now()], + 'unknown' => ['frequency' => 'unknown', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], + 'empty' => ['frequency' => '', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], + ]; + } } diff --git a/tests/unit/Support/Search/QueryParser/AbstractQueryParserInterfaceParseQueryTester.php b/tests/unit/Support/Search/QueryParser/AbstractQueryParserInterfaceParseQueryTester.php index c2abc6aeb2..0081ac0b19 100644 --- a/tests/unit/Support/Search/QueryParser/AbstractQueryParserInterfaceParseQueryTester.php +++ b/tests/unit/Support/Search/QueryParser/AbstractQueryParserInterfaceParseQueryTester.php @@ -15,6 +15,20 @@ 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 + */ + public function testQueryParsing(string $query, Node $expected): void + { + $actual = $this->createParser()->parse($query); + + self::assertObjectEquals($expected, $actual); + + } + public static function queryDataProvider(): iterable { return [ @@ -181,18 +195,4 @@ abstract class AbstractQueryParserInterfaceParseQueryTester extends TestCase ], ]; } - - /** - * @dataProvider queryDataProvider - * - * @param string $query The query string to parse - * @param Node $expected The expected parse result - */ - public function testQueryParsing(string $query, Node $expected): void - { - $actual = $this->createParser()->parse($query); - - self::assertObjectEquals($expected, $actual); - - } }