aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-09-29 11:36:27 +0200
committerGitHub <noreply@github.com>2020-09-29 11:36:27 +0200
commit6cdca9562c7685e9a0eb77b51584d0cc458c44e0 (patch)
tree518de2057da549d0baa982c6aa689aa813377774 /tests
parentd0ae1ba273b6decea8d35ef79bfabb055b0fb6df (diff)
parentb1baca99f280570d0336b4d71ad1f9dca213a35b (diff)
downloadShaarli-6cdca9562c7685e9a0eb77b51584d0cc458c44e0.tar.gz
Shaarli-6cdca9562c7685e9a0eb77b51584d0cc458c44e0.tar.zst
Shaarli-6cdca9562c7685e9a0eb77b51584d0cc458c44e0.zip
Merge pull request #1572 from ArthurHoaro/feature/php8
Diffstat (limited to 'tests')
-rw-r--r--tests/ApplicationUtilsTest.php13
-rw-r--r--tests/FileUtilsTest.php20
-rw-r--r--tests/HistoryTest.php14
-rw-r--r--tests/LanguagesTest.php2
-rw-r--r--tests/ThumbnailerTest.php4
-rw-r--r--tests/TimeZoneTest.php2
-rw-r--r--tests/UtilsTest.php6
-rw-r--r--tests/api/ApiMiddlewareTest.php4
-rw-r--r--tests/api/ApiUtilsTest.php74
-rw-r--r--tests/api/controllers/history/HistoryTest.php4
-rw-r--r--tests/api/controllers/info/InfoTest.php4
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php8
-rw-r--r--tests/api/controllers/links/GetLinkIdTest.php10
-rw-r--r--tests/api/controllers/links/GetLinksTest.php4
-rw-r--r--tests/api/controllers/links/PostLinkTest.php4
-rw-r--r--tests/api/controllers/links/PutLinkTest.php10
-rw-r--r--tests/api/controllers/tags/DeleteTagTest.php10
-rw-r--r--tests/api/controllers/tags/GetTagNameTest.php10
-rw-r--r--tests/api/controllers/tags/GetTagsTest.php4
-rw-r--r--tests/api/controllers/tags/PutTagTest.php16
-rw-r--r--tests/bookmark/BookmarkArrayTest.php24
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php86
-rw-r--r--tests/bookmark/BookmarkFilterTest.php10
-rw-r--r--tests/config/ConfigJsonTest.php16
-rw-r--r--tests/config/ConfigManagerTest.php24
-rw-r--r--tests/config/ConfigPhpTest.php2
-rw-r--r--tests/config/ConfigPluginTest.php4
-rw-r--r--tests/feed/CachedPageTest.php4
-rw-r--r--tests/formatter/BookmarkDefaultFormatterTest.php2
-rw-r--r--tests/formatter/BookmarkMarkdownFormatterTest.php2
-rw-r--r--tests/formatter/BookmarkRawFormatterTest.php2
-rw-r--r--tests/formatter/FormatterFactoryTest.php2
-rw-r--r--tests/languages/fr/LanguagesFrTest.php4
-rw-r--r--tests/legacy/LegacyLinkDBTest.php13
-rw-r--r--tests/legacy/LegacyLinkFilterTest.php12
-rw-r--r--tests/legacy/LegacyUpdaterTest.php14
-rw-r--r--tests/netscape/BookmarkExportTest.php5
-rw-r--r--tests/netscape/BookmarkImportTest.php8
-rw-r--r--tests/plugins/PluginAddlinkTest.php2
-rw-r--r--tests/plugins/PluginDefaultColorsTest.php4
-rw-r--r--tests/plugins/PluginPlayvideosTest.php2
-rw-r--r--tests/plugins/PluginPubsubhubbubTest.php2
-rw-r--r--tests/plugins/PluginQrcodeTest.php2
-rw-r--r--tests/plugins/PluginWallabagTest.php2
-rw-r--r--tests/plugins/WallabagInstanceTest.php2
-rw-r--r--tests/render/PageCacheManagerTest.php4
-rw-r--r--tests/security/BanManagerTest.php2
-rw-r--r--tests/security/LoginManagerTest.php2
-rw-r--r--tests/security/SessionManagerTest.php4
-rw-r--r--tests/updater/UpdaterTest.php12
50 files changed, 255 insertions, 242 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index 15388970..421d2dd9 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -17,7 +17,7 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
17 /** 17 /**
18 * Reset test data for each test 18 * Reset test data for each test
19 */ 19 */
20 public function setUp() 20 protected function setUp(): void
21 { 21 {
22 FakeApplicationUtils::$VERSION_CODE = ''; 22 FakeApplicationUtils::$VERSION_CODE = '';
23 if (file_exists(self::$testUpdateFile)) { 23 if (file_exists(self::$testUpdateFile)) {
@@ -28,7 +28,7 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
28 /** 28 /**
29 * Remove test version file if it exists 29 * Remove test version file if it exists
30 */ 30 */
31 public function tearDown() 31 protected function tearDown(): void
32 { 32 {
33 if (is_file('sandbox/version.php')) { 33 if (is_file('sandbox/version.php')) {
34 unlink('sandbox/version.php'); 34 unlink('sandbox/version.php');
@@ -145,10 +145,11 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
145 /** 145 /**
146 * Test update checks - invalid Git branch 146 * Test update checks - invalid Git branch
147 * @expectedException Exception 147 * @expectedException Exception
148 * @expectedExceptionMessageRegExp /Invalid branch selected for updates/
149 */ 148 */
150 public function testCheckUpdateInvalidGitBranch() 149 public function testCheckUpdateInvalidGitBranch()
151 { 150 {
151 $this->expectExceptionMessageRegExp('/Invalid branch selected for updates/');
152
152 ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable'); 153 ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable');
153 } 154 }
154 155
@@ -261,20 +262,22 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
261 /** 262 /**
262 * Check a unsupported PHP version 263 * Check a unsupported PHP version
263 * @expectedException Exception 264 * @expectedException Exception
264 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
265 */ 265 */
266 public function testCheckSupportedPHPVersion51() 266 public function testCheckSupportedPHPVersion51()
267 { 267 {
268 $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/');
269
268 $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0')); 270 $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0'));
269 } 271 }
270 272
271 /** 273 /**
272 * Check another unsupported PHP version 274 * Check another unsupported PHP version
273 * @expectedException Exception 275 * @expectedException Exception
274 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
275 */ 276 */
276 public function testCheckSupportedPHPVersion52() 277 public function testCheckSupportedPHPVersion52()
277 { 278 {
279 $this->expectExceptionMessageRegExp('/Your PHP version is obsolete/');
280
278 $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2')); 281 $this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2'));
279 } 282 }
280 283
diff --git a/tests/FileUtilsTest.php b/tests/FileUtilsTest.php
index 57719175..6e8f44f2 100644
--- a/tests/FileUtilsTest.php
+++ b/tests/FileUtilsTest.php
@@ -19,7 +19,7 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
19 /** 19 /**
20 * Delete test file after every test. 20 * Delete test file after every test.
21 */ 21 */
22 public function tearDown() 22 protected function tearDown(): void
23 { 23 {
24 @unlink(self::$file); 24 @unlink(self::$file);
25 } 25 }
@@ -49,12 +49,12 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
49 49
50 /** 50 /**
51 * File not writable: raise an exception. 51 * File not writable: raise an exception.
52 *
53 * @expectedException Shaarli\Exceptions\IOException
54 * @expectedExceptionMessage Error accessing "sandbox/flat.db"
55 */ 52 */
56 public function testWriteWithoutPermission() 53 public function testWriteWithoutPermission()
57 { 54 {
55 $this->expectException(\Shaarli\Exceptions\IOException::class);
56 $this->expectExceptionMessage('Error accessing "sandbox/flat.db"');
57
58 touch(self::$file); 58 touch(self::$file);
59 chmod(self::$file, 0440); 59 chmod(self::$file, 0440);
60 FileUtils::writeFlatDB(self::$file, null); 60 FileUtils::writeFlatDB(self::$file, null);
@@ -62,23 +62,23 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
62 62
63 /** 63 /**
64 * Folder non existent: raise an exception. 64 * Folder non existent: raise an exception.
65 *
66 * @expectedException Shaarli\Exceptions\IOException
67 * @expectedExceptionMessage Error accessing "nopefolder"
68 */ 65 */
69 public function testWriteFolderDoesNotExist() 66 public function testWriteFolderDoesNotExist()
70 { 67 {
68 $this->expectException(\Shaarli\Exceptions\IOException::class);
69 $this->expectExceptionMessage('Error accessing "nopefolder"');
70
71 FileUtils::writeFlatDB('nopefolder/file', null); 71 FileUtils::writeFlatDB('nopefolder/file', null);
72 } 72 }
73 73
74 /** 74 /**
75 * Folder non writable: raise an exception. 75 * Folder non writable: raise an exception.
76 *
77 * @expectedException Shaarli\Exceptions\IOException
78 * @expectedExceptionMessage Error accessing "sandbox"
79 */ 76 */
80 public function testWriteFolderPermission() 77 public function testWriteFolderPermission()
81 { 78 {
79 $this->expectException(\Shaarli\Exceptions\IOException::class);
80 $this->expectExceptionMessage('Error accessing "sandbox"');
81
82 chmod(dirname(self::$file), 0555); 82 chmod(dirname(self::$file), 0555);
83 try { 83 try {
84 FileUtils::writeFlatDB(self::$file, null); 84 FileUtils::writeFlatDB(self::$file, null);
diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php
index 7189c3a9..fb633e79 100644
--- a/tests/HistoryTest.php
+++ b/tests/HistoryTest.php
@@ -16,7 +16,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
16 /** 16 /**
17 * Delete history file. 17 * Delete history file.
18 */ 18 */
19 public function setUp() 19 protected function setUp(): void
20 { 20 {
21 if (file_exists(self::$historyFilePath)) { 21 if (file_exists(self::$historyFilePath)) {
22 unlink(self::$historyFilePath); 22 unlink(self::$historyFilePath);
@@ -44,12 +44,12 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
44 44
45 /** 45 /**
46 * Not writable history file: raise an exception. 46 * Not writable history file: raise an exception.
47 *
48 * @expectedException Exception
49 * @expectedExceptionMessage History file isn't readable or writable
50 */ 47 */
51 public function testConstructNotWritable() 48 public function testConstructNotWritable()
52 { 49 {
50 $this->expectException(\Exception::class);
51 $this->expectExceptionMessage('History file isn\'t readable or writable');
52
53 touch(self::$historyFilePath); 53 touch(self::$historyFilePath);
54 chmod(self::$historyFilePath, 0440); 54 chmod(self::$historyFilePath, 0440);
55 $history = new History(self::$historyFilePath); 55 $history = new History(self::$historyFilePath);
@@ -58,12 +58,12 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
58 58
59 /** 59 /**
60 * Not parsable history file: raise an exception. 60 * Not parsable history file: raise an exception.
61 *
62 * @expectedException Exception
63 * @expectedExceptionMessageRegExp /Could not parse history file/
64 */ 61 */
65 public function testConstructNotParsable() 62 public function testConstructNotParsable()
66 { 63 {
64 $this->expectException(\Exception::class);
65 $this->expectExceptionMessageRegExp('/Could not parse history file/');
66
67 file_put_contents(self::$historyFilePath, 'not parsable'); 67 file_put_contents(self::$historyFilePath, 'not parsable');
68 $history = new History(self::$historyFilePath); 68 $history = new History(self::$historyFilePath);
69 // gzinflate generates a warning 69 // gzinflate generates a warning
diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php
index de83f291..914179c8 100644
--- a/tests/LanguagesTest.php
+++ b/tests/LanguagesTest.php
@@ -22,7 +22,7 @@ class LanguagesTest extends \PHPUnit\Framework\TestCase
22 /** 22 /**
23 * 23 *
24 */ 24 */
25 public function setUp() 25 protected function setUp(): void
26 { 26 {
27 $this->conf = new ConfigManager(self::$configFile); 27 $this->conf = new ConfigManager(self::$configFile);
28 } 28 }
diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php
index c01849f7..5b6d6a4d 100644
--- a/tests/ThumbnailerTest.php
+++ b/tests/ThumbnailerTest.php
@@ -30,7 +30,7 @@ class ThumbnailerTest extends TestCase
30 */ 30 */
31 protected $conf; 31 protected $conf;
32 32
33 public function setUp() 33 protected function setUp(): void
34 { 34 {
35 $this->conf = new ConfigManager('tests/utils/config/configJson'); 35 $this->conf = new ConfigManager('tests/utils/config/configJson');
36 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL); 36 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL);
@@ -43,7 +43,7 @@ class ThumbnailerTest extends TestCase
43 WTConfigManager::addFile('tests/utils/config/wt.json'); 43 WTConfigManager::addFile('tests/utils/config/wt.json');
44 } 44 }
45 45
46 public function tearDown() 46 protected function tearDown(): void
47 { 47 {
48 $this->rrmdirContent('sandbox/'); 48 $this->rrmdirContent('sandbox/');
49 } 49 }
diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php
index 02bf060f..d3d9aeeb 100644
--- a/tests/TimeZoneTest.php
+++ b/tests/TimeZoneTest.php
@@ -15,7 +15,7 @@ class TimeZoneTest extends PHPUnit\Framework\TestCase
15 */ 15 */
16 protected $installedTimezones; 16 protected $installedTimezones;
17 17
18 public function setUp() 18 protected function setUp(): void
19 { 19 {
20 $this->installedTimezones = [ 20 $this->installedTimezones = [
21 'Antarctica/Syowa', 21 'Antarctica/Syowa',
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 26d2a6b8..93b77539 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -26,7 +26,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase
26 /** 26 /**
27 * Assign reference data 27 * Assign reference data
28 */ 28 */
29 public static function setUpBeforeClass() 29 public static function setUpBeforeClass(): void
30 { 30 {
31 self::$defaultTimeZone = date_default_timezone_get(); 31 self::$defaultTimeZone = date_default_timezone_get();
32 // Timezone without DST for test consistency 32 // Timezone without DST for test consistency
@@ -36,7 +36,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase
36 /** 36 /**
37 * Reset the timezone 37 * Reset the timezone
38 */ 38 */
39 public static function tearDownAfterClass() 39 public static function tearDownAfterClass(): void
40 { 40 {
41 date_default_timezone_set(self::$defaultTimeZone); 41 date_default_timezone_set(self::$defaultTimeZone);
42 } 42 }
@@ -44,7 +44,7 @@ class UtilsTest extends PHPUnit\Framework\TestCase
44 /** 44 /**
45 * Resets test data before each test 45 * Resets test data before each test
46 */ 46 */
47 protected function setUp() 47 protected function setUp(): void
48 { 48 {
49 if (file_exists(self::$testLogFile)) { 49 if (file_exists(self::$testLogFile)) {
50 unlink(self::$testLogFile); 50 unlink(self::$testLogFile);
diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php
index df2fb33a..b157e4a7 100644
--- a/tests/api/ApiMiddlewareTest.php
+++ b/tests/api/ApiMiddlewareTest.php
@@ -43,7 +43,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
43 /** 43 /**
44 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 44 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
45 */ 45 */
46 public function setUp() 46 protected function setUp(): void
47 { 47 {
48 $this->conf = new ConfigManager('tests/utils/config/configJson'); 48 $this->conf = new ConfigManager('tests/utils/config/configJson');
49 $this->conf->set('api.secret', 'NapoleonWasALizard'); 49 $this->conf->set('api.secret', 'NapoleonWasALizard');
@@ -61,7 +61,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
61 /** 61 /**
62 * After every test, remove the test datastore. 62 * After every test, remove the test datastore.
63 */ 63 */
64 public function tearDown() 64 protected function tearDown(): void
65 { 65 {
66 @unlink(self::$testDatastore); 66 @unlink(self::$testDatastore);
67 } 67 }
diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php
index 7efec9bb..96787014 100644
--- a/tests/api/ApiUtilsTest.php
+++ b/tests/api/ApiUtilsTest.php
@@ -13,7 +13,7 @@ class ApiUtilsTest extends \PHPUnit\Framework\TestCase
13 /** 13 /**
14 * Force the timezone for ISO datetimes. 14 * Force the timezone for ISO datetimes.
15 */ 15 */
16 public static function setUpBeforeClass() 16 public static function setUpBeforeClass(): void
17 { 17 {
18 date_default_timezone_set('UTC'); 18 date_default_timezone_set('UTC');
19 } 19 }
@@ -66,143 +66,143 @@ class ApiUtilsTest extends \PHPUnit\Framework\TestCase
66 66
67 /** 67 /**
68 * Test validateJwtToken() with a malformed JWT token. 68 * Test validateJwtToken() with a malformed JWT token.
69 *
70 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
71 * @expectedExceptionMessage Malformed JWT token
72 */ 69 */
73 public function testValidateJwtTokenMalformed() 70 public function testValidateJwtTokenMalformed()
74 { 71 {
72 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
73 $this->expectExceptionMessage('Malformed JWT token');
74
75 $token = 'ABC.DEF'; 75 $token = 'ABC.DEF';
76 ApiUtils::validateJwtToken($token, 'foo'); 76 ApiUtils::validateJwtToken($token, 'foo');
77 } 77 }
78 78
79 /** 79 /**
80 * Test validateJwtToken() with an empty JWT token. 80 * Test validateJwtToken() with an empty JWT token.
81 *
82 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
83 * @expectedExceptionMessage Malformed JWT token
84 */ 81 */
85 public function testValidateJwtTokenMalformedEmpty() 82 public function testValidateJwtTokenMalformedEmpty()
86 { 83 {
84 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
85 $this->expectExceptionMessage('Malformed JWT token');
86
87 $token = false; 87 $token = false;
88 ApiUtils::validateJwtToken($token, 'foo'); 88 ApiUtils::validateJwtToken($token, 'foo');
89 } 89 }
90 90
91 /** 91 /**
92 * Test validateJwtToken() with a JWT token without header. 92 * Test validateJwtToken() with a JWT token without header.
93 *
94 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
95 * @expectedExceptionMessage Malformed JWT token
96 */ 93 */
97 public function testValidateJwtTokenMalformedEmptyHeader() 94 public function testValidateJwtTokenMalformedEmptyHeader()
98 { 95 {
96 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
97 $this->expectExceptionMessage('Malformed JWT token');
98
99 $token = '.payload.signature'; 99 $token = '.payload.signature';
100 ApiUtils::validateJwtToken($token, 'foo'); 100 ApiUtils::validateJwtToken($token, 'foo');
101 } 101 }
102 102
103 /** 103 /**
104 * Test validateJwtToken() with a JWT token without payload 104 * Test validateJwtToken() with a JWT token without payload
105 *
106 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
107 * @expectedExceptionMessage Malformed JWT token
108 */ 105 */
109 public function testValidateJwtTokenMalformedEmptyPayload() 106 public function testValidateJwtTokenMalformedEmptyPayload()
110 { 107 {
108 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
109 $this->expectExceptionMessage('Malformed JWT token');
110
111 $token = 'header..signature'; 111 $token = 'header..signature';
112 ApiUtils::validateJwtToken($token, 'foo'); 112 ApiUtils::validateJwtToken($token, 'foo');
113 } 113 }
114 114
115 /** 115 /**
116 * Test validateJwtToken() with a JWT token with an empty signature. 116 * Test validateJwtToken() with a JWT token with an empty signature.
117 *
118 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
119 * @expectedExceptionMessage Invalid JWT signature
120 */ 117 */
121 public function testValidateJwtTokenInvalidSignatureEmpty() 118 public function testValidateJwtTokenInvalidSignatureEmpty()
122 { 119 {
120 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
121 $this->expectExceptionMessage('Invalid JWT signature');
122
123 $token = 'header.payload.'; 123 $token = 'header.payload.';
124 ApiUtils::validateJwtToken($token, 'foo'); 124 ApiUtils::validateJwtToken($token, 'foo');
125 } 125 }
126 126
127 /** 127 /**
128 * Test validateJwtToken() with a JWT token with an invalid signature. 128 * Test validateJwtToken() with a JWT token with an invalid signature.
129 *
130 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
131 * @expectedExceptionMessage Invalid JWT signature
132 */ 129 */
133 public function testValidateJwtTokenInvalidSignature() 130 public function testValidateJwtTokenInvalidSignature()
134 { 131 {
132 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
133 $this->expectExceptionMessage('Invalid JWT signature');
134
135 $token = 'header.payload.nope'; 135 $token = 'header.payload.nope';
136 ApiUtils::validateJwtToken($token, 'foo'); 136 ApiUtils::validateJwtToken($token, 'foo');
137 } 137 }
138 138
139 /** 139 /**
140 * Test validateJwtToken() with a JWT token with a signature generated with the wrong API secret. 140 * Test validateJwtToken() with a JWT token with a signature generated with the wrong API secret.
141 *
142 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
143 * @expectedExceptionMessage Invalid JWT signature
144 */ 141 */
145 public function testValidateJwtTokenInvalidSignatureSecret() 142 public function testValidateJwtTokenInvalidSignatureSecret()
146 { 143 {
144 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
145 $this->expectExceptionMessage('Invalid JWT signature');
146
147 ApiUtils::validateJwtToken(self::generateValidJwtToken('foo'), 'bar'); 147 ApiUtils::validateJwtToken(self::generateValidJwtToken('foo'), 'bar');
148 } 148 }
149 149
150 /** 150 /**
151 * Test validateJwtToken() with a JWT token with a an invalid header (not JSON). 151 * Test validateJwtToken() with a JWT token with a an invalid header (not JSON).
152 *
153 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
154 * @expectedExceptionMessage Invalid JWT header
155 */ 152 */
156 public function testValidateJwtTokenInvalidHeader() 153 public function testValidateJwtTokenInvalidHeader()
157 { 154 {
155 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
156 $this->expectExceptionMessage('Invalid JWT header');
157
158 $token = $this->generateCustomJwtToken('notJSON', '{"JSON":1}', 'secret'); 158 $token = $this->generateCustomJwtToken('notJSON', '{"JSON":1}', 'secret');
159 ApiUtils::validateJwtToken($token, 'secret'); 159 ApiUtils::validateJwtToken($token, 'secret');
160 } 160 }
161 161
162 /** 162 /**
163 * Test validateJwtToken() with a JWT token with a an invalid payload (not JSON). 163 * Test validateJwtToken() with a JWT token with a an invalid payload (not JSON).
164 *
165 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
166 * @expectedExceptionMessage Invalid JWT payload
167 */ 164 */
168 public function testValidateJwtTokenInvalidPayload() 165 public function testValidateJwtTokenInvalidPayload()
169 { 166 {
167 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
168 $this->expectExceptionMessage('Invalid JWT payload');
169
170 $token = $this->generateCustomJwtToken('{"JSON":1}', 'notJSON', 'secret'); 170 $token = $this->generateCustomJwtToken('{"JSON":1}', 'notJSON', 'secret');
171 ApiUtils::validateJwtToken($token, 'secret'); 171 ApiUtils::validateJwtToken($token, 'secret');
172 } 172 }
173 173
174 /** 174 /**
175 * Test validateJwtToken() with a JWT token without issued time. 175 * Test validateJwtToken() with a JWT token without issued time.
176 *
177 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
178 * @expectedExceptionMessage Invalid JWT issued time
179 */ 176 */
180 public function testValidateJwtTokenInvalidTimeEmpty() 177 public function testValidateJwtTokenInvalidTimeEmpty()
181 { 178 {
179 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
180 $this->expectExceptionMessage('Invalid JWT issued time');
181
182 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"JSON":1}', 'secret'); 182 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"JSON":1}', 'secret');
183 ApiUtils::validateJwtToken($token, 'secret'); 183 ApiUtils::validateJwtToken($token, 'secret');
184 } 184 }
185 185
186 /** 186 /**
187 * Test validateJwtToken() with an expired JWT token. 187 * Test validateJwtToken() with an expired JWT token.
188 *
189 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
190 * @expectedExceptionMessage Invalid JWT issued time
191 */ 188 */
192 public function testValidateJwtTokenInvalidTimeExpired() 189 public function testValidateJwtTokenInvalidTimeExpired()
193 { 190 {
191 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
192 $this->expectExceptionMessage('Invalid JWT issued time');
193
194 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() - 600) . '}', 'secret'); 194 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() - 600) . '}', 'secret');
195 ApiUtils::validateJwtToken($token, 'secret'); 195 ApiUtils::validateJwtToken($token, 'secret');
196 } 196 }
197 197
198 /** 198 /**
199 * Test validateJwtToken() with a JWT token issued in the future. 199 * Test validateJwtToken() with a JWT token issued in the future.
200 *
201 * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException
202 * @expectedExceptionMessage Invalid JWT issued time
203 */ 200 */
204 public function testValidateJwtTokenInvalidTimeFuture() 201 public function testValidateJwtTokenInvalidTimeFuture()
205 { 202 {
203 $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class);
204 $this->expectExceptionMessage('Invalid JWT issued time');
205
206 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret'); 206 $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret');
207 ApiUtils::validateJwtToken($token, 'secret'); 207 ApiUtils::validateJwtToken($token, 'secret');
208 } 208 }
diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php
index f4d3b646..40f26b12 100644
--- a/tests/api/controllers/history/HistoryTest.php
+++ b/tests/api/controllers/history/HistoryTest.php
@@ -41,7 +41,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
41 /** 41 /**
42 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 42 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
43 */ 43 */
44 public function setUp() 44 protected function setUp(): void
45 { 45 {
46 $this->conf = new ConfigManager('tests/utils/config/configJson'); 46 $this->conf = new ConfigManager('tests/utils/config/configJson');
47 $this->refHistory = new \ReferenceHistory(); 47 $this->refHistory = new \ReferenceHistory();
@@ -57,7 +57,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
57 /** 57 /**
58 * After every test, remove the test datastore. 58 * After every test, remove the test datastore.
59 */ 59 */
60 public function tearDown() 60 protected function tearDown(): void
61 { 61 {
62 @unlink(self::$testHistory); 62 @unlink(self::$testHistory);
63 } 63 }
diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php
index b5c938e1..cc50d2e3 100644
--- a/tests/api/controllers/info/InfoTest.php
+++ b/tests/api/controllers/info/InfoTest.php
@@ -47,7 +47,7 @@ class InfoTest extends TestCase
47 /** 47 /**
48 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 48 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
49 */ 49 */
50 public function setUp() 50 protected function setUp(): void
51 { 51 {
52 $this->conf = new ConfigManager('tests/utils/config/configJson'); 52 $this->conf = new ConfigManager('tests/utils/config/configJson');
53 $this->conf->set('resource.datastore', self::$testDatastore); 53 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -67,7 +67,7 @@ class InfoTest extends TestCase
67 /** 67 /**
68 * After every test, remove the test datastore. 68 * After every test, remove the test datastore.
69 */ 69 */
70 public function tearDown() 70 protected function tearDown(): void
71 { 71 {
72 @unlink(self::$testDatastore); 72 @unlink(self::$testDatastore);
73 } 73 }
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index 6c2b3698..bd8403cf 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -56,7 +56,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
56 /** 56 /**
57 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 57 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
58 */ 58 */
59 public function setUp() 59 protected function setUp(): void
60 { 60 {
61 $this->conf = new ConfigManager('tests/utils/config/configJson'); 61 $this->conf = new ConfigManager('tests/utils/config/configJson');
62 $this->conf->set('resource.datastore', self::$testDatastore); 62 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -78,7 +78,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
78 /** 78 /**
79 * After each test, remove the test datastore. 79 * After each test, remove the test datastore.
80 */ 80 */
81 public function tearDown() 81 protected function tearDown(): void
82 { 82 {
83 @unlink(self::$testDatastore); 83 @unlink(self::$testDatastore);
84 @unlink(self::$testHistory); 84 @unlink(self::$testHistory);
@@ -113,11 +113,11 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase
113 113
114 /** 114 /**
115 * Test DELETE link endpoint: reach not existing ID. 115 * Test DELETE link endpoint: reach not existing ID.
116 *
117 * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
118 */ 116 */
119 public function testDeleteLink404() 117 public function testDeleteLink404()
120 { 118 {
119 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
120
121 $id = -1; 121 $id = -1;
122 $this->assertFalse($this->bookmarkService->exists($id)); 122 $this->assertFalse($this->bookmarkService->exists($id));
123 $env = Environment::mock([ 123 $env = Environment::mock([
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php
index 8bb81dc8..3a3aaa7b 100644
--- a/tests/api/controllers/links/GetLinkIdTest.php
+++ b/tests/api/controllers/links/GetLinkIdTest.php
@@ -55,7 +55,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
55 /** 55 /**
56 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 56 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
57 */ 57 */
58 public function setUp() 58 protected function setUp(): void
59 { 59 {
60 $this->conf = new ConfigManager('tests/utils/config/configJson'); 60 $this->conf = new ConfigManager('tests/utils/config/configJson');
61 $this->conf->set('resource.datastore', self::$testDatastore); 61 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -74,7 +74,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
74 /** 74 /**
75 * After each test, remove the test datastore. 75 * After each test, remove the test datastore.
76 */ 76 */
77 public function tearDown() 77 protected function tearDown(): void
78 { 78 {
79 @unlink(self::$testDatastore); 79 @unlink(self::$testDatastore);
80 } 80 }
@@ -120,12 +120,12 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase
120 120
121 /** 121 /**
122 * Test basic getLink service: get non existent link => ApiLinkNotFoundException. 122 * Test basic getLink service: get non existent link => ApiLinkNotFoundException.
123 *
124 * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException
125 * @expectedExceptionMessage Link not found
126 */ 123 */
127 public function testGetLink404() 124 public function testGetLink404()
128 { 125 {
126 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
127 $this->expectExceptionMessage('Link not found');
128
129 $env = Environment::mock([ 129 $env = Environment::mock([
130 'REQUEST_METHOD' => 'GET', 130 'REQUEST_METHOD' => 'GET',
131 ]); 131 ]);
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php
index d02e6fad..01c40c2f 100644
--- a/tests/api/controllers/links/GetLinksTest.php
+++ b/tests/api/controllers/links/GetLinksTest.php
@@ -55,7 +55,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
55 /** 55 /**
56 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 56 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
57 */ 57 */
58 public function setUp() 58 protected function setUp(): void
59 { 59 {
60 $this->conf = new ConfigManager('tests/utils/config/configJson'); 60 $this->conf = new ConfigManager('tests/utils/config/configJson');
61 $this->conf->set('resource.datastore', self::$testDatastore); 61 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -74,7 +74,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase
74 /** 74 /**
75 * After every test, remove the test datastore. 75 * After every test, remove the test datastore.
76 */ 76 */
77 public function tearDown() 77 protected function tearDown(): void
78 { 78 {
79 @unlink(self::$testDatastore); 79 @unlink(self::$testDatastore);
80 } 80 }
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php
index 4e791a04..b1c9008b 100644
--- a/tests/api/controllers/links/PostLinkTest.php
+++ b/tests/api/controllers/links/PostLinkTest.php
@@ -70,7 +70,7 @@ class PostLinkTest extends TestCase
70 /** 70 /**
71 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 71 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
72 */ 72 */
73 public function setUp() 73 protected function setUp(): void
74 { 74 {
75 $this->conf = new ConfigManager('tests/utils/config/configJson'); 75 $this->conf = new ConfigManager('tests/utils/config/configJson');
76 $this->conf->set('resource.datastore', self::$testDatastore); 76 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -107,7 +107,7 @@ class PostLinkTest extends TestCase
107 /** 107 /**
108 * After every test, remove the test datastore. 108 * After every test, remove the test datastore.
109 */ 109 */
110 public function tearDown() 110 protected function tearDown(): void
111 { 111 {
112 @unlink(self::$testDatastore); 112 @unlink(self::$testDatastore);
113 @unlink(self::$testHistory); 113 @unlink(self::$testHistory);
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index 302cac0f..3d62a1b1 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -62,7 +62,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase
62 /** 62 /**
63 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 63 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
64 */ 64 */
65 public function setUp() 65 protected function setUp(): void
66 { 66 {
67 $this->conf = new ConfigManager('tests/utils/config/configJson'); 67 $this->conf = new ConfigManager('tests/utils/config/configJson');
68 $this->conf->set('resource.datastore', self::$testDatastore); 68 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -91,7 +91,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase
91 /** 91 /**
92 * After every test, remove the test datastore. 92 * After every test, remove the test datastore.
93 */ 93 */
94 public function tearDown() 94 protected function tearDown(): void
95 { 95 {
96 @unlink(self::$testDatastore); 96 @unlink(self::$testDatastore);
97 @unlink(self::$testHistory); 97 @unlink(self::$testHistory);
@@ -218,12 +218,12 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase
218 218
219 /** 219 /**
220 * Test link update on non existent link => ApiLinkNotFoundException. 220 * Test link update on non existent link => ApiLinkNotFoundException.
221 *
222 * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException
223 * @expectedExceptionMessage Link not found
224 */ 221 */
225 public function testGetLink404() 222 public function testGetLink404()
226 { 223 {
224 $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class);
225 $this->expectExceptionMessage('Link not found');
226
227 $env = Environment::mock([ 227 $env = Environment::mock([
228 'REQUEST_METHOD' => 'PUT', 228 'REQUEST_METHOD' => 'PUT',
229 ]); 229 ]);
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php
index c6748872..0d991b85 100644
--- a/tests/api/controllers/tags/DeleteTagTest.php
+++ b/tests/api/controllers/tags/DeleteTagTest.php
@@ -57,7 +57,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase
57 /** 57 /**
58 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 58 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
59 */ 59 */
60 public function setUp() 60 protected function setUp(): void
61 { 61 {
62 $this->conf = new ConfigManager('tests/utils/config/configJson'); 62 $this->conf = new ConfigManager('tests/utils/config/configJson');
63 $this->conf->set('resource.datastore', self::$testDatastore); 63 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -79,7 +79,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase
79 /** 79 /**
80 * After each test, remove the test datastore. 80 * After each test, remove the test datastore.
81 */ 81 */
82 public function tearDown() 82 protected function tearDown(): void
83 { 83 {
84 @unlink(self::$testDatastore); 84 @unlink(self::$testDatastore);
85 @unlink(self::$testHistory); 85 @unlink(self::$testHistory);
@@ -150,12 +150,12 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase
150 150
151 /** 151 /**
152 * Test DELETE tag endpoint: reach not existing tag. 152 * Test DELETE tag endpoint: reach not existing tag.
153 *
154 * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
155 * @expectedExceptionMessage Tag not found
156 */ 153 */
157 public function testDeleteLink404() 154 public function testDeleteLink404()
158 { 155 {
156 $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
157 $this->expectExceptionMessage('Tag not found');
158
159 $tagName = 'nopenope'; 159 $tagName = 'nopenope';
160 $tags = $this->bookmarkService->bookmarksCountPerTag(); 160 $tags = $this->bookmarkService->bookmarksCountPerTag();
161 $this->assertFalse(isset($tags[$tagName])); 161 $this->assertFalse(isset($tags[$tagName]));
diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php
index b9a81f9b..a2fb89ab 100644
--- a/tests/api/controllers/tags/GetTagNameTest.php
+++ b/tests/api/controllers/tags/GetTagNameTest.php
@@ -53,7 +53,7 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase
53 /** 53 /**
54 * Before each test, instantiate a new Api with its config, plugins and bookmarks. 54 * Before each test, instantiate a new Api with its config, plugins and bookmarks.
55 */ 55 */
56 public function setUp() 56 protected function setUp(): void
57 { 57 {
58 $this->conf = new ConfigManager('tests/utils/config/configJson'); 58 $this->conf = new ConfigManager('tests/utils/config/configJson');
59 $this->conf->set('resource.datastore', self::$testDatastore); 59 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -72,7 +72,7 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase
72 /** 72 /**
73 * After each test, remove the test datastore. 73 * After each test, remove the test datastore.
74 */ 74 */
75 public function tearDown() 75 protected function tearDown(): void
76 { 76 {
77 @unlink(self::$testDatastore); 77 @unlink(self::$testDatastore);
78 } 78 }
@@ -117,12 +117,12 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase
117 117
118 /** 118 /**
119 * Test basic getTag service: get non existent tag => ApiTagNotFoundException. 119 * Test basic getTag service: get non existent tag => ApiTagNotFoundException.
120 *
121 * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
122 * @expectedExceptionMessage Tag not found
123 */ 120 */
124 public function testGetTag404() 121 public function testGetTag404()
125 { 122 {
123 $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
124 $this->expectExceptionMessage('Tag not found');
125
126 $env = Environment::mock([ 126 $env = Environment::mock([
127 'REQUEST_METHOD' => 'GET', 127 'REQUEST_METHOD' => 'GET',
128 ]); 128 ]);
diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php
index 53a3326d..ab666f20 100644
--- a/tests/api/controllers/tags/GetTagsTest.php
+++ b/tests/api/controllers/tags/GetTagsTest.php
@@ -57,7 +57,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase
57 /** 57 /**
58 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 58 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
59 */ 59 */
60 public function setUp() 60 protected function setUp(): void
61 { 61 {
62 $this->conf = new ConfigManager('tests/utils/config/configJson'); 62 $this->conf = new ConfigManager('tests/utils/config/configJson');
63 $this->conf->set('resource.datastore', self::$testDatastore); 63 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -78,7 +78,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase
78 /** 78 /**
79 * After every test, remove the test datastore. 79 * After every test, remove the test datastore.
80 */ 80 */
81 public function tearDown() 81 protected function tearDown(): void
82 { 82 {
83 @unlink(self::$testDatastore); 83 @unlink(self::$testDatastore);
84 } 84 }
diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php
index 2a3cc15a..0845dce1 100644
--- a/tests/api/controllers/tags/PutTagTest.php
+++ b/tests/api/controllers/tags/PutTagTest.php
@@ -62,7 +62,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase
62 /** 62 /**
63 * Before every test, instantiate a new Api with its config, plugins and bookmarks. 63 * Before every test, instantiate a new Api with its config, plugins and bookmarks.
64 */ 64 */
65 public function setUp() 65 protected function setUp(): void
66 { 66 {
67 $this->conf = new ConfigManager('tests/utils/config/configJson'); 67 $this->conf = new ConfigManager('tests/utils/config/configJson');
68 $this->conf->set('resource.datastore', self::$testDatastore); 68 $this->conf->set('resource.datastore', self::$testDatastore);
@@ -84,7 +84,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase
84 /** 84 /**
85 * After every test, remove the test datastore. 85 * After every test, remove the test datastore.
86 */ 86 */
87 public function tearDown() 87 protected function tearDown(): void
88 { 88 {
89 @unlink(self::$testDatastore); 89 @unlink(self::$testDatastore);
90 @unlink(self::$testHistory); 90 @unlink(self::$testHistory);
@@ -159,12 +159,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase
159 159
160 /** 160 /**
161 * Test tag update with an empty new tag name => ApiBadParametersException 161 * Test tag update with an empty new tag name => ApiBadParametersException
162 *
163 * @expectedException Shaarli\Api\Exceptions\ApiBadParametersException
164 * @expectedExceptionMessage New tag name is required in the request body
165 */ 162 */
166 public function testPutTagEmpty() 163 public function testPutTagEmpty()
167 { 164 {
165 $this->expectException(\Shaarli\Api\Exceptions\ApiBadParametersException::class);
166 $this->expectExceptionMessage('New tag name is required in the request body');
167
168 $tagName = 'gnu'; 168 $tagName = 'gnu';
169 $newName = ''; 169 $newName = '';
170 170
@@ -194,12 +194,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase
194 194
195 /** 195 /**
196 * Test tag update on non existent tag => ApiTagNotFoundException. 196 * Test tag update on non existent tag => ApiTagNotFoundException.
197 *
198 * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException
199 * @expectedExceptionMessage Tag not found
200 */ 197 */
201 public function testPutTag404() 198 public function testPutTag404()
202 { 199 {
200 $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class);
201 $this->expectExceptionMessage('Tag not found');
202
203 $env = Environment::mock([ 203 $env = Environment::mock([
204 'REQUEST_METHOD' => 'PUT', 204 'REQUEST_METHOD' => 'PUT',
205 ]); 205 ]);
diff --git a/tests/bookmark/BookmarkArrayTest.php b/tests/bookmark/BookmarkArrayTest.php
index 0f8f04c5..bad3af8d 100644
--- a/tests/bookmark/BookmarkArrayTest.php
+++ b/tests/bookmark/BookmarkArrayTest.php
@@ -47,22 +47,22 @@ class BookmarkArrayTest extends TestCase
47 47
48 /** 48 /**
49 * Test adding a bad entry: wrong type 49 * Test adding a bad entry: wrong type
50 *
51 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
52 */ 50 */
53 public function testArrayAccessAddBadEntryInstance() 51 public function testArrayAccessAddBadEntryInstance()
54 { 52 {
53 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
54
55 $array = new BookmarkArray(); 55 $array = new BookmarkArray();
56 $array[] = 'nope'; 56 $array[] = 'nope';
57 } 57 }
58 58
59 /** 59 /**
60 * Test adding a bad entry: no id 60 * Test adding a bad entry: no id
61 *
62 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
63 */ 61 */
64 public function testArrayAccessAddBadEntryNoId() 62 public function testArrayAccessAddBadEntryNoId()
65 { 63 {
64 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
65
66 $array = new BookmarkArray(); 66 $array = new BookmarkArray();
67 $bookmark = new Bookmark(); 67 $bookmark = new Bookmark();
68 $array[] = $bookmark; 68 $array[] = $bookmark;
@@ -70,11 +70,11 @@ class BookmarkArrayTest extends TestCase
70 70
71 /** 71 /**
72 * Test adding a bad entry: no url 72 * Test adding a bad entry: no url
73 *
74 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
75 */ 73 */
76 public function testArrayAccessAddBadEntryNoUrl() 74 public function testArrayAccessAddBadEntryNoUrl()
77 { 75 {
76 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
77
78 $array = new BookmarkArray(); 78 $array = new BookmarkArray();
79 $bookmark = (new Bookmark())->setId(11); 79 $bookmark = (new Bookmark())->setId(11);
80 $array[] = $bookmark; 80 $array[] = $bookmark;
@@ -82,11 +82,11 @@ class BookmarkArrayTest extends TestCase
82 82
83 /** 83 /**
84 * Test adding a bad entry: invalid offset 84 * Test adding a bad entry: invalid offset
85 *
86 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
87 */ 85 */
88 public function testArrayAccessAddBadEntryOffset() 86 public function testArrayAccessAddBadEntryOffset()
89 { 87 {
88 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
89
90 $array = new BookmarkArray(); 90 $array = new BookmarkArray();
91 $bookmark = (new Bookmark())->setId(11); 91 $bookmark = (new Bookmark())->setId(11);
92 $bookmark->validate(); 92 $bookmark->validate();
@@ -95,11 +95,11 @@ class BookmarkArrayTest extends TestCase
95 95
96 /** 96 /**
97 * Test adding a bad entry: invalid ID type 97 * Test adding a bad entry: invalid ID type
98 *
99 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
100 */ 98 */
101 public function testArrayAccessAddBadEntryIdType() 99 public function testArrayAccessAddBadEntryIdType()
102 { 100 {
101 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
102
103 $array = new BookmarkArray(); 103 $array = new BookmarkArray();
104 $bookmark = (new Bookmark())->setId('nope'); 104 $bookmark = (new Bookmark())->setId('nope');
105 $bookmark->validate(); 105 $bookmark->validate();
@@ -108,11 +108,11 @@ class BookmarkArrayTest extends TestCase
108 108
109 /** 109 /**
110 * Test adding a bad entry: ID/offset not consistent 110 * Test adding a bad entry: ID/offset not consistent
111 *
112 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
113 */ 111 */
114 public function testArrayAccessAddBadEntryIdOffset() 112 public function testArrayAccessAddBadEntryIdOffset()
115 { 113 {
114 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
115
116 $array = new BookmarkArray(); 116 $array = new BookmarkArray();
117 $bookmark = (new Bookmark())->setId(11); 117 $bookmark = (new Bookmark())->setId(11);
118 $bookmark->validate(); 118 $bookmark->validate();
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php
index a4ec1013..9cff0fb3 100644
--- a/tests/bookmark/BookmarkFileServiceTest.php
+++ b/tests/bookmark/BookmarkFileServiceTest.php
@@ -66,7 +66,7 @@ class BookmarkFileServiceTest extends TestCase
66 * 66 *
67 * Resets test data for each test 67 * Resets test data for each test
68 */ 68 */
69 protected function setUp() 69 protected function setUp(): void
70 { 70 {
71 if (file_exists(self::$testDatastore)) { 71 if (file_exists(self::$testDatastore)) {
72 unlink(self::$testDatastore); 72 unlink(self::$testDatastore);
@@ -134,11 +134,11 @@ class BookmarkFileServiceTest extends TestCase
134 134
135 /** 135 /**
136 * Test get() method for an undefined bookmark 136 * Test get() method for an undefined bookmark
137 *
138 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
139 */ 137 */
140 public function testGetUndefined() 138 public function testGetUndefined()
141 { 139 {
140 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
141
142 $this->privateLinkDB->get(666); 142 $this->privateLinkDB->get(666);
143 } 143 }
144 144
@@ -230,13 +230,13 @@ class BookmarkFileServiceTest extends TestCase
230 230
231 /** 231 /**
232 * Test add() method for a bookmark without any field set and without writing the data store 232 * Test add() method for a bookmark without any field set and without writing the data store
233 *
234 * @expectedExceptionMessage Shaarli\Bookmark\Exception\BookmarkNotFoundException
235 */ 233 */
236 public function testAddMinimalNoWrite() 234 public function testAddMinimalNoWrite()
237 { 235 {
236 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
237
238 $bookmark = new Bookmark(); 238 $bookmark = new Bookmark();
239 $this->privateLinkDB->add($bookmark); 239 $this->privateLinkDB->add($bookmark, false);
240 240
241 $bookmark = $this->privateLinkDB->get(43); 241 $bookmark = $this->privateLinkDB->get(43);
242 $this->assertEquals(43, $bookmark->getId()); 242 $this->assertEquals(43, $bookmark->getId());
@@ -249,34 +249,34 @@ class BookmarkFileServiceTest extends TestCase
249 249
250 /** 250 /**
251 * Test add() method while logged out 251 * Test add() method while logged out
252 *
253 * @expectedException \Exception
254 * @expectedExceptionMessage You're not authorized to alter the datastore
255 */ 252 */
256 public function testAddLoggedOut() 253 public function testAddLoggedOut()
257 { 254 {
255 $this->expectException(\Exception::class);
256 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
257
258 $this->publicLinkDB->add(new Bookmark()); 258 $this->publicLinkDB->add(new Bookmark());
259 } 259 }
260 260
261 /** 261 /**
262 * Test add() method with an entry which is not a bookmark instance 262 * Test add() method with an entry which is not a bookmark instance
263 *
264 * @expectedException \Exception
265 * @expectedExceptionMessage Provided data is invalid
266 */ 263 */
267 public function testAddNotABookmark() 264 public function testAddNotABookmark()
268 { 265 {
266 $this->expectException(\Exception::class);
267 $this->expectExceptionMessage('Provided data is invalid');
268
269 $this->privateLinkDB->add(['title' => 'hi!']); 269 $this->privateLinkDB->add(['title' => 'hi!']);
270 } 270 }
271 271
272 /** 272 /**
273 * Test add() method with a Bookmark already containing an ID 273 * Test add() method with a Bookmark already containing an ID
274 *
275 * @expectedException \Exception
276 * @expectedExceptionMessage This bookmarks already exists
277 */ 274 */
278 public function testAddWithId() 275 public function testAddWithId()
279 { 276 {
277 $this->expectException(\Exception::class);
278 $this->expectExceptionMessage('This bookmarks already exists');
279
280 $bookmark = new Bookmark(); 280 $bookmark = new Bookmark();
281 $bookmark->setId(43); 281 $bookmark->setId(43);
282 $this->privateLinkDB->add($bookmark); 282 $this->privateLinkDB->add($bookmark);
@@ -397,44 +397,44 @@ class BookmarkFileServiceTest extends TestCase
397 397
398 /** 398 /**
399 * Test set() method while logged out 399 * Test set() method while logged out
400 *
401 * @expectedException \Exception
402 * @expectedExceptionMessage You're not authorized to alter the datastore
403 */ 400 */
404 public function testSetLoggedOut() 401 public function testSetLoggedOut()
405 { 402 {
403 $this->expectException(\Exception::class);
404 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
405
406 $this->publicLinkDB->set(new Bookmark()); 406 $this->publicLinkDB->set(new Bookmark());
407 } 407 }
408 408
409 /** 409 /**
410 * Test set() method with an entry which is not a bookmark instance 410 * Test set() method with an entry which is not a bookmark instance
411 *
412 * @expectedException \Exception
413 * @expectedExceptionMessage Provided data is invalid
414 */ 411 */
415 public function testSetNotABookmark() 412 public function testSetNotABookmark()
416 { 413 {
414 $this->expectException(\Exception::class);
415 $this->expectExceptionMessage('Provided data is invalid');
416
417 $this->privateLinkDB->set(['title' => 'hi!']); 417 $this->privateLinkDB->set(['title' => 'hi!']);
418 } 418 }
419 419
420 /** 420 /**
421 * Test set() method with a Bookmark without an ID defined. 421 * Test set() method with a Bookmark without an ID defined.
422 *
423 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
424 */ 422 */
425 public function testSetWithoutId() 423 public function testSetWithoutId()
426 { 424 {
425 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
426
427 $bookmark = new Bookmark(); 427 $bookmark = new Bookmark();
428 $this->privateLinkDB->set($bookmark); 428 $this->privateLinkDB->set($bookmark);
429 } 429 }
430 430
431 /** 431 /**
432 * Test set() method with a Bookmark with an unknow ID 432 * Test set() method with a Bookmark with an unknow ID
433 *
434 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
435 */ 433 */
436 public function testSetWithUnknownId() 434 public function testSetWithUnknownId()
437 { 435 {
436 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
437
438 $bookmark = new Bookmark(); 438 $bookmark = new Bookmark();
439 $bookmark->setId(666); 439 $bookmark->setId(666);
440 $this->privateLinkDB->set($bookmark); 440 $this->privateLinkDB->set($bookmark);
@@ -481,23 +481,23 @@ class BookmarkFileServiceTest extends TestCase
481 481
482 /** 482 /**
483 * Test addOrSet() method while logged out 483 * Test addOrSet() method while logged out
484 *
485 * @expectedException \Exception
486 * @expectedExceptionMessage You're not authorized to alter the datastore
487 */ 484 */
488 public function testAddOrSetLoggedOut() 485 public function testAddOrSetLoggedOut()
489 { 486 {
487 $this->expectException(\Exception::class);
488 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
489
490 $this->publicLinkDB->addOrSet(new Bookmark()); 490 $this->publicLinkDB->addOrSet(new Bookmark());
491 } 491 }
492 492
493 /** 493 /**
494 * Test addOrSet() method with an entry which is not a bookmark instance 494 * Test addOrSet() method with an entry which is not a bookmark instance
495 *
496 * @expectedException \Exception
497 * @expectedExceptionMessage Provided data is invalid
498 */ 495 */
499 public function testAddOrSetNotABookmark() 496 public function testAddOrSetNotABookmark()
500 { 497 {
498 $this->expectException(\Exception::class);
499 $this->expectExceptionMessage('Provided data is invalid');
500
501 $this->privateLinkDB->addOrSet(['title' => 'hi!']); 501 $this->privateLinkDB->addOrSet(['title' => 'hi!']);
502 } 502 }
503 503
@@ -524,11 +524,11 @@ class BookmarkFileServiceTest extends TestCase
524 524
525 /** 525 /**
526 * Test remove() method with an existing Bookmark 526 * Test remove() method with an existing Bookmark
527 *
528 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
529 */ 527 */
530 public function testRemoveExisting() 528 public function testRemoveExisting()
531 { 529 {
530 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
531
532 $bookmark = $this->privateLinkDB->get(42); 532 $bookmark = $this->privateLinkDB->get(42);
533 $this->privateLinkDB->remove($bookmark); 533 $this->privateLinkDB->remove($bookmark);
534 534
@@ -548,34 +548,34 @@ class BookmarkFileServiceTest extends TestCase
548 548
549 /** 549 /**
550 * Test remove() method while logged out 550 * Test remove() method while logged out
551 *
552 * @expectedException \Exception
553 * @expectedExceptionMessage You're not authorized to alter the datastore
554 */ 551 */
555 public function testRemoveLoggedOut() 552 public function testRemoveLoggedOut()
556 { 553 {
554 $this->expectException(\Exception::class);
555 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
556
557 $bookmark = $this->privateLinkDB->get(42); 557 $bookmark = $this->privateLinkDB->get(42);
558 $this->publicLinkDB->remove($bookmark); 558 $this->publicLinkDB->remove($bookmark);
559 } 559 }
560 560
561 /** 561 /**
562 * Test remove() method with an entry which is not a bookmark instance 562 * Test remove() method with an entry which is not a bookmark instance
563 *
564 * @expectedException \Exception
565 * @expectedExceptionMessage Provided data is invalid
566 */ 563 */
567 public function testRemoveNotABookmark() 564 public function testRemoveNotABookmark()
568 { 565 {
566 $this->expectException(\Exception::class);
567 $this->expectExceptionMessage('Provided data is invalid');
568
569 $this->privateLinkDB->remove(['title' => 'hi!']); 569 $this->privateLinkDB->remove(['title' => 'hi!']);
570 } 570 }
571 571
572 /** 572 /**
573 * Test remove() method with a Bookmark with an unknown ID 573 * Test remove() method with a Bookmark with an unknown ID
574 *
575 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
576 */ 574 */
577 public function testRemoveWithUnknownId() 575 public function testRemoveWithUnknownId()
578 { 576 {
577 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
578
579 $bookmark = new Bookmark(); 579 $bookmark = new Bookmark();
580 $bookmark->setId(666); 580 $bookmark->setId(666);
581 $this->privateLinkDB->remove($bookmark); 581 $this->privateLinkDB->remove($bookmark);
@@ -635,15 +635,15 @@ class BookmarkFileServiceTest extends TestCase
635 * to make sure that nothing have been broken in the migration process. 635 * to make sure that nothing have been broken in the migration process.
636 * They mostly cover search/filters. Some of them might be redundant with the previous ones. 636 * They mostly cover search/filters. Some of them might be redundant with the previous ones.
637 */ 637 */
638
639 /** 638 /**
640 * Attempt to instantiate a LinkDB whereas the datastore is not writable 639 * Attempt to instantiate a LinkDB whereas the datastore is not writable
641 * 640 *
642 * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException 641 * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException
643 * @expectedExceptionMessageRegExp #Couldn't load data from the data store file "null".*#
644 */ 642 */
645 public function testConstructDatastoreNotWriteable() 643 public function testConstructDatastoreNotWriteable()
646 { 644 {
645 $this->expectExceptionMessageRegExp('#Couldn\'t load data from the data store file "null".*#');
646
647 $conf = new ConfigManager('tests/utils/config/configJson'); 647 $conf = new ConfigManager('tests/utils/config/configJson');
648 $conf->set('resource.datastore', 'null/store.db'); 648 $conf->set('resource.datastore', 'null/store.db');
649 new BookmarkFileService($conf, $this->history, true); 649 new BookmarkFileService($conf, $this->history, true);
diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php
index 91e139c2..752631a5 100644
--- a/tests/bookmark/BookmarkFilterTest.php
+++ b/tests/bookmark/BookmarkFilterTest.php
@@ -213,20 +213,22 @@ class BookmarkFilterTest extends TestCase
213 /** 213 /**
214 * Use an invalid date format 214 * Use an invalid date format
215 * @expectedException Exception 215 * @expectedException Exception
216 * @expectedExceptionMessageRegExp /Invalid date format/
217 */ 216 */
218 public function testFilterInvalidDayWithChars() 217 public function testFilterInvalidDayWithChars()
219 { 218 {
219 $this->expectExceptionMessageRegExp('/Invalid date format/');
220
220 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away'); 221 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away');
221 } 222 }
222 223
223 /** 224 /**
224 * Use an invalid date format 225 * Use an invalid date format
225 * @expectedException Exception 226 * @expectedException Exception
226 * @expectedExceptionMessageRegExp /Invalid date format/
227 */ 227 */
228 public function testFilterInvalidDayDigits() 228 public function testFilterInvalidDayDigits()
229 { 229 {
230 $this->expectExceptionMessageRegExp('/Invalid date format/');
231
230 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20'); 232 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20');
231 } 233 }
232 234
@@ -250,11 +252,11 @@ class BookmarkFilterTest extends TestCase
250 252
251 /** 253 /**
252 * No link for this hash 254 * No link for this hash
253 *
254 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
255 */ 255 */
256 public function testFilterUnknownSmallHash() 256 public function testFilterUnknownSmallHash()
257 { 257 {
258 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
259
258 self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah'); 260 self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah');
259 } 261 }
260 262
diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php
index 33160eb0..f884b0c6 100644
--- a/tests/config/ConfigJsonTest.php
+++ b/tests/config/ConfigJsonTest.php
@@ -11,7 +11,7 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase
11 */ 11 */
12 protected $configIO; 12 protected $configIO;
13 13
14 public function setUp() 14 protected function setUp(): void
15 { 15 {
16 $this->configIO = new ConfigJson(); 16 $this->configIO = new ConfigJson();
17 } 17 }
@@ -38,12 +38,12 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase
38 38
39 /** 39 /**
40 * Read a non existent config file -> empty array. 40 * Read a non existent config file -> empty array.
41 *
42 * @expectedException \Exception
43 * @expectedExceptionMessageRegExp /An error occurred while parsing JSON configuration file \([\w\/\.]+\): error code #4/
44 */ 41 */
45 public function testReadInvalidJson() 42 public function testReadInvalidJson()
46 { 43 {
44 $this->expectException(\Exception::class);
45 $this->expectExceptionMessageRegExp(' /An error occurred while parsing JSON configuration file \\([\\w\\/\\.]+\\): error code #4/');
46
47 $this->configIO->read('tests/utils/config/configInvalid.json.php'); 47 $this->configIO->read('tests/utils/config/configInvalid.json.php');
48 } 48 }
49 49
@@ -110,22 +110,22 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase
110 110
111 /** 111 /**
112 * Write to invalid path. 112 * Write to invalid path.
113 *
114 * @expectedException \Shaarli\Exceptions\IOException
115 */ 113 */
116 public function testWriteInvalidArray() 114 public function testWriteInvalidArray()
117 { 115 {
116 $this->expectException(\Shaarli\Exceptions\IOException::class);
117
118 $conf = array('conf' => 'value'); 118 $conf = array('conf' => 'value');
119 @$this->configIO->write(array(), $conf); 119 @$this->configIO->write(array(), $conf);
120 } 120 }
121 121
122 /** 122 /**
123 * Write to invalid path. 123 * Write to invalid path.
124 *
125 * @expectedException \Shaarli\Exceptions\IOException
126 */ 124 */
127 public function testWriteInvalidBlank() 125 public function testWriteInvalidBlank()
128 { 126 {
127 $this->expectException(\Shaarli\Exceptions\IOException::class);
128
129 $conf = array('conf' => 'value'); 129 $conf = array('conf' => 'value');
130 @$this->configIO->write('', $conf); 130 @$this->configIO->write('', $conf);
131 } 131 }
diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php
index 33830bc9..802e6524 100644
--- a/tests/config/ConfigManagerTest.php
+++ b/tests/config/ConfigManagerTest.php
@@ -14,7 +14,7 @@ class ConfigManagerTest extends \PHPUnit\Framework\TestCase
14 */ 14 */
15 protected $conf; 15 protected $conf;
16 16
17 public function setUp() 17 protected function setUp(): void
18 { 18 {
19 $this->conf = new ConfigManager('tests/utils/config/configJson'); 19 $this->conf = new ConfigManager('tests/utils/config/configJson');
20 } 20 }
@@ -95,44 +95,44 @@ class ConfigManagerTest extends \PHPUnit\Framework\TestCase
95 95
96 /** 96 /**
97 * Set with an empty key. 97 * Set with an empty key.
98 *
99 * @expectedException \Exception
100 * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
101 */ 98 */
102 public function testSetEmptyKey() 99 public function testSetEmptyKey()
103 { 100 {
101 $this->expectException(\Exception::class);
102 $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
103
104 $this->conf->set('', 'stuff'); 104 $this->conf->set('', 'stuff');
105 } 105 }
106 106
107 /** 107 /**
108 * Set with an array key. 108 * Set with an array key.
109 *
110 * @expectedException \Exception
111 * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
112 */ 109 */
113 public function testSetArrayKey() 110 public function testSetArrayKey()
114 { 111 {
112 $this->expectException(\Exception::class);
113 $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
114
115 $this->conf->set(array('foo' => 'bar'), 'stuff'); 115 $this->conf->set(array('foo' => 'bar'), 'stuff');
116 } 116 }
117 117
118 /** 118 /**
119 * Remove with an empty key. 119 * Remove with an empty key.
120 *
121 * @expectedException \Exception
122 * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
123 */ 120 */
124 public function testRmoveEmptyKey() 121 public function testRmoveEmptyKey()
125 { 122 {
123 $this->expectException(\Exception::class);
124 $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
125
126 $this->conf->remove(''); 126 $this->conf->remove('');
127 } 127 }
128 128
129 /** 129 /**
130 * Try to write the config without mandatory parameter (e.g. 'login'). 130 * Try to write the config without mandatory parameter (e.g. 'login').
131 *
132 * @expectedException Shaarli\Config\Exception\MissingFieldConfigException
133 */ 131 */
134 public function testWriteMissingParameter() 132 public function testWriteMissingParameter()
135 { 133 {
134 $this->expectException(\Shaarli\Config\Exception\MissingFieldConfigException::class);
135
136 $this->conf->setConfigFile('tests/utils/config/configTmp'); 136 $this->conf->setConfigFile('tests/utils/config/configTmp');
137 $this->assertFalse(file_exists($this->conf->getConfigFileExt())); 137 $this->assertFalse(file_exists($this->conf->getConfigFileExt()));
138 $this->conf->reload(); 138 $this->conf->reload();
diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php
index fb91b51b..a9aa80f5 100644
--- a/tests/config/ConfigPhpTest.php
+++ b/tests/config/ConfigPhpTest.php
@@ -15,7 +15,7 @@ class ConfigPhpTest extends \PHPUnit\Framework\TestCase
15 */ 15 */
16 protected $configIO; 16 protected $configIO;
17 17
18 public function setUp() 18 protected function setUp(): void
19 { 19 {
20 $this->configIO = new ConfigPhp(); 20 $this->configIO = new ConfigPhp();
21 } 21 }
diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php
index b2cc0045..3a45f623 100644
--- a/tests/config/ConfigPluginTest.php
+++ b/tests/config/ConfigPluginTest.php
@@ -46,11 +46,11 @@ class ConfigPluginTest extends \PHPUnit\Framework\TestCase
46 46
47 /** 47 /**
48 * Test save_plugin_config with invalid data. 48 * Test save_plugin_config with invalid data.
49 *
50 * @expectedException Shaarli\Config\Exception\PluginConfigOrderException
51 */ 49 */
52 public function testSavePluginConfigInvalid() 50 public function testSavePluginConfigInvalid()
53 { 51 {
52 $this->expectException(\Shaarli\Config\Exception\PluginConfigOrderException::class);
53
54 $data = array( 54 $data = array(
55 'plugin2' => 0, 55 'plugin2' => 0,
56 'plugin3' => 0, 56 'plugin3' => 0,
diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php
index 2e716432..25d640d3 100644
--- a/tests/feed/CachedPageTest.php
+++ b/tests/feed/CachedPageTest.php
@@ -17,7 +17,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase
17 /** 17 /**
18 * Create the cache directory if needed 18 * Create the cache directory if needed
19 */ 19 */
20 public static function setUpBeforeClass() 20 public static function setUpBeforeClass(): void
21 { 21 {
22 if (!is_dir(self::$testCacheDir)) { 22 if (!is_dir(self::$testCacheDir)) {
23 mkdir(self::$testCacheDir); 23 mkdir(self::$testCacheDir);
@@ -28,7 +28,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase
28 /** 28 /**
29 * Reset the page cache 29 * Reset the page cache
30 */ 30 */
31 public function setUp() 31 protected function setUp(): void
32 { 32 {
33 if (file_exists(self::$filename)) { 33 if (file_exists(self::$filename)) {
34 unlink(self::$filename); 34 unlink(self::$filename);
diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php
index cf48b00b..9ea86c14 100644
--- a/tests/formatter/BookmarkDefaultFormatterTest.php
+++ b/tests/formatter/BookmarkDefaultFormatterTest.php
@@ -25,7 +25,7 @@ class BookmarkDefaultFormatterTest extends TestCase
25 /** 25 /**
26 * Initialize formatter instance. 26 * Initialize formatter instance.
27 */ 27 */
28 public function setUp() 28 protected function setUp(): void
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php
index 3e72d1ee..a7729416 100644
--- a/tests/formatter/BookmarkMarkdownFormatterTest.php
+++ b/tests/formatter/BookmarkMarkdownFormatterTest.php
@@ -25,7 +25,7 @@ class BookmarkMarkdownFormatterTest extends TestCase
25 /** 25 /**
26 * Initialize formatter instance. 26 * Initialize formatter instance.
27 */ 27 */
28 public function setUp() 28 protected function setUp(): void
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
diff --git a/tests/formatter/BookmarkRawFormatterTest.php b/tests/formatter/BookmarkRawFormatterTest.php
index 4491b035..76cf1172 100644
--- a/tests/formatter/BookmarkRawFormatterTest.php
+++ b/tests/formatter/BookmarkRawFormatterTest.php
@@ -25,7 +25,7 @@ class BookmarkRawFormatterTest extends TestCase
25 /** 25 /**
26 * Initialize formatter instance. 26 * Initialize formatter instance.
27 */ 27 */
28 public function setUp() 28 protected function setUp(): void
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
diff --git a/tests/formatter/FormatterFactoryTest.php b/tests/formatter/FormatterFactoryTest.php
index 5adf3ffd..6aab6a61 100644
--- a/tests/formatter/FormatterFactoryTest.php
+++ b/tests/formatter/FormatterFactoryTest.php
@@ -24,7 +24,7 @@ class FormatterFactoryTest extends TestCase
24 /** 24 /**
25 * Initialize FormatterFactory instance 25 * Initialize FormatterFactory instance
26 */ 26 */
27 public function setUp() 27 protected function setUp(): void
28 { 28 {
29 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 29 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
30 $this->conf = new ConfigManager(self::$testConf); 30 $this->conf = new ConfigManager(self::$testConf);
diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php
index b8b7ca3a..e412b5bc 100644
--- a/tests/languages/fr/LanguagesFrTest.php
+++ b/tests/languages/fr/LanguagesFrTest.php
@@ -27,7 +27,7 @@ class LanguagesFrTest extends \PHPUnit\Framework\TestCase
27 /** 27 /**
28 * Init: force French 28 * Init: force French
29 */ 29 */
30 public function setUp() 30 protected function setUp(): void
31 { 31 {
32 $this->conf = new ConfigManager(self::$configFile); 32 $this->conf = new ConfigManager(self::$configFile);
33 $this->conf->set('translation.language', 'fr'); 33 $this->conf->set('translation.language', 'fr');
@@ -36,7 +36,7 @@ class LanguagesFrTest extends \PHPUnit\Framework\TestCase
36 /** 36 /**
37 * Reset the locale since gettext seems to mess with it, making it too long 37 * Reset the locale since gettext seems to mess with it, making it too long
38 */ 38 */
39 public static function tearDownAfterClass() 39 public static function tearDownAfterClass(): void
40 { 40 {
41 if (! empty(getenv('UT_LOCALE'))) { 41 if (! empty(getenv('UT_LOCALE'))) {
42 setlocale(LC_ALL, getenv('UT_LOCALE')); 42 setlocale(LC_ALL, getenv('UT_LOCALE'));
diff --git a/tests/legacy/LegacyLinkDBTest.php b/tests/legacy/LegacyLinkDBTest.php
index 0884ad03..819bc272 100644
--- a/tests/legacy/LegacyLinkDBTest.php
+++ b/tests/legacy/LegacyLinkDBTest.php
@@ -52,7 +52,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
52 * 52 *
53 * Resets test data for each test 53 * Resets test data for each test
54 */ 54 */
55 protected function setUp() 55 protected function setUp(): void
56 { 56 {
57 if (file_exists(self::$testDatastore)) { 57 if (file_exists(self::$testDatastore)) {
58 unlink(self::$testDatastore); 58 unlink(self::$testDatastore);
@@ -101,10 +101,11 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
101 * Attempt to instantiate a LinkDB whereas the datastore is not writable 101 * Attempt to instantiate a LinkDB whereas the datastore is not writable
102 * 102 *
103 * @expectedException Shaarli\Exceptions\IOException 103 * @expectedException Shaarli\Exceptions\IOException
104 * @expectedExceptionMessageRegExp /Error accessing "null"/
105 */ 104 */
106 public function testConstructDatastoreNotWriteable() 105 public function testConstructDatastoreNotWriteable()
107 { 106 {
107 $this->expectExceptionMessageRegExp('/Error accessing "null"/');
108
108 new LegacyLinkDB('null/store.db', false, false); 109 new LegacyLinkDB('null/store.db', false, false);
109 } 110 }
110 111
@@ -420,22 +421,22 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
420 421
421 /** 422 /**
422 * Test filterHash() with an invalid smallhash. 423 * Test filterHash() with an invalid smallhash.
423 *
424 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
425 */ 424 */
426 public function testFilterHashInValid1() 425 public function testFilterHashInValid1()
427 { 426 {
427 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
428
428 $request = 'blabla'; 429 $request = 'blabla';
429 self::$publicLinkDB->filterHash($request); 430 self::$publicLinkDB->filterHash($request);
430 } 431 }
431 432
432 /** 433 /**
433 * Test filterHash() with an empty smallhash. 434 * Test filterHash() with an empty smallhash.
434 *
435 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
436 */ 435 */
437 public function testFilterHashInValid() 436 public function testFilterHashInValid()
438 { 437 {
438 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
439
439 self::$publicLinkDB->filterHash(''); 440 self::$publicLinkDB->filterHash('');
440 } 441 }
441 442
diff --git a/tests/legacy/LegacyLinkFilterTest.php b/tests/legacy/LegacyLinkFilterTest.php
index ba9ec529..9db921a9 100644
--- a/tests/legacy/LegacyLinkFilterTest.php
+++ b/tests/legacy/LegacyLinkFilterTest.php
@@ -34,7 +34,7 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
34 /** 34 /**
35 * Instantiate linkFilter with ReferenceLinkDB data. 35 * Instantiate linkFilter with ReferenceLinkDB data.
36 */ 36 */
37 public static function setUpBeforeClass() 37 public static function setUpBeforeClass(): void
38 { 38 {
39 self::$refDB = new ReferenceLinkDB(true); 39 self::$refDB = new ReferenceLinkDB(true);
40 self::$refDB->write(self::$testDatastore); 40 self::$refDB->write(self::$testDatastore);
@@ -198,20 +198,22 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
198 /** 198 /**
199 * Use an invalid date format 199 * Use an invalid date format
200 * @expectedException Exception 200 * @expectedException Exception
201 * @expectedExceptionMessageRegExp /Invalid date format/
202 */ 201 */
203 public function testFilterInvalidDayWithChars() 202 public function testFilterInvalidDayWithChars()
204 { 203 {
204 $this->expectExceptionMessageRegExp('/Invalid date format/');
205
205 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, 'Rainy day, dream away'); 206 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, 'Rainy day, dream away');
206 } 207 }
207 208
208 /** 209 /**
209 * Use an invalid date format 210 * Use an invalid date format
210 * @expectedException Exception 211 * @expectedException Exception
211 * @expectedExceptionMessageRegExp /Invalid date format/
212 */ 212 */
213 public function testFilterInvalidDayDigits() 213 public function testFilterInvalidDayDigits()
214 { 214 {
215 $this->expectExceptionMessageRegExp('/Invalid date format/');
216
215 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, '20'); 217 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, '20');
216 } 218 }
217 219
@@ -235,11 +237,11 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
235 237
236 /** 238 /**
237 * No link for this hash 239 * No link for this hash
238 *
239 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
240 */ 240 */
241 public function testFilterUnknownSmallHash() 241 public function testFilterUnknownSmallHash()
242 { 242 {
243 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
244
243 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_HASH, 'Iblaah'); 245 self::$linkFilter->filter(LegacyLinkFilter::$FILTER_HASH, 'Iblaah');
244 } 246 }
245 247
diff --git a/tests/legacy/LegacyUpdaterTest.php b/tests/legacy/LegacyUpdaterTest.php
index 7c429811..acfac530 100644
--- a/tests/legacy/LegacyUpdaterTest.php
+++ b/tests/legacy/LegacyUpdaterTest.php
@@ -40,7 +40,7 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
40 /** 40 /**
41 * Executed before each test. 41 * Executed before each test.
42 */ 42 */
43 public function setUp() 43 protected function setUp(): void
44 { 44 {
45 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); 45 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
46 $this->conf = new ConfigManager(self::$configFile); 46 $this->conf = new ConfigManager(self::$configFile);
@@ -82,10 +82,11 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
82 * Test errors in UpdaterUtils::write_updates_file(): empty updates file. 82 * Test errors in UpdaterUtils::write_updates_file(): empty updates file.
83 * 83 *
84 * @expectedException Exception 84 * @expectedException Exception
85 * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
86 */ 85 */
87 public function testWriteEmptyUpdatesFile() 86 public function testWriteEmptyUpdatesFile()
88 { 87 {
88 $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
89
89 UpdaterUtils::write_updates_file('', array('test')); 90 UpdaterUtils::write_updates_file('', array('test'));
90 } 91 }
91 92
@@ -93,10 +94,11 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
93 * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. 94 * Test errors in UpdaterUtils::write_updates_file(): not writable updates file.
94 * 95 *
95 * @expectedException Exception 96 * @expectedException Exception
96 * @expectedExceptionMessageRegExp /Unable to write(.*)/
97 */ 97 */
98 public function testWriteUpdatesFileNotWritable() 98 public function testWriteUpdatesFileNotWritable()
99 { 99 {
100 $this->expectExceptionMessageRegExp('/Unable to write(.*)/');
101
100 $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; 102 $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
101 touch($updatesFile); 103 touch($updatesFile);
102 chmod($updatesFile, 0444); 104 chmod($updatesFile, 0444);
@@ -161,11 +163,11 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
161 163
162 /** 164 /**
163 * Test Update failed. 165 * Test Update failed.
164 *
165 * @expectedException \Exception
166 */ 166 */
167 public function testUpdateFailed() 167 public function testUpdateFailed()
168 { 168 {
169 $this->expectException(\Exception::class);
170
169 $updates = array( 171 $updates = array(
170 'updateMethodDummy1', 172 'updateMethodDummy1',
171 'updateMethodDummy2', 173 'updateMethodDummy2',
@@ -754,7 +756,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
754 if (isset($_SESSION['warnings'])) { 756 if (isset($_SESSION['warnings'])) {
755 unset($_SESSION['warnings']); 757 unset($_SESSION['warnings']);
756 } 758 }
757 759
758 $updater = new LegacyUpdater([], [], $this->conf, true, $_SESSION); 760 $updater = new LegacyUpdater([], [], $this->conf, true, $_SESSION);
759 $this->assertTrue($updater->updateMethodWebThumbnailer()); 761 $this->assertTrue($updater->updateMethodWebThumbnailer());
760 $this->assertFalse($this->conf->exists('thumbnail')); 762 $this->assertFalse($this->conf->exists('thumbnail'));
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index 509da51d..a6eacae4 100644
--- a/tests/netscape/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -54,7 +54,7 @@ class BookmarkExportTest extends TestCase
54 /** 54 /**
55 * Instantiate reference data 55 * Instantiate reference data
56 */ 56 */
57 public static function setUpBeforeClass() 57 public static function setUpBeforeClass(): void
58 { 58 {
59 static::$conf = new ConfigManager('tests/utils/config/configJson'); 59 static::$conf = new ConfigManager('tests/utils/config/configJson');
60 static::$conf->set('resource.datastore', static::$testDatastore); 60 static::$conf->set('resource.datastore', static::$testDatastore);
@@ -78,10 +78,11 @@ class BookmarkExportTest extends TestCase
78 /** 78 /**
79 * Attempt to export an invalid link selection 79 * Attempt to export an invalid link selection
80 * @expectedException Exception 80 * @expectedException Exception
81 * @expectedExceptionMessageRegExp /Invalid export selection/
82 */ 81 */
83 public function testFilterAndFormatInvalid() 82 public function testFilterAndFormatInvalid()
84 { 83 {
84 $this->expectExceptionMessageRegExp('/Invalid export selection/');
85
85 $this->netscapeBookmarkUtils->filterAndFormat( 86 $this->netscapeBookmarkUtils->filterAndFormat(
86 self::$formatter, 87 self::$formatter,
87 'derp', 88 'derp',
diff --git a/tests/netscape/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php
index f678e26b..89ae4aa7 100644
--- a/tests/netscape/BookmarkImportTest.php
+++ b/tests/netscape/BookmarkImportTest.php
@@ -75,7 +75,7 @@ class BookmarkImportTest extends TestCase
75 */ 75 */
76 protected static $defaultTimeZone; 76 protected static $defaultTimeZone;
77 77
78 public static function setUpBeforeClass() 78 public static function setUpBeforeClass(): void
79 { 79 {
80 self::$defaultTimeZone = date_default_timezone_get(); 80 self::$defaultTimeZone = date_default_timezone_get();
81 // Timezone without DST for test consistency 81 // Timezone without DST for test consistency
@@ -85,7 +85,7 @@ class BookmarkImportTest extends TestCase
85 /** 85 /**
86 * Resets test data before each test 86 * Resets test data before each test
87 */ 87 */
88 protected function setUp() 88 protected function setUp(): void
89 { 89 {
90 if (file_exists(self::$testDatastore)) { 90 if (file_exists(self::$testDatastore)) {
91 unlink(self::$testDatastore); 91 unlink(self::$testDatastore);
@@ -104,12 +104,12 @@ class BookmarkImportTest extends TestCase
104 /** 104 /**
105 * Delete history file. 105 * Delete history file.
106 */ 106 */
107 public function tearDown() 107 protected function tearDown(): void
108 { 108 {
109 @unlink(self::$historyFilePath); 109 @unlink(self::$historyFilePath);
110 } 110 }
111 111
112 public static function tearDownAfterClass() 112 public static function tearDownAfterClass(): void
113 { 113 {
114 date_default_timezone_set(self::$defaultTimeZone); 114 date_default_timezone_set(self::$defaultTimeZone);
115 } 115 }
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
index aa5c6988..1f60d289 100644
--- a/tests/plugins/PluginAddlinkTest.php
+++ b/tests/plugins/PluginAddlinkTest.php
@@ -14,7 +14,7 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
14 /** 14 /**
15 * Reset plugin path. 15 * Reset plugin path.
16 */ 16 */
17 public function setUp() 17 protected function setUp(): void
18 { 18 {
19 PluginManager::$PLUGINS_PATH = 'plugins'; 19 PluginManager::$PLUGINS_PATH = 'plugins';
20 } 20 }
diff --git a/tests/plugins/PluginDefaultColorsTest.php b/tests/plugins/PluginDefaultColorsTest.php
index 9835dfa3..240bb4b2 100644
--- a/tests/plugins/PluginDefaultColorsTest.php
+++ b/tests/plugins/PluginDefaultColorsTest.php
@@ -19,7 +19,7 @@ class PluginDefaultColorsTest extends TestCase
19 /** 19 /**
20 * Reset plugin path 20 * Reset plugin path
21 */ 21 */
22 public function setUp() 22 protected function setUp(): void
23 { 23 {
24 PluginManager::$PLUGINS_PATH = 'sandbox'; 24 PluginManager::$PLUGINS_PATH = 'sandbox';
25 mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/'); 25 mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/');
@@ -32,7 +32,7 @@ class PluginDefaultColorsTest extends TestCase
32 /** 32 /**
33 * Remove sandbox files and folder 33 * Remove sandbox files and folder
34 */ 34 */
35 public function tearDown() 35 protected function tearDown(): void
36 { 36 {
37 if (file_exists('sandbox/default_colors/default_colors.css.template')) { 37 if (file_exists('sandbox/default_colors/default_colors.css.template')) {
38 unlink('sandbox/default_colors/default_colors.css.template'); 38 unlink('sandbox/default_colors/default_colors.css.template');
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php
index b7b6ce53..de1a1aec 100644
--- a/tests/plugins/PluginPlayvideosTest.php
+++ b/tests/plugins/PluginPlayvideosTest.php
@@ -19,7 +19,7 @@ class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase
19 /** 19 /**
20 * Reset plugin path 20 * Reset plugin path
21 */ 21 */
22 public function setUp() 22 protected function setUp(): void
23 { 23 {
24 PluginManager::$PLUGINS_PATH = 'plugins'; 24 PluginManager::$PLUGINS_PATH = 'plugins';
25 } 25 }
diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php
index e66f484e..d30c3703 100644
--- a/tests/plugins/PluginPubsubhubbubTest.php
+++ b/tests/plugins/PluginPubsubhubbubTest.php
@@ -21,7 +21,7 @@ class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase
21 /** 21 /**
22 * Reset plugin path 22 * Reset plugin path
23 */ 23 */
24 public function setUp() 24 protected function setUp(): void
25 { 25 {
26 PluginManager::$PLUGINS_PATH = 'plugins'; 26 PluginManager::$PLUGINS_PATH = 'plugins';
27 } 27 }
diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php
index c9f8c733..bc6be0eb 100644
--- a/tests/plugins/PluginQrcodeTest.php
+++ b/tests/plugins/PluginQrcodeTest.php
@@ -19,7 +19,7 @@ class PluginQrcodeTest extends \PHPUnit\Framework\TestCase
19 /** 19 /**
20 * Reset plugin path 20 * Reset plugin path
21 */ 21 */
22 public function setUp() 22 protected function setUp(): void
23 { 23 {
24 PluginManager::$PLUGINS_PATH = 'plugins'; 24 PluginManager::$PLUGINS_PATH = 'plugins';
25 } 25 }
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
index 79751921..372929ea 100644
--- a/tests/plugins/PluginWallabagTest.php
+++ b/tests/plugins/PluginWallabagTest.php
@@ -15,7 +15,7 @@ class PluginWallabagTest extends \PHPUnit\Framework\TestCase
15 /** 15 /**
16 * Reset plugin path 16 * Reset plugin path
17 */ 17 */
18 public function setUp() 18 protected function setUp(): void
19 { 19 {
20 PluginManager::$PLUGINS_PATH = 'plugins'; 20 PluginManager::$PLUGINS_PATH = 'plugins';
21 } 21 }
diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php
index a3cd9076..4cb0d4cc 100644
--- a/tests/plugins/WallabagInstanceTest.php
+++ b/tests/plugins/WallabagInstanceTest.php
@@ -14,7 +14,7 @@ class WallabagInstanceTest extends \PHPUnit\Framework\TestCase
14 /** 14 /**
15 * Reset plugin path 15 * Reset plugin path
16 */ 16 */
17 public function setUp() 17 protected function setUp(): void
18 { 18 {
19 $this->instance = 'http://some.url'; 19 $this->instance = 'http://some.url';
20 } 20 }
diff --git a/tests/render/PageCacheManagerTest.php b/tests/render/PageCacheManagerTest.php
index c258f45f..4aa7e179 100644
--- a/tests/render/PageCacheManagerTest.php
+++ b/tests/render/PageCacheManagerTest.php
@@ -29,7 +29,7 @@ class PageCacheManagerTest extends TestCase
29 /** 29 /**
30 * Populate the cache with dummy files 30 * Populate the cache with dummy files
31 */ 31 */
32 public function setUp() 32 protected function setUp(): void
33 { 33 {
34 $this->cacheManager = new PageCacheManager(static::$testCacheDir, true); 34 $this->cacheManager = new PageCacheManager(static::$testCacheDir, true);
35 35
@@ -48,7 +48,7 @@ class PageCacheManagerTest extends TestCase
48 /** 48 /**
49 * Remove dummycache folder after each tests. 49 * Remove dummycache folder after each tests.
50 */ 50 */
51 public function tearDown() 51 protected function tearDown(): void
52 { 52 {
53 array_map('unlink', glob(self::$testCacheDir . '/*')); 53 array_map('unlink', glob(self::$testCacheDir . '/*'));
54 rmdir(self::$testCacheDir); 54 rmdir(self::$testCacheDir);
diff --git a/tests/security/BanManagerTest.php b/tests/security/BanManagerTest.php
index bba7c8ad..2fef82f5 100644
--- a/tests/security/BanManagerTest.php
+++ b/tests/security/BanManagerTest.php
@@ -32,7 +32,7 @@ class BanManagerTest extends TestCase
32 /** 32 /**
33 * Prepare or reset test resources 33 * Prepare or reset test resources
34 */ 34 */
35 public function setUp() 35 protected function setUp(): void
36 { 36 {
37 if (file_exists($this->banFile)) { 37 if (file_exists($this->banFile)) {
38 unlink($this->banFile); 38 unlink($this->banFile);
diff --git a/tests/security/LoginManagerTest.php b/tests/security/LoginManagerTest.php
index f242be09..cc9aa647 100644
--- a/tests/security/LoginManagerTest.php
+++ b/tests/security/LoginManagerTest.php
@@ -63,7 +63,7 @@ class LoginManagerTest extends TestCase
63 /** 63 /**
64 * Prepare or reset test resources 64 * Prepare or reset test resources
65 */ 65 */
66 public function setUp() 66 protected function setUp(): void
67 { 67 {
68 if (file_exists($this->banFile)) { 68 if (file_exists($this->banFile)) {
69 unlink($this->banFile); 69 unlink($this->banFile);
diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php
index 11a59f9c..27e3b1a9 100644
--- a/tests/security/SessionManagerTest.php
+++ b/tests/security/SessionManagerTest.php
@@ -24,7 +24,7 @@ class SessionManagerTest extends TestCase
24 /** 24 /**
25 * Assign reference data 25 * Assign reference data
26 */ 26 */
27 public static function setUpBeforeClass() 27 public static function setUpBeforeClass(): void
28 { 28 {
29 self::$sidHashes = \ReferenceSessionIdHashes::getHashes(); 29 self::$sidHashes = \ReferenceSessionIdHashes::getHashes();
30 } 30 }
@@ -32,7 +32,7 @@ class SessionManagerTest extends TestCase
32 /** 32 /**
33 * Initialize or reset test resources 33 * Initialize or reset test resources
34 */ 34 */
35 public function setUp() 35 protected function setUp(): void
36 { 36 {
37 $this->conf = new \FakeConfigManager([ 37 $this->conf = new \FakeConfigManager([
38 'credentials.login' => 'johndoe', 38 'credentials.login' => 'johndoe',
diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php
index a7dd70bf..5cfcd5db 100644
--- a/tests/updater/UpdaterTest.php
+++ b/tests/updater/UpdaterTest.php
@@ -42,7 +42,7 @@ class UpdaterTest extends TestCase
42 /** 42 /**
43 * Executed before each test. 43 * Executed before each test.
44 */ 44 */
45 public function setUp() 45 protected function setUp(): void
46 { 46 {
47 $this->refDB = new \ReferenceLinkDB(); 47 $this->refDB = new \ReferenceLinkDB();
48 $this->refDB->write(self::$testDatastore); 48 $this->refDB->write(self::$testDatastore);
@@ -89,10 +89,11 @@ class UpdaterTest extends TestCase
89 * Test errors in UpdaterUtils::write_updates_file(): empty updates file. 89 * Test errors in UpdaterUtils::write_updates_file(): empty updates file.
90 * 90 *
91 * @expectedException Exception 91 * @expectedException Exception
92 * @expectedExceptionMessageRegExp /Updates file path is not set(.*)/
93 */ 92 */
94 public function testWriteEmptyUpdatesFile() 93 public function testWriteEmptyUpdatesFile()
95 { 94 {
95 $this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
96
96 UpdaterUtils::write_updates_file('', array('test')); 97 UpdaterUtils::write_updates_file('', array('test'));
97 } 98 }
98 99
@@ -100,10 +101,11 @@ class UpdaterTest extends TestCase
100 * Test errors in UpdaterUtils::write_updates_file(): not writable updates file. 101 * Test errors in UpdaterUtils::write_updates_file(): not writable updates file.
101 * 102 *
102 * @expectedException Exception 103 * @expectedException Exception
103 * @expectedExceptionMessageRegExp /Unable to write(.*)/
104 */ 104 */
105 public function testWriteUpdatesFileNotWritable() 105 public function testWriteUpdatesFileNotWritable()
106 { 106 {
107 $this->expectExceptionMessageRegExp('/Unable to write(.*)/');
108
107 $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt'; 109 $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
108 touch($updatesFile); 110 touch($updatesFile);
109 chmod($updatesFile, 0444); 111 chmod($updatesFile, 0444);
@@ -168,11 +170,11 @@ class UpdaterTest extends TestCase
168 170
169 /** 171 /**
170 * Test Update failed. 172 * Test Update failed.
171 *
172 * @expectedException \Exception
173 */ 173 */
174 public function testUpdateFailed() 174 public function testUpdateFailed()
175 { 175 {
176 $this->expectException(\Exception::class);
177
176 $updates = array( 178 $updates = array(
177 'updateMethodDummy1', 179 'updateMethodDummy1',
178 'updateMethodDummy2', 180 'updateMethodDummy2',