Skip to content

Commit 09f46e0

Browse files
feat: upgrade to Pest v4 and implement testing improvements (#23)
* feat: upgrade to Pest v4 and implement testing improvements * ci: upgrade php version * ci: fix test command * ci: add playwright * ci: re-add parallel flag * ci: install dependencies fixes * ci: fix attempt * ci: fix attempt #2 * ci: remove custom virtual display * ci: cache playwright * ci: improve caching * ci: fix playwright cache checking * test: fix content-type header assertion in SmokeTest * build(npm): update playwright version to 1.59.1 * ci: separate code coverage report to a separate workflow * build: remove shard scripts from composer.json * ci(tests): add sockets extension and enable `--ci` flag for Pest runs * build: update slimdeluxe/php images to v1.5 and add Playwright dependencies setup * test: add Pest shard timings file for improved test shard balancing * ci(tests): add Pest shard timings CI workflow * ci(tests): disable test shard splitting in CI workflow * build(npm): npm update * test: update workbench database SSL attribute for PHP 8.4+ compatibility * test: remove browser testing and playwright * style: fix code style * ci(tests): disable fail-fast in test-runner workflow * ci(tests): remove test shard splitting --------- Co-authored-by: Omer Sabic <omer@datalinx.si> Co-authored-by: SlimDeluxe <131700+SlimDeluxe@users.noreply.github.com>
1 parent b14a838 commit 09f46e0

10 files changed

Lines changed: 217 additions & 43 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Coverage
2+
3+
on:
4+
# Run testing on all push and pull requests that have committed changes in PHP files
5+
push:
6+
paths:
7+
- '**/*.php'
8+
pull_request:
9+
paths:
10+
- '**/*.php'
11+
# Make it possible to run the workflow manually
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
coverage:
19+
20+
runs-on: ubuntu-latest
21+
22+
name: Code coverage report
23+
24+
steps:
25+
26+
#- name: Configure operating system
27+
# run: sudo apt-get update && sudo apt-get install -y locales locales-all
28+
29+
- name: Checkout code
30+
uses: actions/checkout@v6.0.2
31+
with:
32+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
33+
34+
- name: Validate composer.json and composer.lock
35+
run: composer validate --strict
36+
37+
- name: Cache Composer packages
38+
id: composer-cache
39+
uses: actions/cache@v5.0.5
40+
with:
41+
path: vendor
42+
key: coverage-${{ hashFiles('**/composer.lock') }}
43+
44+
- name: Setup PHP
45+
uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: '8.3'
48+
coverage: xdebug
49+
extensions: mbstring, gd, intl, pcntl
50+
51+
- name: Install dependencies
52+
run: composer update --prefer-dist --no-progress --prefer-stable
53+
54+
- name: Setup testbench environment
55+
run: |
56+
cp workbench/.env.example workbench/.env
57+
sed -i 's/APP_KEY=/APP_KEY=base64:ZQvPGC7uVADkjOgtGIIuCI8u3\/Pzu+VaRObIbHsgjCc=/' workbench/.env
58+
sed -i 's/APP_ENV=local/APP_ENV=testing/' workbench/.env
59+
grep "APP_KEY=base64:" workbench/.env
60+
npm install
61+
php vendor/bin/testbench vendor:publish --tag='filament-shield-config'
62+
php vendor/bin/testbench filament:assets
63+
php vendor/bin/testbench package:sync-skeleton
64+
65+
- name: Run test suite with coverage
66+
run: vendor/bin/pest --coverage-clover ./coverage.xml
67+
68+
- name: Upload coverage reports to Codecov
69+
uses: codecov/codecov-action@v6.0.0
70+
env:
71+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
72+
with:
73+
files: ./coverage.xml
74+
verbose: true

.github/workflows/test-runner.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@ jobs:
6060
uses: shivammathur/setup-php@v2
6161
with:
6262
php-version: ${{ matrix.php }}
63-
coverage: xdebug
64-
# extensions: mbstring, gd, intl
63+
coverage: none
64+
extensions: mbstring, gd, intl, pcntl
6565

6666
- name: Install dependencies
6767
run: |
68-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
69-
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress --no-interaction
68+
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
69+
composer require "orchestra/testbench:${{ matrix.testbench }}" --dev --no-interaction --no-update
70+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress --no-interaction --no-scripts
7071
71-
- name: Run test suite
72-
run: composer test -- --coverage-clover ./coverage.xml
72+
- name: Setup testbench environment
73+
run: |
74+
cp workbench/.env.example workbench/.env
75+
sed -i 's/APP_KEY=/APP_KEY=base64:ZQvPGC7uVADkjOgtGIIuCI8u3\/Pzu+VaRObIbHsgjCc=/' workbench/.env
76+
sed -i 's/APP_ENV=local/APP_ENV=testing/' workbench/.env
77+
grep "APP_KEY=base64:" workbench/.env
78+
npm install
79+
php vendor/bin/testbench vendor:publish --tag='filament-shield-config'
80+
php vendor/bin/testbench filament:assets
81+
php vendor/bin/testbench package:sync-skeleton
7382
74-
- name: Upload coverage reports to Codecov
75-
# Make sure the Codecov action is only executed once
76-
if: matrix.php == '8.3' && matrix.laravel == '12.*' && matrix.dependency-version == 'prefer-stable'
77-
uses: codecov/codecov-action@v6.0.0
78-
env:
79-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
80-
with:
81-
files: ./coverage.xml
82-
verbose: true
83+
- name: Run test suite
84+
run: vendor/bin/pest --ci --parallel

.lando.dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
APP_BASE_PATH: "/app/workbench"
1515
TESTBENCH_WORKING_PATH: "/app"
1616
overrides:
17-
image: slimdeluxe/php:8.3-v1.4
17+
image: slimdeluxe/php:8.3-v1.5
1818
platform: linux/amd64
1919
run:
2020
- composer install --no-interaction --prefer-dist

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
"require-dev": {
5454
"laravel/pint": "^1.21",
5555
"orchestra/testbench": "^9.9|^10.0",
56-
"pestphp/pest": "^3.7",
57-
"pestphp/pest-plugin-livewire": "^3.0"
56+
"pestphp/pest": "^4.0",
57+
"pestphp/pest-plugin-laravel": "^4.0",
58+
"pestphp/pest-plugin-livewire": "^4.0"
5859
},
5960
"scripts": {
6061
"post-autoload-dump": [
@@ -64,7 +65,7 @@
6465
"post-install-cmd": "@setup",
6566
"post-update-cmd": "@setup",
6667
"format": "vendor/bin/pint",
67-
"test": "vendor/bin/testbench package:test",
68+
"test": "vendor/bin/pest --parallel",
6869
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
6970
"prepare": "@php vendor/bin/testbench package:discover --ansi",
7071
"build": "@php vendor/bin/testbench workbench:build --ansi",

env/php-8.4/.lando.dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
via: cli
66
app_mount: delegated
77
overrides:
8-
image: slimdeluxe/php:8.4-v1.4
8+
image: slimdeluxe/php:8.4-v1.5
99
volumes:
1010
# Mount the project root directory to /app
1111
- "../..:/app"

env/php-8.5/.lando.dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
via: cli
66
app_mount: delegated
77
overrides:
8-
image: slimdeluxe/php:8.5-v1.4
8+
image: slimdeluxe/php:8.5-v1.5
99
volumes:
1010
# Mount the project root directory to /app
1111
- "../..:/app"

package-lock.json

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/SmokeTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
use Eclipse\World\Filament\Clusters\World\Resources\CountryResource;
4+
use Eclipse\World\Filament\Clusters\World\Resources\CurrencyResource;
5+
use Eclipse\World\Filament\Clusters\World\Resources\PostResource;
6+
use Eclipse\World\Filament\Clusters\World\Resources\RegionResource;
7+
8+
beforeEach(function () {
9+
$this->setUpSuperAdmin();
10+
});
11+
12+
describe('Smoke Tests', function () {
13+
test('all resource URLs are accessible', function () {
14+
$resources = [
15+
CountryResource::class,
16+
CurrencyResource::class,
17+
PostResource::class,
18+
RegionResource::class,
19+
];
20+
21+
foreach ($resources as $resource) {
22+
/** @noinspection PhpUndefinedMethodInspection */
23+
$this->get($resource::getUrl())
24+
->assertSuccessful()
25+
->assertSee('Filament');
26+
}
27+
});
28+
29+
test('country resource URLs are accessible', function () {
30+
$this->get(CountryResource::getUrl())
31+
->assertSuccessful()
32+
->assertSee('Countries')
33+
->assertSee('Filament');
34+
});
35+
36+
test('currency resource URLs are accessible', function () {
37+
$this->get(CurrencyResource::getUrl())
38+
->assertSuccessful()
39+
->assertSee('Currencies')
40+
->assertSee('Filament');
41+
});
42+
43+
test('post resource URLs are accessible', function () {
44+
$this->get(PostResource::getUrl())
45+
->assertSuccessful()
46+
->assertSee('Posts')
47+
->assertSee('Filament');
48+
});
49+
50+
test('region resource URLs are accessible', function () {
51+
$this->get(RegionResource::getUrl())
52+
->assertSuccessful()
53+
->assertSee('Regions')
54+
->assertSee('Filament');
55+
});
56+
57+
test('all resource URLs return valid HTML', function () {
58+
$resources = [
59+
CountryResource::class,
60+
CurrencyResource::class,
61+
PostResource::class,
62+
RegionResource::class,
63+
];
64+
65+
foreach ($resources as $resource) {
66+
/** @noinspection PhpUndefinedMethodInspection */
67+
$response = $this->get($resource::getUrl());
68+
69+
$response->assertSuccessful();
70+
$response->assertHeader('content-type', 'text/html; charset=utf-8');
71+
$response->assertSee('<!DOCTYPE html>', false);
72+
}
73+
});
74+
75+
test('all resource URLs have no JavaScript errors', function () {
76+
$resources = [
77+
CountryResource::class,
78+
CurrencyResource::class,
79+
PostResource::class,
80+
RegionResource::class,
81+
];
82+
83+
foreach ($resources as $resource) {
84+
/** @noinspection PhpUndefinedMethodInspection */
85+
$response = $this->get($resource::getUrl());
86+
87+
$response->assertSuccessful();
88+
$response->assertDontSee('Uncaught');
89+
$response->assertDontSee('ReferenceError');
90+
$response->assertDontSee('TypeError');
91+
}
92+
});
93+
});

tests/TestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ protected function migrate(): self
4242
*/
4343
protected function setUpSuperAdmin(): self
4444
{
45-
$this->superAdmin = User::factory()->create();
45+
$this->superAdmin = User::factory()->create([
46+
'name' => 'Test Super Admin',
47+
'email' => 'test@example.com',
48+
]);
4649

4750
// Assign super admin role and give all permissions
4851
$superAdminRole = Role::where('name', 'super_admin')->first();

workbench/config/database.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Illuminate\Support\Str;
4+
use Pdo\Mysql;
45

56
return [
67

@@ -58,7 +59,7 @@
5859
'strict' => true,
5960
'engine' => null,
6061
'options' => extension_loaded('pdo_mysql') ? array_filter([
61-
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
62+
version_compare(PHP_VERSION, '8.4', '>=') ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
6263
]) : [],
6364
],
6465

0 commit comments

Comments
 (0)