aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-09-27 14:07:08 +0200
committerArthurHoaro <arthur@hoa.ro>2020-09-27 14:09:55 +0200
commitb1baca99f280570d0336b4d71ad1f9dca213a35b (patch)
tree518de2057da549d0baa982c6aa689aa813377774
parent8f60e1206e45e67c96a7630d4ff94e72fe875f09 (diff)
downloadShaarli-b1baca99f280570d0336b4d71ad1f9dca213a35b.tar.gz
Shaarli-b1baca99f280570d0336b4d71ad1f9dca213a35b.tar.zst
Shaarli-b1baca99f280570d0336b4d71ad1f9dca213a35b.zip
Convert legacy PHPUnit @expected* to new ->expect*
Converted automatically using https://github.com/ArthurHoaro/convert-legacy-phpunit-expect
-rw-r--r--composer.json2
-rw-r--r--tests/ApplicationUtilsTest.php9
-rw-r--r--tests/FileUtilsTest.php18
-rw-r--r--tests/HistoryTest.php12
-rw-r--r--tests/api/ApiUtilsTest.php72
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php4
-rw-r--r--tests/api/controllers/links/GetLinkIdTest.php6
-rw-r--r--tests/api/controllers/links/PutLinkTest.php6
-rw-r--r--tests/api/controllers/tags/DeleteTagTest.php6
-rw-r--r--tests/api/controllers/tags/GetTagNameTest.php6
-rw-r--r--tests/api/controllers/tags/PutTagTest.php12
-rw-r--r--tests/bookmark/BookmarkArrayTest.php24
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php84
-rw-r--r--tests/bookmark/BookmarkFilterTest.php10
-rw-r--r--tests/config/ConfigJsonTest.php14
-rw-r--r--tests/config/ConfigManagerTest.php22
-rw-r--r--tests/config/ConfigPluginTest.php4
-rw-r--r--tests/legacy/LegacyLinkDBTest.php11
-rw-r--r--tests/legacy/LegacyLinkFilterTest.php10
-rw-r--r--tests/legacy/LegacyUpdaterTest.php10
-rw-r--r--tests/netscape/BookmarkExportTest.php3
-rw-r--r--tests/updater/UpdaterTest.php10
22 files changed, 184 insertions, 171 deletions
diff --git a/composer.json b/composer.json
index 35043fd2..de7b1732 100644
--- a/composer.json
+++ b/composer.json
@@ -28,7 +28,7 @@
28 "require-dev": { 28 "require-dev": {
29 "roave/security-advisories": "dev-master", 29 "roave/security-advisories": "dev-master",
30 "phpunit/phpcov": "*", 30 "phpunit/phpcov": "*",
31 "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0", 31 "phpunit/phpunit": "^7.5 || ^8.0",
32 "squizlabs/php_codesniffer": "3.*" 32 "squizlabs/php_codesniffer": "3.*"
33 }, 33 },
34 "suggest": { 34 "suggest": {
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index 57359196..421d2dd9 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.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 eb9cb89a..6e8f44f2 100644
--- a/tests/FileUtilsTest.php
+++ b/tests/FileUtilsTest.php
@@ -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 e9e61032..fb633e79 100644
--- a/tests/HistoryTest.php
+++ b/tests/HistoryTest.php
@@ -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/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php
index e8075a5d..96787014 100644
--- a/tests/api/ApiUtilsTest.php
+++ b/tests/api/ApiUtilsTest.php
@@ -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/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index 10dfe8bc..bd8403cf 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -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 ee42e259..3a3aaa7b 100644
--- a/tests/api/controllers/links/GetLinkIdTest.php
+++ b/tests/api/controllers/links/GetLinkIdTest.php
@@ -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/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index f582a2b5..3d62a1b1 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -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 b0980572..0d991b85 100644
--- a/tests/api/controllers/tags/DeleteTagTest.php
+++ b/tests/api/controllers/tags/DeleteTagTest.php
@@ -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 f8ee10d9..a2fb89ab 100644
--- a/tests/api/controllers/tags/GetTagNameTest.php
+++ b/tests/api/controllers/tags/GetTagNameTest.php
@@ -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/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php
index e0bc8663..0845dce1 100644
--- a/tests/api/controllers/tags/PutTagTest.php
+++ b/tests/api/controllers/tags/PutTagTest.php
@@ -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 aed4dc76..9cff0fb3 100644
--- a/tests/bookmark/BookmarkFileServiceTest.php
+++ b/tests/bookmark/BookmarkFileServiceTest.php
@@ -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 f1612e9b..f884b0c6 100644
--- a/tests/config/ConfigJsonTest.php
+++ b/tests/config/ConfigJsonTest.php
@@ -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 69456bce..802e6524 100644
--- a/tests/config/ConfigManagerTest.php
+++ b/tests/config/ConfigManagerTest.php
@@ -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/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/legacy/LegacyLinkDBTest.php b/tests/legacy/LegacyLinkDBTest.php
index 92cf607c..819bc272 100644
--- a/tests/legacy/LegacyLinkDBTest.php
+++ b/tests/legacy/LegacyLinkDBTest.php
@@ -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 8223cc15..9db921a9 100644
--- a/tests/legacy/LegacyLinkFilterTest.php
+++ b/tests/legacy/LegacyLinkFilterTest.php
@@ -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 9b693dcb..acfac530 100644
--- a/tests/legacy/LegacyUpdaterTest.php
+++ b/tests/legacy/LegacyUpdaterTest.php
@@ -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',
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index 13b85f3d..a6eacae4 100644
--- a/tests/netscape/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -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/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php
index 277f2fb0..5cfcd5db 100644
--- a/tests/updater/UpdaterTest.php
+++ b/tests/updater/UpdaterTest.php
@@ -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',