Skip to content

Commit e092bea

Browse files
mmitchgarvinhicking
authored andcommitted
add simple CI pipeline with basic PHP test runner (#823)
* add initial PHP test workflow test matrix contains all currently released and supported PHP versions * actually run the tests as described in tests/README * tests: fix PHPUnit imports * tests: fix missing constant S9Y_INCLUDE_PATH * tests: fix PHPUnit deprecation warning: DataProviders must be static ``` 2 tests triggered 2 PHPUnit deprecations: 1) functionsTest::test_serendipity_serverOffsetHour Data Provider method functionsTest::serverOffsetHourDataProvider() is not static /home/runner/work/Serendipity/Serendipity/tests/include/functionsTest.php:17 2) functionsTest::test_serendipity_serverOffsetHourWithTimestampNull Data Provider method functionsTest::serverOffsetHourWithTimestampNullDataProvider() is not static /home/runner/work/Serendipity/Serendipity/tests/include/functionsTest.php:46 ``` * tests: migrate PHPUnit XML configuration to version 11.0 ``` There was 1 PHPUnit test runner deprecation: 1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"! ``` * tests: disable code coverage for now * tests: migrate doc-comments to Attributes ``` There were 3 PHPUnit test runner deprecations: 1) Metadata found in doc-comment for method functionsConfigTest::test_serendipity_getTemplateFile(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. 2) Metadata found in doc-comment for method functionsTest::test_serendipity_serverOffsetHour(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. 3) Metadata found in doc-comment for method functionsTest::test_serendipity_serverOffsetHourWithTimestampNull(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. ``` * tests: fix assertions `assertContains()` is used for arrays etc., but we only have a string. Use `assertStringEndsWith()` instead, the _ends with_ also makes the test more robust. * tests: also run on PHP 7.4
1 parent 383b667 commit e092bea

File tree

5 files changed

+97
-64
lines changed

5 files changed

+97
-64
lines changed

.github/workflows/php_tests.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will run the tests on various versions of PHP.
2+
3+
name: PHP Tests
4+
5+
on:
6+
push:
7+
pull_request:
8+
types: [opened]
9+
# TODO: enable to run once a week regardless of commits, but this will expire if repo is inactive for a longer time
10+
# schedule:
11+
# - cron: '12 3 4 * *'
12+
13+
jobs:
14+
test-php:
15+
name: Run PHP Tests
16+
17+
runs-on: ubuntu-22.04
18+
19+
# for available versions see https://github.com/marketplace/actions/setup-php-action#tada-php-support
20+
strategy:
21+
matrix:
22+
phpversion: ['7.4', '8.1', '8.2', '8.3']
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Setup PHP and dependencies
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: ${{ matrix.phpversion }}
30+
extensions: pdo-sqlite
31+
tools: phpunit
32+
# TODO: enable coverage check
33+
coverage: none
34+
env:
35+
fail-fast: true
36+
- name: Run Tests
37+
run: |
38+
cd tests
39+
phpunit --configuration config.xml.dist include/*

tests/config.xml.dist

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit>
4-
<filter>
5-
<whitelist addUncoveredFilesFromWhitelist="false">
6-
<directory>../include</directory>
7-
<directory>../plugins</directory>
8-
<exclude>
9-
<file>../include/db/mysql.inc.php</file>
10-
<file>../include/db/mysqli.inc.php</file>
11-
<file>../include/db/pdo-postgres.inc.php</file>
12-
<file>../include/db/postgres.inc.php</file>
13-
<file>../include/db/mysql.inc.php</file>
14-
<file>../include/db/sqlrelay.inc.php</file>
15-
</exclude>
16-
</whitelist>
17-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
183
<php>
194
<var name="S9Y_INSTALLDIR" value="http://localhost/s9y"/>
205
<var name="S9Y_LANG" value="en"/>
@@ -23,4 +8,18 @@
238
<var name="S9Y_SELENIUM_PORT" value="4444"/>
249
<var name="S9Y_SELENIUM_BROWSER" value="*firefox /usr/lib/firefox/firefox-bin"/>
2510
</php>
11+
<source>
12+
<include>
13+
<directory>../include</directory>
14+
<directory>../plugins</directory>
15+
</include>
16+
<exclude>
17+
<file>../include/db/mysql.inc.php</file>
18+
<file>../include/db/mysqli.inc.php</file>
19+
<file>../include/db/pdo-postgres.inc.php</file>
20+
<file>../include/db/postgres.inc.php</file>
21+
<file>../include/db/mysql.inc.php</file>
22+
<file>../include/db/sqlrelay.inc.php</file>
23+
</exclude>
24+
</source>
2625
</phpunit>

tests/include/functionsConfigTest.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
define('IN_serendipity', true);
55
require_once dirname(__FILE__) . '/../../include/functions_config.inc.php';
66

7+
use PHPUnit\Framework\Attributes\Test;
8+
79
/**
810
* Class functionsTest
911
*/
10-
class functionsConfigTest extends PHPUnit_Framework_TestCase
12+
class functionsConfigTest extends PHPUnit\Framework\TestCase
1113
{
12-
/**
13-
* @test
14-
*/
14+
#[Test]
1515
public function test_serendipity_getTemplateFile()
1616
{
1717
global $serendipity;
@@ -22,12 +22,11 @@ public function test_serendipity_getTemplateFile()
2222
$serendipity['template_backend'] = '2k11';
2323
$serendipity['serendipityPath'] = realpath('../');
2424
$serendipity['serendipityHTTPPath'] = realpath('/');
25-
26-
$this->assertContains('next/index.tpl', serendipity_getTemplateFile('index.tpl'));
25+
26+
$this->assertStringEndsWith('next/index.tpl', serendipity_getTemplateFile('index.tpl'));
2727
define('IN_serendipity_admin', true);
28-
$this->assertContains('2k11/admin/index.tpl', serendipity_getTemplateFile('admin/index.tpl'));
29-
$this->assertContains('next/index.tpl', serendipity_getTemplateFile('index.tpl', 'serendipityHTTPPath', true));
28+
$this->assertStringEndsWith('2k11/admin/index.tpl', serendipity_getTemplateFile('admin/index.tpl'));
29+
$this->assertStringEndsWith('next/index.tpl', serendipity_getTemplateFile('index.tpl', 'serendipityHTTPPath', true));
3030
}
3131

32-
33-
}
32+
}

