fix: notifications

This commit is contained in:
James Cole
2023-07-17 20:33:26 +02:00
parent 2bb4cc7954
commit 788dae1477
34 changed files with 192 additions and 99 deletions

View File

@@ -37,14 +37,16 @@ readonly class CalculatorProvider
public Periodicity $periodicity;
public int $skip;
private function __construct(IntervalProvider $intervalProvider, Periodicity $periodicity, int $skip = 0) {
private function __construct(IntervalProvider $intervalProvider, Periodicity $periodicity, int $skip = 0)
{
$this->skip = $skip;
$this->intervalProvider = $intervalProvider;
$this->periodicity = $periodicity;
$this->label = "{$periodicity->name} {$intervalProvider->label}";
}
public static function providePeriodicityWithSkippedIntervals(): Generator {
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),
@@ -117,15 +119,18 @@ 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): CalculatorProvider
{
return new self($interval, $periodicity, $skip);
}
public function epoch(): Carbon {
public function epoch(): Carbon
{
return $this->intervalProvider->epoch;
}
public function expected(): Carbon {
public function expected(): Carbon
{
return $this->intervalProvider->expected;
}
}

View File

@@ -48,7 +48,8 @@ use Tests\unit\Support\Calendar\Periodicity\YearlyTest;
*/
class CalculatorTest extends TestCase
{
public static function provideAllPeriodicity(): Generator {
public static function provideAllPeriodicity(): Generator
{
$intervals = [];
$intervals = array_merge($intervals, self::convert(Periodicity::Daily, DailyTest::provideIntervals()));
$intervals = array_merge($intervals, self::convert(Periodicity::Weekly, WeeklyTest::provideIntervals()));
@@ -65,7 +66,8 @@ class CalculatorTest extends TestCase
}
}
private static function convert(Periodicity $periodicity, array $intervals): array {
private static function convert(Periodicity $periodicity, array $intervals): array
{
$periodicityIntervals = [];
/** @var IntervalProvider $interval */
foreach ($intervals as $index => $interval) {
@@ -76,7 +78,8 @@ class CalculatorTest extends TestCase
return $periodicityIntervals;
}
public static function provideSkippedIntervals(): Generator {
public static function provideSkippedIntervals(): Generator
{
return CalculatorProvider::providePeriodicityWithSkippedIntervals();
}
@@ -84,7 +87,8 @@ class CalculatorTest extends TestCase
* @dataProvider provideAllPeriodicity
* @throws IntervalException
*/
public function testGivenADailyPeriodicityWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider) {
public function testGivenADailyPeriodicityWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider)
{
$calculator = new Calculator();
$period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity);
$this->assertEquals($provider->expected()->toDateString(), $period->toDateString());
@@ -94,7 +98,8 @@ class CalculatorTest extends TestCase
* @dataProvider provideSkippedIntervals
* @throws IntervalException
*/
public function testGivenAnEpochWithSkipIntervalNumberWhenCallTheNextDateBySkippedIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider) {
public function testGivenAnEpochWithSkipIntervalNumberWhenCallTheNextDateBySkippedIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider)
{
$calculator = new Calculator();
$period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity, $provider->skip);
$this->assertEquals($provider->expected()->toDateString(), $period->toDateString());

View File

@@ -37,11 +37,13 @@ use FireflyIII\Support\Calendar\Periodicity\Interval;
*/
class MonthlyTest extends IntervalTestCase
{
public static function factory(): Interval {
public static function factory(): Interval
{
return new Periodicity\Monthly();
}
public static function provideIntervals(): array {
public static function provideIntervals(): array
{
return [
new IntervalProvider(Carbon::now(), Carbon::now()->addMonth(1)),
new IntervalProvider(Carbon::parse('2019-01-01'), Carbon::parse('2019-02-01')),

View File

@@ -37,11 +37,13 @@ use FireflyIII\Support\Calendar\Periodicity\Interval;
*/
class QuarterlyTest extends IntervalTestCase
{
public static function factory(): Interval {
public static function factory(): Interval
{
return new Periodicity\Quarterly();
}
public static function provideIntervals(): array {
public static function provideIntervals(): array
{
return [
new IntervalProvider(Carbon::now(), Carbon::now()->addMonths(3)),
new IntervalProvider(Carbon::parse('2019-01-29'), Carbon::parse('2019-04-29')),

View File

@@ -37,11 +37,13 @@ use FireflyIII\Support\Calendar\Periodicity\Interval;
*/
class WeeklyTest extends IntervalTestCase
{
public static function factory(): Interval {
public static function factory(): Interval
{
return new Periodicity\Weekly();
}
public static function provideIntervals(): array {
public static function provideIntervals(): array
{
return [
new IntervalProvider(Carbon::now(), Carbon::now()->addWeek()),
new IntervalProvider(Carbon::parse('2023-01-31'), Carbon::parse('2023-02-07')),

View File

@@ -37,11 +37,13 @@ use FireflyIII\Support\Calendar\Periodicity\Interval;
*/
class YearlyTest extends IntervalTestCase
{
public static function factory(): Interval {
public static function factory(): Interval
{
return new Periodicity\Yearly();
}
public static function provideIntervals(): array {
public static function provideIntervals(): array
{
return [
new IntervalProvider(Carbon::now(), Carbon::now()->addYears(1)),
new IntervalProvider(Carbon::parse('2019-01-29'), Carbon::parse('2020-01-29')),

View File

@@ -39,12 +39,14 @@ class NavigationAddPeriodTest extends TestCase
{
private Navigation $navigation;
public function __construct(string $name) {
public function __construct(string $name)
{
parent::__construct($name);
$this->navigation = new Navigation();
}
public static function provideFrequencies(): array {
public static function provideFrequencies(): array
{
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)],
@@ -71,7 +73,8 @@ class NavigationAddPeriodTest extends TestCase
];
}
public static function provideMonthPeriods(): array {
public static function provideMonthPeriods(): array
{
return [
'1M' => ['frequency' => '1M', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonths(1)],
'month' => ['frequency' => 'month', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonths(1)],
@@ -86,7 +89,8 @@ class NavigationAddPeriodTest extends TestCase
];
}
public static function providePeriods(): array {
public static function providePeriods(): array
{
return [
'1D' => ['frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()],
'daily' => ['frequency' => 'daily', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()],
@@ -111,7 +115,8 @@ class NavigationAddPeriodTest extends TestCase
];
}
public static function providePeriodsWithSkippingParam(): Generator {
public static function providePeriodsWithSkippingParam(): Generator
{
$intervals = [
'2019-01-31 to 2019-02-11' => ['skip' => 10, 'frequency' => 'daily', 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-02-11')],
'1D' => ['skip' => 1, 'frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::now()->addDays(2)],
@@ -155,7 +160,8 @@ class NavigationAddPeriodTest extends TestCase
/**
* @dataProvider providePeriodsWithSkippingParam
*/
public function testGivenAFrequencyAndSkipIntervalWhenCalculateTheDateThenReturnsTheSkippedDateSuccessful(int $skip, string $frequency, Carbon $from, Carbon $expected) {
public function testGivenAFrequencyAndSkipIntervalWhenCalculateTheDateThenReturnsTheSkippedDateSuccessful(int $skip, string $frequency, Carbon $from, Carbon $expected)
{
$period = $this->navigation->addPeriod($from, $frequency, $skip);
$this->assertEquals($expected->toDateString(), $period->toDateString());
}
@@ -163,7 +169,8 @@ class NavigationAddPeriodTest extends TestCase
/**
* @dataProvider providePeriods
*/
public function testGivenAFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) {
public function testGivenAFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected)
{
$period = $this->navigation->addPeriod($from, $frequency, 0);
$this->assertEquals($expected->toDateString(), $period->toDateString());
}
@@ -171,7 +178,8 @@ class NavigationAddPeriodTest extends TestCase
/**
* @dataProvider provideFrequencies
*/
public function testGivenAIntervalWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(Periodicity $periodicity, Carbon $from, Carbon $expected) {
public function testGivenAIntervalWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(Periodicity $periodicity, Carbon $from, Carbon $expected)
{
$period = $this->navigation->nextDateByInterval($from, $periodicity);
$this->assertEquals($expected->toDateString(), $period->toDateString());
}
@@ -179,7 +187,8 @@ class NavigationAddPeriodTest extends TestCase
/**
* @dataProvider provideMonthPeriods
*/
public function testGivenAMonthFrequencyWhenCalculateTheDateThenReturnsTheLastDayOfMonthSuccessful(string $frequency, Carbon $from, Carbon $expected) {
public function testGivenAMonthFrequencyWhenCalculateTheDateThenReturnsTheLastDayOfMonthSuccessful(string $frequency, Carbon $from, Carbon $expected)
{
$period = $this->navigation->addPeriod($from, $frequency, 0);
$this->assertEquals($expected->toDateString(), $period->toDateString());
}

View File

@@ -38,12 +38,14 @@ class NavigationStartOfPeriodTest extends TestCase
{
private Navigation $navigation;
public function __construct(string $name) {
public function __construct(string $name)
{
parent::__construct($name);
$this->navigation = new Navigation();
}
public static function provideDates(): array {
public static function provideDates(): array
{
return [
'custom' => ['frequency' => 'custom', 'from' => Carbon::now(), 'expected' => Carbon::now()],
'1D' => ['frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()],
@@ -72,7 +74,8 @@ class NavigationStartOfPeriodTest extends TestCase
];
}
public static function provideUnknownFrequencies(): array {
public static function provideUnknownFrequencies(): array
{
return [
'1day' => ['frequency' => '1day', 'from' => Carbon::now(), 'expected' => Carbon::now()],
'unknown' => ['frequency' => 'unknown', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()],
@@ -83,7 +86,8 @@ class NavigationStartOfPeriodTest extends TestCase
/**
* @dataProvider provideDates
*/
public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) {
public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected)
{
$period = $this->navigation->startOfPeriod($from, $frequency);
$this->assertEquals($expected->toDateString(), $period->toDateString());
}
@@ -91,7 +95,8 @@ class NavigationStartOfPeriodTest extends TestCase
/**
* @dataProvider provideUnknownFrequencies
*/
public function testGivenADateAndUnknownFrequencyWhenCalculateTheDateThenReturnsTheSameDateSuccessful(string $frequency, Carbon $from, Carbon $expected) {
public function testGivenADateAndUnknownFrequencyWhenCalculateTheDateThenReturnsTheSameDateSuccessful(string $frequency, Carbon $from, Carbon $expected)
{
Log::shouldReceive('error')
->with(sprintf('Cannot do startOfPeriod for $repeat_freq "%s"', $frequency))
->andReturnNull();