Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simple CI pipeline with basic PHP test runner #823

Merged
merged 10 commits into from
Feb 20, 2024
39 changes: 39 additions & 0 deletions .github/workflows/php_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will run the tests on various versions of PHP.

name: PHP Tests

on:
push:
pull_request:
types: [opened]
# TODO: enable to run once a week regardless of commits, but this will expire if repo is inactive for a longer time
# schedule:
# - cron: '12 3 4 * *'

jobs:
test-php:
name: Run PHP Tests

runs-on: ubuntu-22.04

# for available versions see https://github.com/marketplace/actions/setup-php-action#tada-php-support
strategy:
matrix:
phpversion: ['8.1', '8.2', '8.3']

steps:
- uses: actions/checkout@v4
- name: Setup PHP and dependencies
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.phpversion }}
extensions: pdo-sqlite
tools: phpunit
# TODO: enable coverage check
coverage: none
env:
fail-fast: true
- name: Run Tests
run: |
cd tests
phpunit --configuration config.xml.dist include/*
31 changes: 15 additions & 16 deletions tests/config.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit>
<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<directory>../include</directory>
<directory>../plugins</directory>
<exclude>
<file>../include/db/mysql.inc.php</file>
<file>../include/db/mysqli.inc.php</file>
<file>../include/db/pdo-postgres.inc.php</file>
<file>../include/db/postgres.inc.php</file>
<file>../include/db/mysql.inc.php</file>
<file>../include/db/sqlrelay.inc.php</file>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
<php>
<var name="S9Y_INSTALLDIR" value="http://localhost/s9y"/>
<var name="S9Y_LANG" value="en"/>
Expand All @@ -23,4 +8,18 @@
<var name="S9Y_SELENIUM_PORT" value="4444"/>
<var name="S9Y_SELENIUM_BROWSER" value="*firefox /usr/lib/firefox/firefox-bin"/>
</php>
<source>
<include>
<directory>../include</directory>
<directory>../plugins</directory>
</include>
<exclude>
<file>../include/db/mysql.inc.php</file>
<file>../include/db/mysqli.inc.php</file>
<file>../include/db/pdo-postgres.inc.php</file>
<file>../include/db/postgres.inc.php</file>
<file>../include/db/mysql.inc.php</file>
<file>../include/db/sqlrelay.inc.php</file>
</exclude>
</source>
</phpunit>
19 changes: 9 additions & 10 deletions tests/include/functionsConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
define('IN_serendipity', true);
require_once dirname(__FILE__) . '/../../include/functions_config.inc.php';

use PHPUnit\Framework\Attributes\Test;

/**
* Class functionsTest
*/
class functionsConfigTest extends PHPUnit_Framework_TestCase
class functionsConfigTest extends PHPUnit\Framework\TestCase
{
/**
* @test
*/
#[Test]
public function test_serendipity_getTemplateFile()
{
global $serendipity;
Expand All @@ -22,12 +22,11 @@ public function test_serendipity_getTemplateFile()
$serendipity['template_backend'] = '2k11';
$serendipity['serendipityPath'] = realpath('../');
$serendipity['serendipityHTTPPath'] = realpath('/');
$this->assertContains('next/index.tpl', serendipity_getTemplateFile('index.tpl'));

$this->assertStringEndsWith('next/index.tpl', serendipity_getTemplateFile('index.tpl'));
define('IN_serendipity_admin', true);
$this->assertContains('2k11/admin/index.tpl', serendipity_getTemplateFile('admin/index.tpl'));
$this->assertContains('next/index.tpl', serendipity_getTemplateFile('index.tpl', 'serendipityHTTPPath', true));
$this->assertStringEndsWith('2k11/admin/index.tpl', serendipity_getTemplateFile('admin/index.tpl'));
$this->assertStringEndsWith('next/index.tpl', serendipity_getTemplateFile('index.tpl', 'serendipityHTTPPath', true));
}


}
}
22 changes: 11 additions & 11 deletions tests/include/functionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

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

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

