From aee12a9f372d839cfbbf3005245b0d691cfdbb4b Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Sun, 10 May 2020 16:22:55 +0200 Subject: tests: run tests over multiple OS --- .github/workflows/php.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 6172685..9cccc26 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -6,11 +6,17 @@ on: jobs: test-php: - name: test (php ${{ matrix.php-versions }}) - runs-on: ubuntu-latest + name: test php ${{ matrix.php }} / ${{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: matrix: - php-versions: ['7.2', '7.3', '7.4'] + os: [ubuntu-latest] + php: ['7.2', '7.3', '7.4'] + include: + - os: windows-latest + php: '7.4' + - os: macos-latest + php: '7.4' steps: - name: Git checkout uses: actions/checkout@v2 @@ -18,7 +24,8 @@ jobs: - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php with: - php-version: ${{ matrix.php-versions }} + php-version: ${{ matrix.php }} + extensions: mbstring coverage: xdebug - name: Validate composer.json and composer.lock @@ -50,7 +57,7 @@ jobs: with: file: ./build/phpunit/cov.xml flags: php - name: php-${{ matrix.php-versions }} + name: php-${{ matrix.php }}-${{ matrix.os }} lint: name: lint -- cgit v1.2.3 From 2f8105cabf63f3ef3d4a59c306f4e1403d3c5164 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Sun, 10 May 2020 16:46:45 +0200 Subject: fix: log file was not closed --- app/class/Logger.php | 8 ++++++++ index.php | 1 + tests/LoggerTest.php | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/app/class/Logger.php b/app/class/Logger.php index e2ab4b6..beceddb 100644 --- a/app/class/Logger.php +++ b/app/class/Logger.php @@ -38,6 +38,14 @@ class Logger self::$verbosity = $verbosity; } + public static function close() + { + if (self::$file !== false) { + fclose(self::$file); + self::$file = false; + } + } + protected static function write(string $level, string $msg, array $args = []) { $caller = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]; diff --git a/index.php b/index.php index 49974f7..bb2adf3 100644 --- a/index.php +++ b/index.php @@ -50,3 +50,4 @@ try { } echo '

⚠ Whoops ! There is a little problem :

', $e->getMessage(), "\n"; } +Wcms\Logger::close(); diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php index eb237ce..5536864 100644 --- a/tests/LoggerTest.php +++ b/tests/LoggerTest.php @@ -388,4 +388,10 @@ class LoggerTest extends FilesTest [4, new Exception('Test 4'), 'Test 4', 0], ]; } + + protected function tearDown(): void + { + parent::tearDown(); + Logger::close(); + } } -- cgit v1.2.3 From 28fb122f56df0cb034013740dd30aaaf5ce9059e Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Sun, 10 May 2020 16:55:04 +0200 Subject: fix: explicitely set PATH in Makefile for MacOS --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 1204a5a..3f15ce4 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ js_src_dir := src # Misc variables. PATH := vendor/bin:node_modules/.bin:$(PATH) +SHELL := PATH=$(PATH) /bin/bash override GIT_VERSION := $(shell git --no-pager describe --always --tags) override CUR_VERSION := $(strip $(shell cat VERSION 2>/dev/null)) override WEBPACK_FLAGS += $(if $(filter $(ENV),dist),-p) -- cgit v1.2.3 From e8b0993f7054299e61af1ab501aaca46285b0caa Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Mon, 11 May 2020 14:25:39 +0200 Subject: fix: tests for Windows --- Makefile | 5 ++++- tests/FilesTest.php | 1 + tests/LoggerTest.php | 28 +++++++++++++++------------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 3f15ce4..e3fc1ad 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,10 @@ js_src_dir := src # Misc variables. PATH := vendor/bin:node_modules/.bin:$(PATH) -SHELL := PATH=$(PATH) /bin/bash + +ifneq ($(OS),Windows_NT) # Not for Windows + SHELL := PATH=$(PATH) /bin/bash +endif override GIT_VERSION := $(shell git --no-pager describe --always --tags) override CUR_VERSION := $(strip $(shell cat VERSION 2>/dev/null)) override WEBPACK_FLAGS += $(if $(filter $(ENV),dist),-p) diff --git a/tests/FilesTest.php b/tests/FilesTest.php index 7ab66fe..83a32d6 100644 --- a/tests/FilesTest.php +++ b/tests/FilesTest.php @@ -12,6 +12,7 @@ use PHPUnit\Framework\TestCase; */ abstract class FilesTest extends TestCase { + protected $ds = DIRECTORY_SEPARATOR; protected $testdir = 'build/test'; protected $notwritabledir = 'build/test/notwritabledir'; protected $notwritablefile = 'build/test/notwritablefile'; diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php index 5536864..c383003 100644 --- a/tests/LoggerTest.php +++ b/tests/LoggerTest.php @@ -48,6 +48,7 @@ class LoggerTest extends FilesTest /** * @test + * @requires OSFAMILY Linux */ public function initDirNotWritableTest(): void { @@ -100,7 +101,7 @@ class LoggerTest extends FilesTest { Logger::init($this->logfile, $verbosity); Logger::error($msg, ...$args); - $expected = " [ ERROR ] tests/LoggerTest.php(102) $expected\n"; + $expected = " [ ERROR ] tests{$this->ds}LoggerTest.php(103) $expected\n"; $this->assertEquals($expected, substr(file_get_contents($this->logfile), 25)); } @@ -138,7 +139,7 @@ class LoggerTest extends FilesTest { Logger::init($this->logfile, $verbosity); Logger::warning($msg, ...$args); - $expected = " [ WARN ] tests/LoggerTest.php(140) $expected\n"; + $expected = " [ WARN ] tests{$this->ds}LoggerTest.php(141) $expected\n"; $this->assertEquals($expected, substr(file_get_contents($this->logfile), 25)); } @@ -175,7 +176,7 @@ class LoggerTest extends FilesTest { Logger::init($this->logfile, $verbosity); Logger::info($msg, ...$args); - $expected = " [ INFO ] tests/LoggerTest.php(177) $expected\n"; + $expected = " [ INFO ] tests{$this->ds}LoggerTest.php(178) $expected\n"; $this->assertEquals($expected, substr(file_get_contents($this->logfile), 25)); } @@ -211,7 +212,7 @@ class LoggerTest extends FilesTest { Logger::init($this->logfile, $verbosity); Logger::debug($msg, ...$args); - $expected = " [ DEBUG ] tests/LoggerTest.php(213) $expected\n"; + $expected = " [ DEBUG ] tests{$this->ds}LoggerTest.php(214) $expected\n"; $this->assertEquals($expected, substr(file_get_contents($this->logfile), 25)); } @@ -247,8 +248,8 @@ class LoggerTest extends FilesTest Logger::init($this->logfile, $verbosity); Logger::errorex($e); $file = __FILE__; - $line += 258; - $expected = " [ ERROR ] tests/LoggerTest.php(248) $expected in $file($line)\n"; + $line += 259; + $expected = " [ ERROR ] tests{$this->ds}LoggerTest.php(249) $expected in $file($line)\n"; $this->assertEquals($expected, substr(file_get_contents($this->logfile), 25)); } @@ -264,13 +265,14 @@ class LoggerTest extends FilesTest /** * @test + * @requires OSFAMILY Linux */ public function errorexBacktraceTest(): void { Logger::init($this->logfile, 1); Logger::errorex(new Exception('Error'), true); $content = file_get_contents($this->logfile); - $expected = " [ ERROR ] tests/LoggerTest.php(271) Error "; + $expected = " [ ERROR ] tests{$this->ds}LoggerTest.php(273) Error "; $this->assertEquals($expected, substr($content, 25, 43)); $this->assertRegExp('/(#\d+ [\w\/\.]*\(\d+\): .*\)\n)+#\d+ \{main\}\n/U', $content); } @@ -300,8 +302,8 @@ class LoggerTest extends FilesTest Logger::init($this->logfile, $verbosity); Logger::warningex($e); $file = __FILE__; - $line += 311; - $expected = " [ WARN ] tests/LoggerTest.php(301) $expected in $file($line)\n"; + $line += 313; + $expected = " [ WARN ] tests{$this->ds}LoggerTest.php(303) $expected in $file($line)\n"; $this->assertEquals($expected, substr(file_get_contents($this->logfile), 25)); } @@ -339,8 +341,8 @@ class LoggerTest extends FilesTest Logger::init($this->logfile, $verbosity); Logger::infoex($e); $file = __FILE__; - $line += 350; - $expected = " [ INFO ] tests/LoggerTest.php(340) $expected in $file($line)\n"; + $line += 352; + $expected = " [ INFO ] tests{$this->ds}LoggerTest.php(342) $expected in $file($line)\n"; $this->assertEquals($expected, substr(file_get_contents($this->logfile), 25)); } @@ -377,8 +379,8 @@ class LoggerTest extends FilesTest Logger::init($this->logfile, $verbosity); Logger::debugex($e); $file = __FILE__; - $line += 388; - $expected = " [ DEBUG ] tests/LoggerTest.php(378) $expected in $file($line)\n"; + $line += 390; + $expected = " [ DEBUG ] tests{$this->ds}LoggerTest.php(380) $expected in $file($line)\n"; $this->assertEquals($expected, substr(file_get_contents($this->logfile), 25)); } -- cgit v1.2.3