aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-05-18 17:09:46 +0200
committervincent-peugnet <v.peugnet@free.fr>2020-05-18 17:09:46 +0200
commitbab3d969f6ab1846d818e4ef4d4f777c13575d88 (patch)
treeb8a09d75779f046a774e0b7afd36cfd5f9ca115a
parent121af5f84ad9262e5c509dc1dd741166ca1dc3de (diff)
parentaa6bfe02129d37b75d9684e1d7f89d39412f8d12 (diff)
downloadwcms-bab3d969f6ab1846d818e4ef4d4f777c13575d88.tar.gz
wcms-bab3d969f6ab1846d818e4ef4d4f777c13575d88.zip
Merge branch 'master' of https://github.com/vincent-peugnet/wcms
-rw-r--r--.github/workflows/php.yml17
-rw-r--r--Makefile4
-rw-r--r--app/class/Logger.php8
-rw-r--r--index.php1
-rw-r--r--tests/FilesTest.php1
-rw-r--r--tests/LoggerTest.php34
6 files changed, 47 insertions, 18 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
diff --git a/Makefile b/Makefile
index 1204a5a..e3fc1ad 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,10 @@ js_src_dir := src
# Misc variables.
PATH := vendor/bin:node_modules/.bin:$(PATH)
+
+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/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 '<h1>⚠ Whoops ! There is a little problem : </h1>', $e->getMessage(), "\n";
}
+Wcms\Logger::close();
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 eb237ce..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));
}
@@ -388,4 +390,10 @@ class LoggerTest extends FilesTest
[4, new Exception('Test 4'), 'Test 4', 0],
];
}
+
+ protected function tearDown(): void
+ {
+ parent::tearDown();
+ Logger::close();
+ }
}