diff --git a/.github/workflows/php_tests.yml b/.github/workflows/php_tests.yml new file mode 100644 index 000000000..76e32c40f --- /dev/null +++ b/.github/workflows/php_tests.yml @@ -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: ['7.4', '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/* diff --git a/tests/config.xml.dist b/tests/config.xml.dist index 1cdea6559..b68e28884 100644 --- a/tests/config.xml.dist +++ b/tests/config.xml.dist @@ -1,20 +1,5 @@ - - - - - ../include - ../plugins - - ../include/db/mysql.inc.php - ../include/db/mysqli.inc.php - ../include/db/pdo-postgres.inc.php - ../include/db/postgres.inc.php - ../include/db/mysql.inc.php - ../include/db/sqlrelay.inc.php - - - + @@ -23,4 +8,18 @@ + + + ../include + ../plugins + + + ../include/db/mysql.inc.php + ../include/db/mysqli.inc.php + ../include/db/pdo-postgres.inc.php + ../include/db/postgres.inc.php + ../include/db/mysql.inc.php + ../include/db/sqlrelay.inc.php + + diff --git a/tests/include/functionsConfigTest.php b/tests/include/functionsConfigTest.php index 52f0a5095..d8277e72b 100644 --- a/tests/include/functionsConfigTest.php +++ b/tests/include/functionsConfigTest.php @@ -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; @@ -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)); } - -} \ No newline at end of file +} diff --git a/tests/include/functionsTest.php b/tests/include/functionsTest.php index d20dd2cf9..a1db77b56 100644 --- a/tests/include/functionsTest.php +++ b/tests/include/functionsTest.php @@ -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; @@ -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), @@ -38,10 +40,8 @@ public function serverOffsetHourDataProvider() ); } - /** - * @test - * @dataProvider serverOffsetHourWithTimestampNullDataProvider - */ + #[Test] + #[DataProvider("serverOffsetHourWithTimestampNullDataProvider")] public function test_serendipity_serverOffsetHourWithTimestampNull($serverOffsetHours, $negative) { global $serendipity; @@ -62,7 +62,7 @@ public function test_serendipity_serverOffsetHourWithTimestampNull($serverOffset /** * @return array */ - public function serverOffsetHourWithTimestampNullDataProvider() + public static function serverOffsetHourWithTimestampNullDataProvider() { return array( array(null, false), diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist index ad28e69d0..9ecd504a8 100644 --- a/tests/phpunit.xml.dist +++ b/tests/phpunit.xml.dist @@ -1,28 +1,24 @@ - - - - - - - - - - - - - - - - - - - - ../tests/include - - + + + + + + + + + + + + + + + + + + + + ../tests/include + + +