Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
php: [8.2, 8.3, 8.4]
php: [8.3, 8.4]
laravel: [11.*, 12.*]
stability: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]
dependency-version: [prefer-stable]
exclude:
- php: 8.1
laravel: 11.*
- php: 8.1
laravel: 12.*
- php: 8.4
laravel: 10.*
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -39,8 +33,7 @@ jobs:
coverage: none

- name: Install dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Execute tests
run: vendor/bin/phpunit -c phpunit.xml
run: vendor/bin/pest
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
}
],
"require": {
"php": "^8.3",
"rlanvin/php-rrule": "^2.3.1",
"spatie/calendar-links": "^1.0",
"spatie/icalendar-generator": "^2.3.3",
"statamic/cms": "6.0.0-alpha.4"
},
"require-dev": {
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^8.0",
"orchestra/testbench": "^9.0",
"phpunit/phpunit": "^11.0",
"orchestra/testbench": "^9.2 || ^10.0",
"pestphp/pest": "^4.0",
"spatie/laravel-ray": "^1.35",
"spatie/test-time": "^1.2"
},
"autoload": {
"psr-4": {
"TransformStudios\\Events\\": "src"
"TransformStudios\\Events\\": "src",
"TransformStudios\\Events\\Tests\\": "tests"
},
"files": [
"src/helpers.php"
Expand All @@ -39,6 +39,7 @@
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true,
"pixelfear/composer-dist-plugin": true
},
"optimize-autoloader": true,
Expand Down
204 changes: 92 additions & 112 deletions tests/Feature/EventsOffsetTest.php
Original file line number Diff line number Diff line change
@@ -1,117 +1,97 @@
<?php

namespace TransformStudios\Events\Tests\Feature;

use Illuminate\Support\Carbon;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Entry;
use TransformStudios\Events\Tags\Events;
use TransformStudios\Events\Tests\TestCase;

class EventsOffsetTest extends TestCase
{
private Events $tag;

protected function setUp(): void
{
parent::setUp();

Entry::make()
->collection('events')
->slug('recurring-event')
->id('recurring-event')
->data([
'title' => 'Recurring Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'categories' => ['one'],
])->save();

$this->tag = app(Events::class);
}

#[Test]
public function can_offset_upcoming_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag
->setContext([])
->setParameters([
'collection' => 'events',
'limit' => 5,
'offset' => 2,
]);

$occurrences = $this->tag->upcoming();

$this->assertCount(3, $occurrences);
}

#[Test]
public function can_offset_between_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'from' => Carbon::now()->toDateString(),
'to' => Carbon::now()->addWeek(3),
'offset' => 2,
]);

$occurrences = $this->tag->between();

$this->assertCount(2, $occurrences);
}

#[Test]
public function can_offset_today_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('12:01'));

Entry::make()
->collection('events')
->slug('single-event')
->data([
'title' => 'Single Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '13:00',
'end_time' => '15:00',
])->save();

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);

$this->assertCount(1, $this->tag->today());

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'ignore_finished' => true,
'offset' => 1,
]);

$this->assertCount(0, $this->tag->today());
}

#[Test]
public function can_offset_single_day_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);

$this->assertCount(0, $this->tag->today());
}
}

beforeEach(function () {
Entry::make()
->collection('events')
->slug('recurring-event')
->id('recurring-event')
->data([
'title' => 'Recurring Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'categories' => ['one'],
])->save();

$this->tag = app(Events::class);
});

test('can offset upcoming occurrences', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag
->setContext([])
->setParameters([
'collection' => 'events',
'limit' => 5,
'offset' => 2,
]);

$occurrences = $this->tag->upcoming();

expect($occurrences)->toHaveCount(3);
});

test('can offset between occurrences', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'from' => Carbon::now()->toDateString(),
'to' => Carbon::now()->addWeek(3),
'offset' => 2,
]);

$occurrences = $this->tag->between();

expect($occurrences)->toHaveCount(2);
});

test('can offset today occurrences', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('12:01'));

Entry::make()
->collection('events')
->slug('single-event')
->data([
'title' => 'Single Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '13:00',
'end_time' => '15:00',
])->save();

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);

expect($this->tag->today())->toHaveCount(1);

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'ignore_finished' => true,
'offset' => 1,
]);

expect($this->tag->today())->toHaveCount(0);
});

test('can offset single day occurrences', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));

$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);

expect($this->tag->today())->toHaveCount(0);
});
Loading