/**
* Class functionsTest
*/
class functionsTest extends PHPUnit_Framework_TestCase
class functionsTest extends PHPUnit\Framework\TestCase
{
/**
* @test
* @dataProvider serverOffsetHourDataProvider
*/
#[Test]
#[DataProvider("serverOffsetHourDataProvider")]
public function test_serendipity_serverOffsetHour($serverOffsetHours, $timestamp, $negative, $expected)
{
global $serendipity;
Expand All @@ -24,7 +26,7 @@ public function test_serendipity_serverOffsetHour($serverOffsetHours, $timestamp
/**
* @return array
*/
public function serverOffsetHourDataProvider()
public static function serverOffsetHourDataProvider()
{
return array(
array(0, 0, false, 0),
Expand All @@ -38,10 +40,8 @@ public function serverOffsetHourDataProvider()
);
}

/**
* @test
* @dataProvider serverOffsetHourWithTimestampNullDataProvider
*/
#[Test]
#[DataProvider("serverOffsetHourWithTimestampNullDataProvider")]
public function test_serendipity_serverOffsetHourWithTimestampNull($serverOffsetHours, $negative)
{
global $serendipity;
Expand All @@ -62,7 +62,7 @@ public function test_serendipity_serverOffsetHourWithTimestampNull($serverOffset
/**
* @return array
*/
public function serverOffsetHourWithTimestampNullDataProvider()
public static function serverOffsetHourWithTimestampNullDataProvider()
{
return array(
array(null, false),
Expand Down
50 changes: 23 additions & 27 deletions tests/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="bootstrap.php"
backupGlobals="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
colors="true">
<php>
<const name="IN_serendipity" value="true"/>
<!--<const name="IS_installed" value="true"/>-->
<!--<const name="USERLEVEL_ADMIN" value="255"/>-->
<!--<const name="USERLEVEL_CHIEF" value="1"/>-->
<!--<const name="USERLEVEL_EDITOR" value="0"/>-->
<!--<const name="DB_DSN" value="sqlite:dbname=s9y_test;host=localhost" />-->
<!--<const name="DB_HOST" value="localhost" />-->
<!--<const name="DB_TYPE" value="pdo-sqlite" />-->
<!--<const name="DB_USER" value="s9y_test" />-->
<!--<const name="DB_PASSWD" value="s9y_test" />-->
<!--<const name="DB_DBNAME" value="s9y_test" />-->
<!--<const name="TEST_DB" value="test.db" />-->
<!--<const name="PATH_SMARTY_COMPILE" value="templates_c" />-->
</php>
<testsuites>
<testsuite name="include">
<directory>../tests/include</directory>
</testsuite>
</testsuites>
<?xml version="1.0" encoding="UTF-8"?>
<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">
<php>
<const name="IN_serendipity" value="true"/>
<!--<const name="IS_installed" value="true"/>-->
<!--<const name="USERLEVEL_ADMIN" value="255"/>-->
<!--<const name="USERLEVEL_CHIEF" value="1"/>-->
<!--<const name="USERLEVEL_EDITOR" value="0"/>-->
<!--<const name="DB_DSN" value="sqlite:dbname=s9y_test;host=localhost" />-->
<!--<const name="DB_HOST" value="localhost" />-->
<!--<const name="DB_TYPE" value="pdo-sqlite" />-->
<!--<const name="DB_USER" value="s9y_test" />-->
<!--<const name="DB_PASSWD" value="s9y_test" />-->
<!--<const name="DB_DBNAME" value="s9y_test" />-->
<!--<const name="TEST_DB" value="test.db" />-->
<!--<const name="PATH_SMARTY_COMPILE" value="templates_c" />-->
</php>
<testsuites>
<testsuite name="include">
<directory>../tests/include</directory>
</testsuite>
</testsuites>
<source/>
</phpunit>