Skip to content

Commit 5efc779

Browse files
authored
GitHub Actions: Use new PHP workflow (#93)
This PR switches to the new PHP workflow, which combines linting, static analysis, and unit testing. `phpcs.xml` and `phpunit.xml` have been removed, as the new workflow provides sane defaults for both and the files did not contain any special configurations anyway. Since the new workflow uses the latest PHPUnit version by default, deprecated PHPUnit features have been migrated.
2 parents 6b12a66 + 4313ad0 commit 5efc779

File tree

5 files changed

+16
-173
lines changed

5 files changed

+16
-173
lines changed

.github/workflows/php.yml

Lines changed: 7 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,17 @@
1-
name: PHP Tests
1+
name: CI
22

33
on:
44
push:
55
branches:
66
- main
7-
- release/*
87
pull_request:
98
branches:
109
- main
1110

1211
jobs:
13-
lint:
14-
name: Static analysis for php ${{ matrix.php }} on ${{ matrix.os }}
15-
runs-on: ${{ matrix.os }}
16-
17-
strategy:
18-
fail-fast: false
19-
matrix:
20-
php: ['8.2', '8.3', '8.4']
21-
os: ['ubuntu-latest']
22-
23-
steps:
24-
- name: Checkout code base
25-
uses: actions/checkout@v5
26-
27-
- name: Setup PHP
28-
uses: shivammathur/setup-php@v2
29-
with:
30-
php-version: ${{ matrix.php }}
31-
tools: phpcs
32-
33-
- name: Setup dependencies
34-
run: composer require -n --no-progress overtrue/phplint
35-
36-
- name: PHP Lint
37-
if: ${{ ! cancelled() }}
38-
run: ./vendor/bin/phplint -n --exclude={^vendor/.*} -- .
39-
40-
- name: PHP CodeSniffer
41-
if: ${{ ! cancelled() }}
42-
run: phpcs -wps --colors
43-
44-
test:
45-
name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }}
46-
runs-on: ${{ matrix.os }}
47-
48-
env:
49-
phpunit-version: 8.5
50-
51-
strategy:
52-
fail-fast: false
53-
matrix:
54-
php: ['8.2', '8.3', '8.4']
55-
os: ['ubuntu-latest']
56-
57-
services:
58-
mysql:
59-
image: mariadb
60-
env:
61-
MYSQL_ROOT_PASSWORD: root
62-
MYSQL_DATABASE: icinga_unittest
63-
MYSQL_USER: icinga_unittest
64-
MYSQL_PASSWORD: icinga_unittest
65-
options: >-
66-
--health-cmd "mariadb -s -uroot -proot -e'SHOW DATABASES;' 2> /dev/null | grep icinga_unittest > test"
67-
--health-interval 10s
68-
--health-timeout 5s
69-
--health-retries 5
70-
ports:
71-
- 3306/tcp
72-
73-
pgsql:
74-
image: postgres
75-
env:
76-
POSTGRES_USER: icinga_unittest
77-
POSTGRES_PASSWORD: icinga_unittest
78-
POSTGRES_DB: icinga_unittest
79-
options: >-
80-
--health-cmd pg_isready
81-
--health-interval 10s
82-
--health-timeout 5s
83-
--health-retries 5
84-
ports:
85-
- 5432/tcp
86-
87-
steps:
88-
- name: Checkout code base
89-
uses: actions/checkout@v5
90-
91-
- name: Setup PHP
92-
uses: shivammathur/setup-php@v2
93-
with:
94-
php-version: ${{ matrix.php }}
95-
tools: phpunit:${{ matrix.phpunit-version || env.phpunit-version }}
96-
extensions: pdo, pdo-sqlite
97-
98-
- name: Setup dependencies
99-
run: composer install -n --no-progress
100-
101-
- name: PHPUnit
102-
env:
103-
MYSQL_TESTDB: icinga_unittest
104-
MYSQL_TESTDB_HOST: 127.0.0.1
105-
MYSQL_TESTDB_PORT: ${{ job.services.mysql.ports['3306'] }}
106-
MYSQL_TESTDB_USER: icinga_unittest
107-
MYSQL_TESTDB_PASSWORD: icinga_unittest
108-
PGSQL_TESTDB: icinga_unittest
109-
PGSQL_TESTDB_HOST: 127.0.0.1
110-
PGSQL_TESTDB_PORT: ${{ job.services.pgsql.ports['5432'] }}
111-
PGSQL_TESTDB_USER: icinga_unittest
112-
PGSQL_TESTDB_PASSWORD: icinga_unittest
113-
run: phpunit --verbose
12+
php:
13+
name: PHP
14+
uses: Icinga/github-actions/.github/workflows/php.yml@main
15+
with:
16+
php-extensions: pdo, pdo-sqlite
17+
databases: true

.github/workflows/phpstan.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

phpcs.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

phpunit.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/SharedDatabasesTest.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use ipl\Sql\Connection;
66
use ipl\Sql\Select;
77
use ipl\Sql\Test\SharedDatabases;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\Attributes\Depends;
810

911
/**
1012
* A test for a test component! Yay!
@@ -13,7 +15,7 @@ class SharedDatabasesTest extends TestCase
1315
{
1416
use SharedDatabases;
1517

16-
/** @dataProvider sharedDatabases */
18+
#[DataProvider('sharedDatabases')]
1719
public function testInsert(Connection $db)
1820
{
1921
// This is the first case, so the table must have been dropped and be empty
@@ -24,10 +26,8 @@ public function testInsert(Connection $db)
2426
$db->insert('test', ['name' => 'test2']);
2527
}
2628

27-
/**
28-
* @depends testInsert
29-
* @dataProvider sharedDatabases
30-
*/
29+
#[Depends('testInsert')]
30+
#[DataProvider('sharedDatabases')]
3131
public function testSelect(Connection $db)
3232
{
3333
// The previous case inserts "name=test" but tearDown removes it
@@ -36,20 +36,16 @@ public function testSelect(Connection $db)
3636
$this->assertSame('test2', $result[0]['name']);
3737
}
3838

39-
/**
40-
* @depends testSelect
41-
* @dataProvider sharedDatabases
42-
*/
39+
#[Depends('testSelect')]
40+
#[DataProvider('sharedDatabases')]
4341
public function testUpdate(Connection $db)
4442
{
4543
$stmt = $db->update('test', ['name' => 'test3'], ['name = ?' => 'test2']);
4644
$this->assertEquals(1, $stmt->rowCount());
4745
}
4846

49-
/**
50-
* @depends testUpdate
51-
* @dataProvider sharedDatabases
52-
*/
47+
#[Depends('testUpdate')]
48+
#[DataProvider('sharedDatabases')]
5349
public function testDelete(Connection $db)
5450
{
5551
$stmt = $db->delete('test', ['name = ?' => 'test3']);

0 commit comments

Comments
 (0)