From def39d0dd7a81a4af9ad68b62c9e9823fbc2b38e Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 10 Aug 2019 12:31:32 +0200 Subject: Run Unit Tests against PHP 7.4 Bump PHPUnit version and fix unit test - Globals are handled differently and are persistent through tests - Tests without assertions are marked as risky: some of them are just meant to check that no error is raised. --- tests/ApplicationUtilsTest.php | 10 +++++----- tests/PluginManagerTest.php | 3 +-- tests/api/ApiUtilsTest.php | 2 +- tests/config/ConfigPhpTest.php | 4 ++++ tests/feed/CachedPageTest.php | 1 + tests/updater/UpdaterTest.php | 6 ++++++ 6 files changed, 18 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 82f8804d..15388970 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -253,9 +253,9 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase public function testCheckSupportedPHPVersion() { $minVersion = '5.3'; - ApplicationUtils::checkPHPVersion($minVersion, '5.4.32'); - ApplicationUtils::checkPHPVersion($minVersion, '5.5'); - ApplicationUtils::checkPHPVersion($minVersion, '5.6.10'); + $this->assertTrue(ApplicationUtils::checkPHPVersion($minVersion, '5.4.32')); + $this->assertTrue(ApplicationUtils::checkPHPVersion($minVersion, '5.5')); + $this->assertTrue(ApplicationUtils::checkPHPVersion($minVersion, '5.6.10')); } /** @@ -265,7 +265,7 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase */ public function testCheckSupportedPHPVersion51() { - ApplicationUtils::checkPHPVersion('5.3', '5.1.0'); + $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0')); } /** @@ -275,7 +275,7 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase */ public function testCheckSupportedPHPVersion52() { - ApplicationUtils::checkPHPVersion('5.3', '5.2'); + $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2')); } /** diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index 71761ac1..195d959c 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php @@ -58,13 +58,12 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase /** * Test missing plugin loading. - * - * @return void */ public function testPluginNotFound() { $this->pluginManager->load(array()); $this->pluginManager->load(array('nope', 'renope')); + $this->addToAssertionCount(1); } /** diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php index ea0ae500..7499dd71 100644 --- a/tests/api/ApiUtilsTest.php +++ b/tests/api/ApiUtilsTest.php @@ -60,7 +60,7 @@ class ApiUtilsTest extends \PHPUnit\Framework\TestCase public function testValidateJwtTokenValid() { $secret = 'WarIsPeace'; - ApiUtils::validateJwtToken(self::generateValidJwtToken($secret), $secret); + $this->assertTrue(ApiUtils::validateJwtToken(self::generateValidJwtToken($secret), $secret)); } /** diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php index 67d878ce..fb91b51b 100644 --- a/tests/config/ConfigPhpTest.php +++ b/tests/config/ConfigPhpTest.php @@ -3,6 +3,10 @@ namespace Shaarli\Config; /** * Class ConfigPhpTest + * + * We run tests in separate processes due to the usage for $GLOBALS + * which are kept between tests. + * @runTestsInSeparateProcesses */ class ConfigPhpTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php index 0bcc1442..363028a2 100644 --- a/tests/feed/CachedPageTest.php +++ b/tests/feed/CachedPageTest.php @@ -44,6 +44,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase new CachedPage(self::$testCacheDir, '', false); new CachedPage(self::$testCacheDir, 'http://shaar.li/?do=rss', true); new CachedPage(self::$testCacheDir, 'http://shaar.li/?do=atom', false); + $this->addToAssertionCount(1); } /** diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index 93bc86c1..ac87e33c 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -724,6 +724,9 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; */ public function testUpdateMethodWebThumbnailerDisabled() { + if (isset($_SESSION['warnings'])) { + unset($_SESSION['warnings']); + } $this->conf->remove('thumbnails'); $this->conf->set('thumbnail.enable_thumbnails', false); $updater = new Updater([], [], $this->conf, true, $_SESSION); @@ -740,6 +743,9 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; */ public function testUpdateMethodWebThumbnailerNothingToDo() { + if (isset($_SESSION['warnings'])) { + unset($_SESSION['warnings']); + } $updater = new Updater([], [], $this->conf, true, $_SESSION); $this->assertTrue($updater->updateMethodWebThumbnailer()); $this->assertFalse($this->conf->exists('thumbnail')); -- cgit v1.2.3