tests/include/functionsTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
$serendipity['dbType'] = 'pdo-sqlite';
44
define('IN_serendipity', true);
5+
define('S9Y_INCLUDE_PATH', dirname(__FILE__) . '/../../');
56
require_once dirname(__FILE__) . '/../../include/functions.inc.php';
67

8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\Attributes\Test;
10+
711
/**
812
* Class functionsTest
913
*/
10-
class functionsTest extends PHPUnit_Framework_TestCase
14+
class functionsTest extends PHPUnit\Framework\TestCase
1115
{
12-
/**
13-
* @test
14-
* @dataProvider serverOffsetHourDataProvider
15-
*/
16+
#[Test]
17+
#[DataProvider("serverOffsetHourDataProvider")]
1618
public function test_serendipity_serverOffsetHour($serverOffsetHours, $timestamp, $negative, $expected)
1719
{
1820
global $serendipity;
@@ -24,7 +26,7 @@ public function test_serendipity_serverOffsetHour($serverOffsetHours, $timestamp
2426
/**
2527
* @return array
2628
*/
27-
public function serverOffsetHourDataProvider()
29+
public static function serverOffsetHourDataProvider()
2830
{
2931
return array(
3032
array(0, 0, false, 0),
@@ -38,10 +40,8 @@ public function serverOffsetHourDataProvider()
3840
);
3941
}
4042

41-
/**
42-
* @test
43-
* @dataProvider serverOffsetHourWithTimestampNullDataProvider
44-
*/
43+
#[Test]
44+
#[DataProvider("serverOffsetHourWithTimestampNullDataProvider")]
4545
public function test_serendipity_serverOffsetHourWithTimestampNull($serverOffsetHours, $negative)
4646
{
4747
global $serendipity;
@@ -62,7 +62,7 @@ public function test_serendipity_serverOffsetHourWithTimestampNull($serverOffset
6262
/**
6363
* @return array
6464
*/
65-
public function serverOffsetHourWithTimestampNullDataProvider()
65+
public static function serverOffsetHourWithTimestampNullDataProvider()
6666
{
6767
return array(
6868
array(null, false),

tests/phpunit.xml.dist

+23-27
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
<?xml version="1.0" encoding="UTF-8" ?>
2-
<phpunit bootstrap="bootstrap.php"
3-
backupGlobals="true"
4-
convertErrorsToExceptions="true"
5-
convertNoticesToExceptions="true"
6-
convertWarningsToExceptions="true"
7-
colors="true">
8-
<php>
9-
<const name="IN_serendipity" value="true"/>
10-
<!--<const name="IS_installed" value="true"/>-->
11-
<!--<const name="USERLEVEL_ADMIN" value="255"/>-->
12-
<!--<const name="USERLEVEL_CHIEF" value="1"/>-->
13-
<!--<const name="USERLEVEL_EDITOR" value="0"/>-->
14-
<!--<const name="DB_DSN" value="sqlite:dbname=s9y_test;host=localhost" />-->
15-
<!--<const name="DB_HOST" value="localhost" />-->
16-
<!--<const name="DB_TYPE" value="pdo-sqlite" />-->
17-
<!--<const name="DB_USER" value="s9y_test" />-->
18-
<!--<const name="DB_PASSWD" value="s9y_test" />-->
19-
<!--<const name="DB_DBNAME" value="s9y_test" />-->
20-
<!--<const name="TEST_DB" value="test.db" />-->
21-
<!--<const name="PATH_SMARTY_COMPILE" value="templates_c" />-->
22-
</php>
23-
<testsuites>
24-
<testsuite name="include">
25-
<directory>../tests/include</directory>
26-
</testsuite>
27-
</testsuites>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="bootstrap.php" backupGlobals="true" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
3+
<php>
4+
<const name="IN_serendipity" value="true"/>
5+
<!--<const name="IS_installed" value="true"/>-->
6+
<!--<const name="USERLEVEL_ADMIN" value="255"/>-->
7+
<!--<const name="USERLEVEL_CHIEF" value="1"/>-->
8+
<!--<const name="USERLEVEL_EDITOR" value="0"/>-->
9+
<!--<const name="DB_DSN" value="sqlite:dbname=s9y_test;host=localhost" />-->
10+
<!--<const name="DB_HOST" value="localhost" />-->
11+
<!--<const name="DB_TYPE" value="pdo-sqlite" />-->
12+
<!--<const name="DB_USER" value="s9y_test" />-->
13+
<!--<const name="DB_PASSWD" value="s9y_test" />-->
14+
<!--<const name="DB_DBNAME" value="s9y_test" />-->
15+
<!--<const name="TEST_DB" value="test.db" />-->
16+
<!--<const name="PATH_SMARTY_COMPILE" value="templates_c" />-->
17+
</php>
18+
<testsuites>
19+
<testsuite name="include">
20+
<directory>../tests/include</directory>
21+
</testsuite>
22+
</testsuites>
23+
<source/>
2824
</phpunit>

0 commit comments

Comments
 (0)