Skip to content

Commit 65fb918

Browse files
freekmurzeclaude
andauthored
Convert test suite from PHPUnit to Pest (#2912)
* Convert test suite from PHPUnit to Pest - Replace phpunit/phpunit with pestphp/pest and pestphp/pest-plugin-laravel - Convert all 26 test files from class-based PHPUnit to Pest functional syntax - Use Pest expectations (expect()) instead of PHPUnit assertions - Create TestCase subclasses for files needing pre-setUp properties - Add tests/Pest.php and tests/ContentPolicy.php - Update GitHub Actions workflows to use vendor/bin/pest - 599 tests, 1463 assertions all passing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix CI: add pest-plugin to allow-plugins, drop PHP 8.0/8.1 and Laravel 8/9 from matrix Pest v3 requires PHP ^8.2 and pest-plugin-laravel requires Laravel ^10+, so these older combinations cannot be tested with Pest. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Reorganize test suite into subdirectories and simplify TestCase by replacing subclasses with setup methods * Fix styling --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: freekmurze <483853+freekmurze@users.noreply.github.com>
1 parent e2cad43 commit 65fb918

89 files changed

Lines changed: 8449 additions & 6903 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run-tests.yml

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
php: [8.5, 8.4, 8.3, 8.2, 8.1, 8.0]
13-
laravel: ["^12.0", "^11.0", "^10.0", "^9.0", "^8.12"]
12+
php: [8.5, 8.4, 8.3, 8.2]
13+
laravel: ["^12.0", "^11.0", "^10.0"]
1414
dependency-version: [prefer-lowest, prefer-stable]
1515
include:
1616
- laravel: "^12.0"
@@ -19,33 +19,11 @@ jobs:
1919
testbench: 9.*
2020
- laravel: "^10.0"
2121
testbench: 8.*
22-
- laravel: "^9.0"
23-
testbench: 7.*
24-
- laravel: "^8.12"
25-
testbench: "^6.23"
2622
exclude:
27-
- laravel: "^12.0"
28-
php: 8.1
29-
- laravel: "^12.0"
30-
php: 8.0
3123
- laravel: "^11.0"
3224
dependency-version: prefer-lowest
33-
- laravel: "^11.0"
34-
php: 8.1
35-
- laravel: "^11.0"
36-
php: 8.0
37-
- laravel: "^10.0"
38-
php: 8.0
3925
- laravel: "^10.0"
4026
php: 8.5
41-
- laravel: "^9.0"
42-
php: 8.5
43-
- laravel: "^8.12"
44-
php: 8.3
45-
- laravel: "^8.12"
46-
php: 8.4
47-
- laravel: "^8.12"
48-
php: 8.5
4927

5028
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
5129

@@ -60,14 +38,10 @@ jobs:
6038
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
6139
coverage: none
6240

63-
- name: Install dependencies (remove passport)
64-
run: composer remove --dev laravel/passport --no-interaction --no-update
65-
if: matrix.laravel == '^8.12'
66-
6741
- name: Install dependencies
6842
run: |
6943
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "symfony/console:>=4.3.4" "mockery/mockery:^1.3.2" "nesbot/carbon:>=2.72.6" --no-interaction --no-update
7044
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
7145
7246
- name: Execute tests
73-
run: vendor/bin/phpunit
47+
run: vendor/bin/pest

.github/workflows/test-cache-drivers.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,31 @@ jobs:
3737
3838
- name: Execute tests - memcached cache driver
3939
run: |
40-
vendor/bin/phpunit
40+
vendor/bin/pest
4141
env:
4242
CACHE_DRIVER: memcached
4343

4444
- name: Execute tests - redis cache driver
4545
run: |
46-
vendor/bin/phpunit
46+
vendor/bin/pest
4747
env:
4848
CACHE_DRIVER: redis
4949
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
5050

5151
- name: Execute tests - database cache driver
5252
run: |
53-
vendor/bin/phpunit
53+
vendor/bin/pest
5454
env:
5555
CACHE_DRIVER: database
5656

5757
- name: Execute tests - file cache driver
5858
run: |
59-
vendor/bin/phpunit
59+
vendor/bin/pest
6060
env:
6161
CACHE_DRIVER: file
6262

6363
- name: Execute tests - array cache driver
6464
run: |
65-
vendor/bin/phpunit
65+
vendor/bin/pest
6666
env:
6767
CACHE_DRIVER: array

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"laravel/passport": "^11.0|^12.0",
3333
"laravel/pint": "^1.0",
3434
"orchestra/testbench": "^6.23|^7.0|^8.0|^9.0|^10.0",
35-
"phpunit/phpunit": "^9.4|^10.1|^11.5"
35+
"pestphp/pest": "^2.0|^3.0",
36+
"pestphp/pest-plugin-laravel": "^2.0|^3.0"
3637
},
3738
"minimum-stability": "dev",
3839
"prefer-stable": true,
@@ -50,7 +51,10 @@
5051
}
5152
},
5253
"config": {
53-
"sort-packages": true
54+
"sort-packages": true,
55+
"allow-plugins": {
56+
"pestphp/pest-plugin": true
57+
}
5458
},
5559
"extra": {
5660
"branch-alias": {
@@ -64,7 +68,7 @@
6468
}
6569
},
6670
"scripts": {
67-
"test": "phpunit",
71+
"test": "pest",
6872
"format": "pint",
6973
"analyse": "echo 'Checking dependencies...' && composer require --dev larastan/larastan && phpstan analyse"
7074
}

src/helpers.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22

3+
use Spatie\Permission\Guard;
4+
use Spatie\Permission\PermissionRegistrar;
5+
36
if (! function_exists('getModelForGuard')) {
47
function getModelForGuard(string $guard): ?string
58
{
6-
return Spatie\Permission\Guard::getModelForGuard($guard);
9+
return Guard::getModelForGuard($guard);
710
}
811

912
}
@@ -14,7 +17,7 @@ function getModelForGuard(string $guard): ?string
1417
*/
1518
function setPermissionsTeamId($id)
1619
{
17-
app(\Spatie\Permission\PermissionRegistrar::class)->setPermissionsTeamId($id);
20+
app(PermissionRegistrar::class)->setPermissionsTeamId($id);
1821
}
1922
}
2023

@@ -24,6 +27,6 @@ function setPermissionsTeamId($id)
2427
*/
2528
function getPermissionsTeamId()
2629
{
27-
return app(\Spatie\Permission\PermissionRegistrar::class)->getPermissionsTeamId();
30+
return app(PermissionRegistrar::class)->getPermissionsTeamId();
2831
}
2932
}

0 commit comments

Comments
 (0)