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

Run unit tests in CI on Windows too #9251

Merged
merged 7 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/config-test.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$config = [];

// Database configuration
$config['db_dsnw'] = 'sqlite:////tmp/sqlite.db?mode=0646';
$config['db_dsnw'] = 'sqlite:///' . sys_get_temp_dir() . '/roundcube-test-sqlite.db?mode=0646';

// Test user credentials
$config['tests_username'] = 'test';
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/browser_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: browser_tests
name: E2E

on:
push:
Expand All @@ -14,8 +14,10 @@ jobs:

strategy:
fail-fast: true
matrix:
php: ["8.1"]

name: Browser Tests
name: Linux / PHP ${{ matrix.php }}

steps:
- name: Checkout code
Expand All @@ -24,7 +26,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: ${{ matrix.php }}
extensions: dom, curl, fileinfo, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, ldap, intl, pspell
tools: composer:v2
coverage: none
Expand Down
48 changes: 41 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: tests
name: Unit

on:
push:
Expand All @@ -8,7 +8,7 @@ permissions:
contents: read

jobs:
linux_tests:
tests_linux:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"

Expand All @@ -17,7 +17,7 @@ jobs:
matrix:
php: ["7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]

name: PHP ${{ matrix.php }}/Linux
name: Linux / PHP ${{ matrix.php }}

steps:
- name: Checkout code
Expand All @@ -43,10 +43,6 @@ jobs:
cp composer.json-dist composer.json
composer require "kolab/net_ldap3:~1.1.1" --no-update

- name: Fix PHPUnit for PHP 8.2
run: composer config platform.php 8.1
if: matrix.php >= 8.2

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress

Expand All @@ -62,3 +58,41 @@ jobs:
with:
name: Logs
path: logs/errors.log

tests_windows:
runs-on: windows-latest
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"

strategy:
fail-fast: true
matrix:
php: ["7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]

name: Windows / PHP ${{ matrix.php }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, fileinfo, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, ldap, intl
tools: composer:v2
coverage: none
ini-values: error_reporting=E_ALL

- name: Setup composer
run: |
cp composer.json-dist composer.json
composer require "kolab/net_ldap3:~1.1.1" --no-update

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Roundcube configuration
run: cp .github/config-test.inc.php config/config-test.inc.php

- name: Execute tests
run: vendor/bin/phpunit -c tests/phpunit.xml
5 changes: 5 additions & 0 deletions tests/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# prevent git EOL conversion
/src/sql/*.sql -text
/src/format-flowed.txt -text
/src/format-flowed-unfolded.txt -text
*.php eol=lf
3 changes: 2 additions & 1 deletion tests/ActionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public static function initDB($file = null)
}
else if ($dsn['phptype'] == 'sqlite') {
$db->closeConnection();

// delete database file
system(sprintf('rm -f %s', escapeshellarg($dsn['database'])));
unlink($dsn['database']);

// load sample test data
self::loadSQLScript($db, 'init');
Expand Down
7 changes: 7 additions & 0 deletions tests/Framework/Rcube.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ function test_encrypt_and_decrypt()
*/
function test_exec()
{
if (PHP_OS_FAMILY === 'Windows') {
$this->assertSame('', rcube::exec('where.exe unknown-command-123 2> nul'));
$this->assertSame('12', rcube::exec('set /a 10 + {v}', ['v' => '2']));

return;
}

$this->assertSame('', rcube::exec('which unknown-command-123'));
$this->assertSame("2038\n", rcube::exec('date --date={date} +%Y', ['date' => '@2147483647']));
// TODO: More cases
Expand Down
2 changes: 1 addition & 1 deletion tests/Framework/TnefDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function test_rtf2text()
$body = file_get_contents(TESTS_DIR . 'src/sample.rtf');
$text = rcube_tnef_decoder::rtf2text($body);

$this->assertMatchesRegularExpression('/^[a-zA-Z1-6!&<,> \n\.]+$/', $text);
$this->assertMatchesRegularExpression('/^[a-zA-Z1-6!&<,> \n\r\.]+$/', $text);
$this->assertTrue(strpos($text, 'Alex Skolnick') !== false);
$this->assertTrue(strpos($text, 'Heading 1') !== false);
$this->assertTrue(strpos($text, 'Heading 2') !== false);
Expand Down
4 changes: 4 additions & 0 deletions tests/Rcmail/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ function test_check_mime_detection()

/**
* Test check_mime_extensions() method
*
* Windows feature request: https://github.com/php/php-src/issues/12918
*
* @requires OSFAMILY Linux
*/
function test_check_mime_extensions()
{
Expand Down