Skip to content

Commit d6af929

Browse files
authored
Convert to Pest (#131)
1 parent 2c943b3 commit d6af929

15 files changed

Lines changed: 1805 additions & 2076 deletions

.github/workflows/test.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010
strategy:
1111
matrix:
12-
os: [ubuntu-latest]
13-
php: [8.2, 8.3, 8.4]
12+
php: [8.3, 8.4]
1413
laravel: [11.*, 12.*]
14+
stability: [prefer-lowest, prefer-stable]
15+
os: [ubuntu-latest]
1516
dependency-version: [prefer-stable]
16-
exclude:
17-
- php: 8.1
18-
laravel: 11.*
19-
- php: 8.1
20-
laravel: 12.*
21-
- php: 8.4
22-
laravel: 10.*
2317
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ubuntu-latest
2418
steps:
2519
- name: Checkout code
@@ -39,8 +33,7 @@ jobs:
3933
coverage: none
4034

4135
- name: Install dependencies
42-
run: |
43-
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
36+
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
4437

4538
- name: Execute tests
46-
run: vendor/bin/phpunit -c phpunit.xml
39+
run: vendor/bin/pest

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
}
1212
],
1313
"require": {
14+
"php": "^8.3",
1415
"rlanvin/php-rrule": "^2.3.1",
1516
"spatie/calendar-links": "^1.0",
1617
"spatie/icalendar-generator": "^2.3.3",
1718
"statamic/cms": "6.0.0-alpha.4"
1819
},
1920
"require-dev": {
20-
"mockery/mockery": "^1.3.1",
21-
"nunomaduro/collision": "^8.0",
22-
"orchestra/testbench": "^9.0",
23-
"phpunit/phpunit": "^11.0",
21+
"orchestra/testbench": "^9.2 || ^10.0",
22+
"pestphp/pest": "^4.0",
2423
"spatie/laravel-ray": "^1.35",
2524
"spatie/test-time": "^1.2"
2625
},
2726
"autoload": {
2827
"psr-4": {
29-
"TransformStudios\\Events\\": "src"
28+
"TransformStudios\\Events\\": "src",
29+
"TransformStudios\\Events\\Tests\\": "tests"
3030
},
3131
"files": [
3232
"src/helpers.php"
@@ -39,6 +39,7 @@
3939
},
4040
"config": {
4141
"allow-plugins": {
42+
"pestphp/pest-plugin": true,
4243
"pixelfear/composer-dist-plugin": true
4344
},
4445
"optimize-autoloader": true,

tests/Feature/EventsOffsetTest.php

Lines changed: 92 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,97 @@
11
<?php
22

3-
namespace TransformStudios\Events\Tests\Feature;
4-
53
use Illuminate\Support\Carbon;
6-
use PHPUnit\Framework\Attributes\Test;
74
use Statamic\Facades\Entry;
85
use TransformStudios\Events\Tags\Events;
9-
use TransformStudios\Events\Tests\TestCase;
10-
11-
class EventsOffsetTest extends TestCase
12-
{
13-
private Events $tag;
14-
15-
protected function setUp(): void
16-
{
17-
parent::setUp();
18-
19-
Entry::make()
20-
->collection('events')
21-
->slug('recurring-event')
22-
->id('recurring-event')
23-
->data([
24-
'title' => 'Recurring Event',
25-
'start_date' => Carbon::now()->toDateString(),
26-
'start_time' => '11:00',
27-
'end_time' => '12:00',
28-
'recurrence' => 'weekly',
29-
'categories' => ['one'],
30-
])->save();
31-
32-
$this->tag = app(Events::class);
33-
}
34-
35-
#[Test]
36-
public function can_offset_upcoming_occurrences()
37-
{
38-
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
39-
40-
$this->tag
41-
->setContext([])
42-
->setParameters([
43-
'collection' => 'events',
44-
'limit' => 5,
45-
'offset' => 2,
46-
]);
47-
48-
$occurrences = $this->tag->upcoming();
49-
50-
$this->assertCount(3, $occurrences);
51-
}
52-
53-
#[Test]
54-
public function can_offset_between_occurrences()
55-
{
56-
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
57-
58-
$this->tag->setContext([])
59-
->setParameters([
60-
'collection' => 'events',
61-
'from' => Carbon::now()->toDateString(),
62-
'to' => Carbon::now()->addWeek(3),
63-
'offset' => 2,
64-
]);
65-
66-
$occurrences = $this->tag->between();
67-
68-
$this->assertCount(2, $occurrences);
69-
}
70-
71-
#[Test]
72-
public function can_offset_today_occurrences()
73-
{
74-
Carbon::setTestNow(now()->setTimeFromTimeString('12:01'));
75-
76-
Entry::make()
77-
->collection('events')
78-
->slug('single-event')
79-
->data([
80-
'title' => 'Single Event',
81-
'start_date' => Carbon::now()->toDateString(),
82-
'start_time' => '13:00',
83-
'end_time' => '15:00',
84-
])->save();
85-
86-
$this->tag->setContext([])
87-
->setParameters([
88-
'collection' => 'events',
89-
'offset' => 1,
90-
]);
91-
92-
$this->assertCount(1, $this->tag->today());
93-
94-
$this->tag->setContext([])
95-
->setParameters([
96-
'collection' => 'events',
97-
'ignore_finished' => true,
98-
'offset' => 1,
99-
]);
100-
101-
$this->assertCount(0, $this->tag->today());
102-
}
103-
104-
#[Test]
105-
public function can_offset_single_day_occurrences()
106-
{
107-
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
108-
109-
$this->tag->setContext([])
110-
->setParameters([
111-
'collection' => 'events',
112-
'offset' => 1,
113-
]);
114-
115-
$this->assertCount(0, $this->tag->today());
116-
}
117-
}
6+
7+
beforeEach(function () {
8+
Entry::make()
9+
->collection('events')
10+
->slug('recurring-event')
11+
->id('recurring-event')
12+
->data([
13+
'title' => 'Recurring Event',
14+
'start_date' => Carbon::now()->toDateString(),
15+
'start_time' => '11:00',
16+
'end_time' => '12:00',
17+
'recurrence' => 'weekly',
18+
'categories' => ['one'],
19+
])->save();
20+
21+
$this->tag = app(Events::class);
22+
});
23+
24+
test('can offset upcoming occurrences', function () {
25+
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
26+
27+
$this->tag
28+
->setContext([])
29+
->setParameters([
30+
'collection' => 'events',
31+
'limit' => 5,
32+
'offset' => 2,
33+
]);
34+
35+
$occurrences = $this->tag->upcoming();
36+
37+
expect($occurrences)->toHaveCount(3);
38+
});
39+
40+
test('can offset between occurrences', function () {
41+
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
42+
43+
$this->tag->setContext([])
44+
->setParameters([
45+
'collection' => 'events',
46+
'from' => Carbon::now()->toDateString(),
47+
'to' => Carbon::now()->addWeek(3),
48+
'offset' => 2,
49+
]);
50+
51+
$occurrences = $this->tag->between();
52+
53+
expect($occurrences)->toHaveCount(2);
54+
});
55+
56+
test('can offset today occurrences', function () {
57+
Carbon::setTestNow(now()->setTimeFromTimeString('12:01'));
58+
59+
Entry::make()
60+
->collection('events')
61+
->slug('single-event')
62+
->data([
63+
'title' => 'Single Event',
64+
'start_date' => Carbon::now()->toDateString(),
65+
'start_time' => '13:00',
66+
'end_time' => '15:00',
67+
])->save();
68+
69+
$this->tag->setContext([])
70+
->setParameters([
71+
'collection' => 'events',
72+
'offset' => 1,
73+
]);
74+
75+
expect($this->tag->today())->toHaveCount(1);
76+
77+
$this->tag->setContext([])
78+
->setParameters([
79+
'collection' => 'events',
80+
'ignore_finished' => true,
81+
'offset' => 1,
82+
]);
83+
84+
expect($this->tag->today())->toHaveCount(0);
85+
});
86+
87+
test('can offset single day occurrences', function () {
88+
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
89+
90+
$this->tag->setContext([])
91+
->setParameters([
92+
'collection' => 'events',
93+
'offset' => 1,
94+
]);
95+
96+
expect($this->tag->today())->toHaveCount(0);
97+
});

0 commit comments

Comments
 (0)