diff options
Diffstat (limited to 'tests/api')
-rw-r--r-- | tests/api/ApiMiddlewareTest.php | 65 | ||||
-rw-r--r-- | tests/api/ApiUtilsTest.php | 76 | ||||
-rw-r--r-- | tests/api/controllers/history/HistoryTest.php | 6 | ||||
-rw-r--r-- | tests/api/controllers/info/InfoTest.php | 10 | ||||
-rw-r--r-- | tests/api/controllers/links/DeleteLinkTest.php | 19 | ||||
-rw-r--r-- | tests/api/controllers/links/GetLinkIdTest.php | 18 | ||||
-rw-r--r-- | tests/api/controllers/links/GetLinksTest.php | 14 | ||||
-rw-r--r-- | tests/api/controllers/links/PostLinkTest.php | 22 | ||||
-rw-r--r-- | tests/api/controllers/links/PutLinkTest.php | 20 | ||||
-rw-r--r-- | tests/api/controllers/tags/DeleteTagTest.php | 23 | ||||
-rw-r--r-- | tests/api/controllers/tags/GetTagNameTest.php | 16 | ||||
-rw-r--r-- | tests/api/controllers/tags/GetTagsTest.php | 10 | ||||
-rw-r--r-- | tests/api/controllers/tags/PutTagTest.php | 22 |
13 files changed, 197 insertions, 124 deletions
diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php index df2fb33a..86700840 100644 --- a/tests/api/ApiMiddlewareTest.php +++ b/tests/api/ApiMiddlewareTest.php | |||
@@ -18,7 +18,7 @@ use Slim\Http\Response; | |||
18 | * | 18 | * |
19 | * @package Api | 19 | * @package Api |
20 | */ | 20 | */ |
21 | class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase | 21 | class ApiMiddlewareTest extends \Shaarli\TestCase |
22 | { | 22 | { |
23 | /** | 23 | /** |
24 | * @var string datastore to test write operations | 24 | * @var string datastore to test write operations |
@@ -26,7 +26,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase | |||
26 | protected static $testDatastore = 'sandbox/datastore.php'; | 26 | protected static $testDatastore = 'sandbox/datastore.php'; |
27 | 27 | ||
28 | /** | 28 | /** |
29 | * @var \ConfigManager instance | 29 | * @var ConfigManager instance |
30 | */ | 30 | */ |
31 | protected $conf; | 31 | protected $conf; |
32 | 32 | ||
@@ -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,12 +61,59 @@ 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 | } |
68 | 68 | ||
69 | /** | 69 | /** |
70 | * Invoke the middleware with a valid token | ||
71 | */ | ||
72 | public function testInvokeMiddlewareWithValidToken(): void | ||
73 | { | ||
74 | $next = function (Request $request, Response $response): Response { | ||
75 | return $response; | ||
76 | }; | ||
77 | $mw = new ApiMiddleware($this->container); | ||
78 | $env = Environment::mock([ | ||
79 | 'REQUEST_METHOD' => 'GET', | ||
80 | 'REQUEST_URI' => '/echo', | ||
81 | 'HTTP_AUTHORIZATION'=> 'Bearer ' . ApiUtilsTest::generateValidJwtToken('NapoleonWasALizard'), | ||
82 | ]); | ||
83 | $request = Request::createFromEnvironment($env); | ||
84 | $response = new Response(); | ||
85 | /** @var Response $response */ | ||
86 | $response = $mw($request, $response, $next); | ||
87 | |||
88 | $this->assertEquals(200, $response->getStatusCode()); | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Invoke the middleware with a valid token | ||
93 | * Using specific Apache CGI redirected authorization. | ||
94 | */ | ||
95 | public function testInvokeMiddlewareWithValidTokenFromRedirectedHeader(): void | ||
96 | { | ||
97 | $next = function (Request $request, Response $response): Response { | ||
98 | return $response; | ||
99 | }; | ||
100 | |||
101 | $token = 'Bearer ' . ApiUtilsTest::generateValidJwtToken('NapoleonWasALizard'); | ||
102 | $this->container->environment['REDIRECT_HTTP_AUTHORIZATION'] = $token; | ||
103 | $mw = new ApiMiddleware($this->container); | ||
104 | $env = Environment::mock([ | ||
105 | 'REQUEST_METHOD' => 'GET', | ||
106 | 'REQUEST_URI' => '/echo', | ||
107 | ]); | ||
108 | $request = Request::createFromEnvironment($env); | ||
109 | $response = new Response(); | ||
110 | /** @var Response $response */ | ||
111 | $response = $mw($request, $response, $next); | ||
112 | |||
113 | $this->assertEquals(200, $response->getStatusCode()); | ||
114 | } | ||
115 | |||
116 | /** | ||
70 | * Invoke the middleware with the API disabled: | 117 | * Invoke the middleware with the API disabled: |
71 | * should return a 401 error Unauthorized. | 118 | * should return a 401 error Unauthorized. |
72 | */ | 119 | */ |
@@ -109,7 +156,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase | |||
109 | $this->assertEquals(401, $response->getStatusCode()); | 156 | $this->assertEquals(401, $response->getStatusCode()); |
110 | $body = json_decode((string) $response->getBody()); | 157 | $body = json_decode((string) $response->getBody()); |
111 | $this->assertEquals('Not authorized: API is disabled', $body->message); | 158 | $this->assertEquals('Not authorized: API is disabled', $body->message); |
112 | $this->assertContains('ApiAuthorizationException', $body->stacktrace); | 159 | $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); |
113 | } | 160 | } |
114 | 161 | ||
115 | /** | 162 | /** |
@@ -132,7 +179,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase | |||
132 | $this->assertEquals(401, $response->getStatusCode()); | 179 | $this->assertEquals(401, $response->getStatusCode()); |
133 | $body = json_decode((string) $response->getBody()); | 180 | $body = json_decode((string) $response->getBody()); |
134 | $this->assertEquals('Not authorized: JWT token not provided', $body->message); | 181 | $this->assertEquals('Not authorized: JWT token not provided', $body->message); |
135 | $this->assertContains('ApiAuthorizationException', $body->stacktrace); | 182 | $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); |
136 | } | 183 | } |
137 | 184 | ||
138 | /** | 185 | /** |
@@ -157,7 +204,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase | |||
157 | $this->assertEquals(401, $response->getStatusCode()); | 204 | $this->assertEquals(401, $response->getStatusCode()); |
158 | $body = json_decode((string) $response->getBody()); | 205 | $body = json_decode((string) $response->getBody()); |
159 | $this->assertEquals('Not authorized: Token secret must be set in Shaarli\'s administration', $body->message); | 206 | $this->assertEquals('Not authorized: Token secret must be set in Shaarli\'s administration', $body->message); |
160 | $this->assertContains('ApiAuthorizationException', $body->stacktrace); | 207 | $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); |
161 | } | 208 | } |
162 | 209 | ||
163 | /** | 210 | /** |
@@ -180,7 +227,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase | |||
180 | $this->assertEquals(401, $response->getStatusCode()); | 227 | $this->assertEquals(401, $response->getStatusCode()); |
181 | $body = json_decode((string) $response->getBody()); | 228 | $body = json_decode((string) $response->getBody()); |
182 | $this->assertEquals('Not authorized: Invalid JWT header', $body->message); | 229 | $this->assertEquals('Not authorized: Invalid JWT header', $body->message); |
183 | $this->assertContains('ApiAuthorizationException', $body->stacktrace); | 230 | $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); |
184 | } | 231 | } |
185 | 232 | ||
186 | /** | 233 | /** |
@@ -206,6 +253,6 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase | |||
206 | $this->assertEquals(401, $response->getStatusCode()); | 253 | $this->assertEquals(401, $response->getStatusCode()); |
207 | $body = json_decode((string) $response->getBody()); | 254 | $body = json_decode((string) $response->getBody()); |
208 | $this->assertEquals('Not authorized: Malformed JWT token', $body->message); | 255 | $this->assertEquals('Not authorized: Malformed JWT token', $body->message); |
209 | $this->assertContains('ApiAuthorizationException', $body->stacktrace); | 256 | $this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace); |
210 | } | 257 | } |
211 | } | 258 | } |
diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php index 7efec9bb..7a143859 100644 --- a/tests/api/ApiUtilsTest.php +++ b/tests/api/ApiUtilsTest.php | |||
@@ -8,12 +8,12 @@ use Shaarli\Http\Base64Url; | |||
8 | /** | 8 | /** |
9 | * Class ApiUtilsTest | 9 | * Class ApiUtilsTest |
10 | */ | 10 | */ |
11 | class ApiUtilsTest extends \PHPUnit\Framework\TestCase | 11 | class ApiUtilsTest extends \Shaarli\TestCase |
12 | { | 12 | { |
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..84f8716e 100644 --- a/tests/api/controllers/history/HistoryTest.php +++ b/tests/api/controllers/history/HistoryTest.php | |||
@@ -11,7 +11,7 @@ use Slim\Http\Response; | |||
11 | 11 | ||
12 | require_once 'tests/utils/ReferenceHistory.php'; | 12 | require_once 'tests/utils/ReferenceHistory.php'; |
13 | 13 | ||
14 | class HistoryTest extends \PHPUnit\Framework\TestCase | 14 | class HistoryTest extends \Shaarli\TestCase |
15 | { | 15 | { |
16 | /** | 16 | /** |
17 | * @var string datastore to test write operations | 17 | * @var string datastore to test write operations |
@@ -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..10b29ab2 100644 --- a/tests/api/controllers/info/InfoTest.php +++ b/tests/api/controllers/info/InfoTest.php | |||
@@ -1,10 +1,11 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Api\Controllers; | 2 | namespace Shaarli\Api\Controllers; |
3 | 3 | ||
4 | use PHPUnit\Framework\TestCase; | 4 | use malkusch\lock\mutex\NoMutex; |
5 | use Shaarli\Bookmark\BookmarkFileService; | 5 | use Shaarli\Bookmark\BookmarkFileService; |
6 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | 7 | use Shaarli\History; |
8 | use Shaarli\TestCase; | ||
8 | use Slim\Container; | 9 | use Slim\Container; |
9 | use Slim\Http\Environment; | 10 | use Slim\Http\Environment; |
10 | use Slim\Http\Request; | 11 | use Slim\Http\Request; |
@@ -47,8 +48,9 @@ class InfoTest extends TestCase | |||
47 | /** | 48 | /** |
48 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. | 49 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. |
49 | */ | 50 | */ |
50 | public function setUp() | 51 | protected function setUp(): void |
51 | { | 52 | { |
53 | $mutex = new NoMutex(); | ||
52 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 54 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
53 | $this->conf->set('resource.datastore', self::$testDatastore); | 55 | $this->conf->set('resource.datastore', self::$testDatastore); |
54 | $this->refDB = new \ReferenceLinkDB(); | 56 | $this->refDB = new \ReferenceLinkDB(); |
@@ -58,7 +60,7 @@ class InfoTest extends TestCase | |||
58 | 60 | ||
59 | $this->container = new Container(); | 61 | $this->container = new Container(); |
60 | $this->container['conf'] = $this->conf; | 62 | $this->container['conf'] = $this->conf; |
61 | $this->container['db'] = new BookmarkFileService($this->conf, $history, true); | 63 | $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true); |
62 | $this->container['history'] = null; | 64 | $this->container['history'] = null; |
63 | 65 | ||
64 | $this->controller = new Info($this->container); | 66 | $this->controller = new Info($this->container); |
@@ -67,7 +69,7 @@ class InfoTest extends TestCase | |||
67 | /** | 69 | /** |
68 | * After every test, remove the test datastore. | 70 | * After every test, remove the test datastore. |
69 | */ | 71 | */ |
70 | public function tearDown() | 72 | protected function tearDown(): void |
71 | { | 73 | { |
72 | @unlink(self::$testDatastore); | 74 | @unlink(self::$testDatastore); |
73 | } | 75 | } |
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php index 6c2b3698..805c9be3 100644 --- a/tests/api/controllers/links/DeleteLinkTest.php +++ b/tests/api/controllers/links/DeleteLinkTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use malkusch\lock\mutex\NoMutex; | ||
6 | use Shaarli\Bookmark\BookmarkFileService; | 7 | use Shaarli\Bookmark\BookmarkFileService; |
7 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | 9 | use Shaarli\History; |
@@ -11,7 +12,7 @@ use Slim\Http\Environment; | |||
11 | use Slim\Http\Request; | 12 | use Slim\Http\Request; |
12 | use Slim\Http\Response; | 13 | use Slim\Http\Response; |
13 | 14 | ||
14 | class DeleteLinkTest extends \PHPUnit\Framework\TestCase | 15 | class DeleteLinkTest extends \Shaarli\TestCase |
15 | { | 16 | { |
16 | /** | 17 | /** |
17 | * @var string datastore to test write operations | 18 | * @var string datastore to test write operations |
@@ -53,11 +54,15 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
53 | */ | 54 | */ |
54 | protected $controller; | 55 | protected $controller; |
55 | 56 | ||
57 | /** @var NoMutex */ | ||
58 | protected $mutex; | ||
59 | |||
56 | /** | 60 | /** |
57 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. | 61 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. |
58 | */ | 62 | */ |
59 | public function setUp() | 63 | protected function setUp(): void |
60 | { | 64 | { |
65 | $this->mutex = new NoMutex(); | ||
61 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 66 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
62 | $this->conf->set('resource.datastore', self::$testDatastore); | 67 | $this->conf->set('resource.datastore', self::$testDatastore); |
63 | $this->refDB = new \ReferenceLinkDB(); | 68 | $this->refDB = new \ReferenceLinkDB(); |
@@ -65,7 +70,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
65 | $refHistory = new \ReferenceHistory(); | 70 | $refHistory = new \ReferenceHistory(); |
66 | $refHistory->write(self::$testHistory); | 71 | $refHistory->write(self::$testHistory); |
67 | $this->history = new History(self::$testHistory); | 72 | $this->history = new History(self::$testHistory); |
68 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 73 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
69 | 74 | ||
70 | $this->container = new Container(); | 75 | $this->container = new Container(); |
71 | $this->container['conf'] = $this->conf; | 76 | $this->container['conf'] = $this->conf; |
@@ -78,7 +83,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
78 | /** | 83 | /** |
79 | * After each test, remove the test datastore. | 84 | * After each test, remove the test datastore. |
80 | */ | 85 | */ |
81 | public function tearDown() | 86 | protected function tearDown(): void |
82 | { | 87 | { |
83 | @unlink(self::$testDatastore); | 88 | @unlink(self::$testDatastore); |
84 | @unlink(self::$testHistory); | 89 | @unlink(self::$testHistory); |
@@ -100,7 +105,7 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
100 | $this->assertEquals(204, $response->getStatusCode()); | 105 | $this->assertEquals(204, $response->getStatusCode()); |
101 | $this->assertEmpty((string) $response->getBody()); | 106 | $this->assertEmpty((string) $response->getBody()); |
102 | 107 | ||
103 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 108 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
104 | $this->assertFalse($this->bookmarkService->exists($id)); | 109 | $this->assertFalse($this->bookmarkService->exists($id)); |
105 | 110 | ||
106 | $historyEntry = $this->history->getHistory()[0]; | 111 | $historyEntry = $this->history->getHistory()[0]; |
@@ -113,11 +118,11 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase | |||
113 | 118 | ||
114 | /** | 119 | /** |
115 | * Test DELETE link endpoint: reach not existing ID. | 120 | * Test DELETE link endpoint: reach not existing ID. |
116 | * | ||
117 | * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException | ||
118 | */ | 121 | */ |
119 | public function testDeleteLink404() | 122 | public function testDeleteLink404() |
120 | { | 123 | { |
124 | $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); | ||
125 | |||
121 | $id = -1; | 126 | $id = -1; |
122 | $this->assertFalse($this->bookmarkService->exists($id)); | 127 | $this->assertFalse($this->bookmarkService->exists($id)); |
123 | $env = Environment::mock([ | 128 | $env = Environment::mock([ |
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index c26411ac..1ec56ef3 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use malkusch\lock\mutex\NoMutex; | ||
5 | use Shaarli\Bookmark\Bookmark; | 6 | use Shaarli\Bookmark\Bookmark; |
6 | use Shaarli\Bookmark\BookmarkFileService; | 7 | use Shaarli\Bookmark\BookmarkFileService; |
7 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
@@ -20,7 +21,7 @@ use Slim\Http\Response; | |||
20 | * | 21 | * |
21 | * @package Shaarli\Api\Controllers | 22 | * @package Shaarli\Api\Controllers |
22 | */ | 23 | */ |
23 | class GetLinkIdTest extends \PHPUnit\Framework\TestCase | 24 | class GetLinkIdTest extends \Shaarli\TestCase |
24 | { | 25 | { |
25 | /** | 26 | /** |
26 | * @var string datastore to test write operations | 27 | * @var string datastore to test write operations |
@@ -55,8 +56,9 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
55 | /** | 56 | /** |
56 | * 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. |
57 | */ | 58 | */ |
58 | public function setUp() | 59 | protected function setUp(): void |
59 | { | 60 | { |
61 | $mutex = new NoMutex(); | ||
60 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 62 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
61 | $this->conf->set('resource.datastore', self::$testDatastore); | 63 | $this->conf->set('resource.datastore', self::$testDatastore); |
62 | $this->refDB = new \ReferenceLinkDB(); | 64 | $this->refDB = new \ReferenceLinkDB(); |
@@ -65,7 +67,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
65 | 67 | ||
66 | $this->container = new Container(); | 68 | $this->container = new Container(); |
67 | $this->container['conf'] = $this->conf; | 69 | $this->container['conf'] = $this->conf; |
68 | $this->container['db'] = new BookmarkFileService($this->conf, $history, true); | 70 | $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true); |
69 | $this->container['history'] = null; | 71 | $this->container['history'] = null; |
70 | 72 | ||
71 | $this->controller = new Links($this->container); | 73 | $this->controller = new Links($this->container); |
@@ -74,7 +76,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
74 | /** | 76 | /** |
75 | * After each test, remove the test datastore. | 77 | * After each test, remove the test datastore. |
76 | */ | 78 | */ |
77 | public function tearDown() | 79 | protected function tearDown(): void |
78 | { | 80 | { |
79 | @unlink(self::$testDatastore); | 81 | @unlink(self::$testDatastore); |
80 | } | 82 | } |
@@ -102,7 +104,7 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
102 | $this->assertEquals($id, $data['id']); | 104 | $this->assertEquals($id, $data['id']); |
103 | 105 | ||
104 | // Check link elements | 106 | // Check link elements |
105 | $this->assertEquals('http://domain.tld/?WDWyig', $data['url']); | 107 | $this->assertEquals('http://domain.tld/shaare/WDWyig', $data['url']); |
106 | $this->assertEquals('WDWyig', $data['shorturl']); | 108 | $this->assertEquals('WDWyig', $data['shorturl']); |
107 | $this->assertEquals('Link title: @website', $data['title']); | 109 | $this->assertEquals('Link title: @website', $data['title']); |
108 | $this->assertEquals( | 110 | $this->assertEquals( |
@@ -120,12 +122,12 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase | |||
120 | 122 | ||
121 | /** | 123 | /** |
122 | * Test basic getLink service: get non existent link => ApiLinkNotFoundException. | 124 | * Test basic getLink service: get non existent link => ApiLinkNotFoundException. |
123 | * | ||
124 | * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException | ||
125 | * @expectedExceptionMessage Link not found | ||
126 | */ | 125 | */ |
127 | public function testGetLink404() | 126 | public function testGetLink404() |
128 | { | 127 | { |
128 | $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); | ||
129 | $this->expectExceptionMessage('Link not found'); | ||
130 | |||
129 | $env = Environment::mock([ | 131 | $env = Environment::mock([ |
130 | 'REQUEST_METHOD' => 'GET', | 132 | 'REQUEST_METHOD' => 'GET', |
131 | ]); | 133 | ]); |
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php index 4e2d55ac..b1c46ee2 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php | |||
@@ -1,6 +1,7 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Api\Controllers; | 2 | namespace Shaarli\Api\Controllers; |
3 | 3 | ||
4 | use malkusch\lock\mutex\NoMutex; | ||
4 | use Shaarli\Bookmark\Bookmark; | 5 | use Shaarli\Bookmark\Bookmark; |
5 | use Shaarli\Bookmark\BookmarkFileService; | 6 | use Shaarli\Bookmark\BookmarkFileService; |
6 | use Shaarli\Bookmark\LinkDB; | 7 | use Shaarli\Bookmark\LinkDB; |
@@ -20,7 +21,7 @@ use Slim\Http\Response; | |||
20 | * | 21 | * |
21 | * @package Shaarli\Api\Controllers | 22 | * @package Shaarli\Api\Controllers |
22 | */ | 23 | */ |
23 | class GetLinksTest extends \PHPUnit\Framework\TestCase | 24 | class GetLinksTest extends \Shaarli\TestCase |
24 | { | 25 | { |
25 | /** | 26 | /** |
26 | * @var string datastore to test write operations | 27 | * @var string datastore to test write operations |
@@ -55,8 +56,9 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase | |||
55 | /** | 56 | /** |
56 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. | 57 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. |
57 | */ | 58 | */ |
58 | public function setUp() | 59 | protected function setUp(): void |
59 | { | 60 | { |
61 | $mutex = new NoMutex(); | ||
60 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 62 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
61 | $this->conf->set('resource.datastore', self::$testDatastore); | 63 | $this->conf->set('resource.datastore', self::$testDatastore); |
62 | $this->refDB = new \ReferenceLinkDB(); | 64 | $this->refDB = new \ReferenceLinkDB(); |
@@ -65,7 +67,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase | |||
65 | 67 | ||
66 | $this->container = new Container(); | 68 | $this->container = new Container(); |
67 | $this->container['conf'] = $this->conf; | 69 | $this->container['conf'] = $this->conf; |
68 | $this->container['db'] = new BookmarkFileService($this->conf, $history, true); | 70 | $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true); |
69 | $this->container['history'] = null; | 71 | $this->container['history'] = null; |
70 | 72 | ||
71 | $this->controller = new Links($this->container); | 73 | $this->controller = new Links($this->container); |
@@ -74,7 +76,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase | |||
74 | /** | 76 | /** |
75 | * After every test, remove the test datastore. | 77 | * After every test, remove the test datastore. |
76 | */ | 78 | */ |
77 | public function tearDown() | 79 | protected function tearDown(): void |
78 | { | 80 | { |
79 | @unlink(self::$testDatastore); | 81 | @unlink(self::$testDatastore); |
80 | } | 82 | } |
@@ -109,7 +111,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase | |||
109 | 111 | ||
110 | // Check first element fields | 112 | // Check first element fields |
111 | $first = $data[2]; | 113 | $first = $data[2]; |
112 | $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); | 114 | $this->assertEquals('http://domain.tld/shaare/WDWyig', $first['url']); |
113 | $this->assertEquals('WDWyig', $first['shorturl']); | 115 | $this->assertEquals('WDWyig', $first['shorturl']); |
114 | $this->assertEquals('Link title: @website', $first['title']); | 116 | $this->assertEquals('Link title: @website', $first['title']); |
115 | $this->assertEquals( | 117 | $this->assertEquals( |
@@ -396,7 +398,7 @@ class GetLinksTest extends \PHPUnit\Framework\TestCase | |||
396 | $response = $this->controller->getLinks($request, new Response()); | 398 | $response = $this->controller->getLinks($request, new Response()); |
397 | $this->assertEquals(200, $response->getStatusCode()); | 399 | $this->assertEquals(200, $response->getStatusCode()); |
398 | $data = json_decode((string) $response->getBody(), true); | 400 | $data = json_decode((string) $response->getBody(), true); |
399 | $this->assertEquals(4, count($data)); | 401 | $this->assertEquals(5, count($data)); |
400 | $this->assertEquals(6, $data[0]['id']); | 402 | $this->assertEquals(6, $data[0]['id']); |
401 | 403 | ||
402 | // wildcard: placeholder at the middle | 404 | // wildcard: placeholder at the middle |
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index 969b9fd9..e12f803b 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php | |||
@@ -2,11 +2,12 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use malkusch\lock\mutex\NoMutex; |
6 | use Shaarli\Bookmark\Bookmark; | 6 | use Shaarli\Bookmark\Bookmark; |
7 | use Shaarli\Bookmark\BookmarkFileService; | 7 | use Shaarli\Bookmark\BookmarkFileService; |
8 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
9 | use Shaarli\History; | 9 | use Shaarli\History; |
10 | use Shaarli\TestCase; | ||
10 | use Slim\Container; | 11 | use Slim\Container; |
11 | use Slim\Http\Environment; | 12 | use Slim\Http\Environment; |
12 | use Slim\Http\Request; | 13 | use Slim\Http\Request; |
@@ -70,8 +71,9 @@ class PostLinkTest extends TestCase | |||
70 | /** | 71 | /** |
71 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. | 72 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. |
72 | */ | 73 | */ |
73 | public function setUp() | 74 | protected function setUp(): void |
74 | { | 75 | { |
76 | $mutex = new NoMutex(); | ||
75 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 77 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
76 | $this->conf->set('resource.datastore', self::$testDatastore); | 78 | $this->conf->set('resource.datastore', self::$testDatastore); |
77 | $this->refDB = new \ReferenceLinkDB(); | 79 | $this->refDB = new \ReferenceLinkDB(); |
@@ -79,7 +81,7 @@ class PostLinkTest extends TestCase | |||
79 | $refHistory = new \ReferenceHistory(); | 81 | $refHistory = new \ReferenceHistory(); |
80 | $refHistory->write(self::$testHistory); | 82 | $refHistory->write(self::$testHistory); |
81 | $this->history = new History(self::$testHistory); | 83 | $this->history = new History(self::$testHistory); |
82 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 84 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); |
83 | 85 | ||
84 | $this->container = new Container(); | 86 | $this->container = new Container(); |
85 | $this->container['conf'] = $this->conf; | 87 | $this->container['conf'] = $this->conf; |
@@ -107,7 +109,7 @@ class PostLinkTest extends TestCase | |||
107 | /** | 109 | /** |
108 | * After every test, remove the test datastore. | 110 | * After every test, remove the test datastore. |
109 | */ | 111 | */ |
110 | public function tearDown() | 112 | protected function tearDown(): void |
111 | { | 113 | { |
112 | @unlink(self::$testDatastore); | 114 | @unlink(self::$testDatastore); |
113 | @unlink(self::$testHistory); | 115 | @unlink(self::$testHistory); |
@@ -131,8 +133,8 @@ class PostLinkTest extends TestCase | |||
131 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 133 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
132 | $this->assertEquals(43, $data['id']); | 134 | $this->assertEquals(43, $data['id']); |
133 | $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']); | 135 | $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']); |
134 | $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); | 136 | $this->assertEquals('http://domain.tld/shaare/' . $data['shorturl'], $data['url']); |
135 | $this->assertEquals('?' . $data['shorturl'], $data['title']); | 137 | $this->assertEquals('/shaare/' . $data['shorturl'], $data['title']); |
136 | $this->assertEquals('', $data['description']); | 138 | $this->assertEquals('', $data['description']); |
137 | $this->assertEquals([], $data['tags']); | 139 | $this->assertEquals([], $data['tags']); |
138 | $this->assertEquals(true, $data['private']); | 140 | $this->assertEquals(true, $data['private']); |
@@ -160,6 +162,8 @@ class PostLinkTest extends TestCase | |||
160 | 'description' => 'shaare description', | 162 | 'description' => 'shaare description', |
161 | 'tags' => ['one', 'two'], | 163 | 'tags' => ['one', 'two'], |
162 | 'private' => true, | 164 | 'private' => true, |
165 | 'created' => '2015-05-05T12:30:00+03:00', | ||
166 | 'updated' => '2016-06-05T14:32:10+03:00', | ||
163 | ]; | 167 | ]; |
164 | $env = Environment::mock([ | 168 | $env = Environment::mock([ |
165 | 'REQUEST_METHOD' => 'POST', | 169 | 'REQUEST_METHOD' => 'POST', |
@@ -181,10 +185,8 @@ class PostLinkTest extends TestCase | |||
181 | $this->assertEquals($link['description'], $data['description']); | 185 | $this->assertEquals($link['description'], $data['description']); |
182 | $this->assertEquals($link['tags'], $data['tags']); | 186 | $this->assertEquals($link['tags'], $data['tags']); |
183 | $this->assertEquals(true, $data['private']); | 187 | $this->assertEquals(true, $data['private']); |
184 | $this->assertTrue( | 188 | $this->assertSame($link['created'], $data['created']); |
185 | new \DateTime('2 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 189 | $this->assertSame($link['updated'], $data['updated']); |
186 | ); | ||
187 | $this->assertEquals('', $data['updated']); | ||
188 | } | 190 | } |
189 | 191 | ||
190 | /** | 192 | /** |
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index cb63742e..240ee323 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use malkusch\lock\mutex\NoMutex; | ||
6 | use Shaarli\Bookmark\Bookmark; | 7 | use Shaarli\Bookmark\Bookmark; |
7 | use Shaarli\Bookmark\BookmarkFileService; | 8 | use Shaarli\Bookmark\BookmarkFileService; |
8 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
@@ -12,7 +13,7 @@ use Slim\Http\Environment; | |||
12 | use Slim\Http\Request; | 13 | use Slim\Http\Request; |
13 | use Slim\Http\Response; | 14 | use Slim\Http\Response; |
14 | 15 | ||
15 | class PutLinkTest extends \PHPUnit\Framework\TestCase | 16 | class PutLinkTest extends \Shaarli\TestCase |
16 | { | 17 | { |
17 | /** | 18 | /** |
18 | * @var string datastore to test write operations | 19 | * @var string datastore to test write operations |
@@ -62,8 +63,9 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
62 | /** | 63 | /** |
63 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. | 64 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. |
64 | */ | 65 | */ |
65 | public function setUp() | 66 | protected function setUp(): void |
66 | { | 67 | { |
68 | $mutex = new NoMutex(); | ||
67 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 69 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
68 | $this->conf->set('resource.datastore', self::$testDatastore); | 70 | $this->conf->set('resource.datastore', self::$testDatastore); |
69 | $this->refDB = new \ReferenceLinkDB(); | 71 | $this->refDB = new \ReferenceLinkDB(); |
@@ -71,7 +73,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
71 | $refHistory = new \ReferenceHistory(); | 73 | $refHistory = new \ReferenceHistory(); |
72 | $refHistory->write(self::$testHistory); | 74 | $refHistory->write(self::$testHistory); |
73 | $this->history = new History(self::$testHistory); | 75 | $this->history = new History(self::$testHistory); |
74 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 76 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); |
75 | 77 | ||
76 | $this->container = new Container(); | 78 | $this->container = new Container(); |
77 | $this->container['conf'] = $this->conf; | 79 | $this->container['conf'] = $this->conf; |
@@ -91,7 +93,7 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
91 | /** | 93 | /** |
92 | * After every test, remove the test datastore. | 94 | * After every test, remove the test datastore. |
93 | */ | 95 | */ |
94 | public function tearDown() | 96 | protected function tearDown(): void |
95 | { | 97 | { |
96 | @unlink(self::$testDatastore); | 98 | @unlink(self::$testDatastore); |
97 | @unlink(self::$testHistory); | 99 | @unlink(self::$testHistory); |
@@ -114,8 +116,8 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
114 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 116 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
115 | $this->assertEquals($id, $data['id']); | 117 | $this->assertEquals($id, $data['id']); |
116 | $this->assertEquals('WDWyig', $data['shorturl']); | 118 | $this->assertEquals('WDWyig', $data['shorturl']); |
117 | $this->assertEquals('http://domain.tld/?WDWyig', $data['url']); | 119 | $this->assertEquals('http://domain.tld/shaare/WDWyig', $data['url']); |
118 | $this->assertEquals('?WDWyig', $data['title']); | 120 | $this->assertEquals('/shaare/WDWyig', $data['title']); |
119 | $this->assertEquals('', $data['description']); | 121 | $this->assertEquals('', $data['description']); |
120 | $this->assertEquals([], $data['tags']); | 122 | $this->assertEquals([], $data['tags']); |
121 | $this->assertEquals(true, $data['private']); | 123 | $this->assertEquals(true, $data['private']); |
@@ -218,12 +220,12 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase | |||
218 | 220 | ||
219 | /** | 221 | /** |
220 | * Test link update on non existent link => ApiLinkNotFoundException. | 222 | * Test link update on non existent link => ApiLinkNotFoundException. |
221 | * | ||
222 | * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException | ||
223 | * @expectedExceptionMessage Link not found | ||
224 | */ | 223 | */ |
225 | public function testGetLink404() | 224 | public function testGetLink404() |
226 | { | 225 | { |
226 | $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); | ||
227 | $this->expectExceptionMessage('Link not found'); | ||
228 | |||
227 | $env = Environment::mock([ | 229 | $env = Environment::mock([ |
228 | 'REQUEST_METHOD' => 'PUT', | 230 | 'REQUEST_METHOD' => 'PUT', |
229 | ]); | 231 | ]); |
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index c6748872..37f07229 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use malkusch\lock\mutex\NoMutex; | ||
6 | use Shaarli\Bookmark\BookmarkFileService; | 7 | use Shaarli\Bookmark\BookmarkFileService; |
7 | use Shaarli\Bookmark\LinkDB; | 8 | use Shaarli\Bookmark\LinkDB; |
8 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
@@ -12,7 +13,7 @@ use Slim\Http\Environment; | |||
12 | use Slim\Http\Request; | 13 | use Slim\Http\Request; |
13 | use Slim\Http\Response; | 14 | use Slim\Http\Response; |
14 | 15 | ||
15 | class DeleteTagTest extends \PHPUnit\Framework\TestCase | 16 | class DeleteTagTest extends \Shaarli\TestCase |
16 | { | 17 | { |
17 | /** | 18 | /** |
18 | * @var string datastore to test write operations | 19 | * @var string datastore to test write operations |
@@ -54,11 +55,15 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
54 | */ | 55 | */ |
55 | protected $controller; | 56 | protected $controller; |
56 | 57 | ||
58 | /** @var NoMutex */ | ||
59 | protected $mutex; | ||
60 | |||
57 | /** | 61 | /** |
58 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. | 62 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. |
59 | */ | 63 | */ |
60 | public function setUp() | 64 | protected function setUp(): void |
61 | { | 65 | { |
66 | $this->mutex = new NoMutex(); | ||
62 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 67 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
63 | $this->conf->set('resource.datastore', self::$testDatastore); | 68 | $this->conf->set('resource.datastore', self::$testDatastore); |
64 | $this->refDB = new \ReferenceLinkDB(); | 69 | $this->refDB = new \ReferenceLinkDB(); |
@@ -66,7 +71,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
66 | $refHistory = new \ReferenceHistory(); | 71 | $refHistory = new \ReferenceHistory(); |
67 | $refHistory->write(self::$testHistory); | 72 | $refHistory->write(self::$testHistory); |
68 | $this->history = new History(self::$testHistory); | 73 | $this->history = new History(self::$testHistory); |
69 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 74 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
70 | 75 | ||
71 | $this->container = new Container(); | 76 | $this->container = new Container(); |
72 | $this->container['conf'] = $this->conf; | 77 | $this->container['conf'] = $this->conf; |
@@ -79,7 +84,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
79 | /** | 84 | /** |
80 | * After each test, remove the test datastore. | 85 | * After each test, remove the test datastore. |
81 | */ | 86 | */ |
82 | public function tearDown() | 87 | protected function tearDown(): void |
83 | { | 88 | { |
84 | @unlink(self::$testDatastore); | 89 | @unlink(self::$testDatastore); |
85 | @unlink(self::$testHistory); | 90 | @unlink(self::$testHistory); |
@@ -102,7 +107,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
102 | $this->assertEquals(204, $response->getStatusCode()); | 107 | $this->assertEquals(204, $response->getStatusCode()); |
103 | $this->assertEmpty((string) $response->getBody()); | 108 | $this->assertEmpty((string) $response->getBody()); |
104 | 109 | ||
105 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 110 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
106 | $tags = $this->bookmarkService->bookmarksCountPerTag(); | 111 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
107 | $this->assertFalse(isset($tags[$tagName])); | 112 | $this->assertFalse(isset($tags[$tagName])); |
108 | 113 | ||
@@ -136,7 +141,7 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
136 | $this->assertEquals(204, $response->getStatusCode()); | 141 | $this->assertEquals(204, $response->getStatusCode()); |
137 | $this->assertEmpty((string) $response->getBody()); | 142 | $this->assertEmpty((string) $response->getBody()); |
138 | 143 | ||
139 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 144 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
140 | $tags = $this->bookmarkService->bookmarksCountPerTag(); | 145 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
141 | $this->assertFalse(isset($tags[$tagName])); | 146 | $this->assertFalse(isset($tags[$tagName])); |
142 | $this->assertTrue($tags[strtolower($tagName)] > 0); | 147 | $this->assertTrue($tags[strtolower($tagName)] > 0); |
@@ -150,12 +155,12 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase | |||
150 | 155 | ||
151 | /** | 156 | /** |
152 | * Test DELETE tag endpoint: reach not existing tag. | 157 | * Test DELETE tag endpoint: reach not existing tag. |
153 | * | ||
154 | * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException | ||
155 | * @expectedExceptionMessage Tag not found | ||
156 | */ | 158 | */ |
157 | public function testDeleteLink404() | 159 | public function testDeleteLink404() |
158 | { | 160 | { |
161 | $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); | ||
162 | $this->expectExceptionMessage('Tag not found'); | ||
163 | |||
159 | $tagName = 'nopenope'; | 164 | $tagName = 'nopenope'; |
160 | $tags = $this->bookmarkService->bookmarksCountPerTag(); | 165 | $tags = $this->bookmarkService->bookmarksCountPerTag(); |
161 | $this->assertFalse(isset($tags[$tagName])); | 166 | $this->assertFalse(isset($tags[$tagName])); |
diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php index b9a81f9b..878de5a4 100644 --- a/tests/api/controllers/tags/GetTagNameTest.php +++ b/tests/api/controllers/tags/GetTagNameTest.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use malkusch\lock\mutex\NoMutex; | ||
5 | use Shaarli\Bookmark\BookmarkFileService; | 6 | use Shaarli\Bookmark\BookmarkFileService; |
6 | use Shaarli\Bookmark\LinkDB; | 7 | use Shaarli\Bookmark\LinkDB; |
7 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
@@ -18,7 +19,7 @@ use Slim\Http\Response; | |||
18 | * | 19 | * |
19 | * @package Shaarli\Api\Controllers | 20 | * @package Shaarli\Api\Controllers |
20 | */ | 21 | */ |
21 | class GetTagNameTest extends \PHPUnit\Framework\TestCase | 22 | class GetTagNameTest extends \Shaarli\TestCase |
22 | { | 23 | { |
23 | /** | 24 | /** |
24 | * @var string datastore to test write operations | 25 | * @var string datastore to test write operations |
@@ -53,8 +54,9 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase | |||
53 | /** | 54 | /** |
54 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. | 55 | * Before each test, instantiate a new Api with its config, plugins and bookmarks. |
55 | */ | 56 | */ |
56 | public function setUp() | 57 | protected function setUp(): void |
57 | { | 58 | { |
59 | $mutex = new NoMutex(); | ||
58 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 60 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
59 | $this->conf->set('resource.datastore', self::$testDatastore); | 61 | $this->conf->set('resource.datastore', self::$testDatastore); |
60 | $this->refDB = new \ReferenceLinkDB(); | 62 | $this->refDB = new \ReferenceLinkDB(); |
@@ -63,7 +65,7 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase | |||
63 | 65 | ||
64 | $this->container = new Container(); | 66 | $this->container = new Container(); |
65 | $this->container['conf'] = $this->conf; | 67 | $this->container['conf'] = $this->conf; |
66 | $this->container['db'] = new BookmarkFileService($this->conf, $history, true); | 68 | $this->container['db'] = new BookmarkFileService($this->conf, $history, $mutex, true); |
67 | $this->container['history'] = null; | 69 | $this->container['history'] = null; |
68 | 70 | ||
69 | $this->controller = new Tags($this->container); | 71 | $this->controller = new Tags($this->container); |
@@ -72,7 +74,7 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase | |||
72 | /** | 74 | /** |
73 | * After each test, remove the test datastore. | 75 | * After each test, remove the test datastore. |
74 | */ | 76 | */ |
75 | public function tearDown() | 77 | protected function tearDown(): void |
76 | { | 78 | { |
77 | @unlink(self::$testDatastore); | 79 | @unlink(self::$testDatastore); |
78 | } | 80 | } |
@@ -117,12 +119,12 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase | |||
117 | 119 | ||
118 | /** | 120 | /** |
119 | * Test basic getTag service: get non existent tag => ApiTagNotFoundException. | 121 | * Test basic getTag service: get non existent tag => ApiTagNotFoundException. |
120 | * | ||
121 | * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException | ||
122 | * @expectedExceptionMessage Tag not found | ||
123 | */ | 122 | */ |
124 | public function testGetTag404() | 123 | public function testGetTag404() |
125 | { | 124 | { |
125 | $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); | ||
126 | $this->expectExceptionMessage('Tag not found'); | ||
127 | |||
126 | $env = Environment::mock([ | 128 | $env = Environment::mock([ |
127 | 'REQUEST_METHOD' => 'GET', | 129 | 'REQUEST_METHOD' => 'GET', |
128 | ]); | 130 | ]); |
diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php index 53a3326d..b565a8c4 100644 --- a/tests/api/controllers/tags/GetTagsTest.php +++ b/tests/api/controllers/tags/GetTagsTest.php | |||
@@ -1,6 +1,7 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Api\Controllers; | 2 | namespace Shaarli\Api\Controllers; |
3 | 3 | ||
4 | use malkusch\lock\mutex\NoMutex; | ||
4 | use Shaarli\Bookmark\BookmarkFileService; | 5 | use Shaarli\Bookmark\BookmarkFileService; |
5 | use Shaarli\Bookmark\LinkDB; | 6 | use Shaarli\Bookmark\LinkDB; |
6 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
@@ -17,7 +18,7 @@ use Slim\Http\Response; | |||
17 | * | 18 | * |
18 | * @package Shaarli\Api\Controllers | 19 | * @package Shaarli\Api\Controllers |
19 | */ | 20 | */ |
20 | class GetTagsTest extends \PHPUnit\Framework\TestCase | 21 | class GetTagsTest extends \Shaarli\TestCase |
21 | { | 22 | { |
22 | /** | 23 | /** |
23 | * @var string datastore to test write operations | 24 | * @var string datastore to test write operations |
@@ -57,15 +58,16 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase | |||
57 | /** | 58 | /** |
58 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. | 59 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. |
59 | */ | 60 | */ |
60 | public function setUp() | 61 | protected function setUp(): void |
61 | { | 62 | { |
63 | $mutex = new NoMutex(); | ||
62 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 64 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
63 | $this->conf->set('resource.datastore', self::$testDatastore); | 65 | $this->conf->set('resource.datastore', self::$testDatastore); |
64 | $this->refDB = new \ReferenceLinkDB(); | 66 | $this->refDB = new \ReferenceLinkDB(); |
65 | $this->refDB->write(self::$testDatastore); | 67 | $this->refDB->write(self::$testDatastore); |
66 | $history = new History('sandbox/history.php'); | 68 | $history = new History('sandbox/history.php'); |
67 | 69 | ||
68 | $this->bookmarkService = new BookmarkFileService($this->conf, $history, true); | 70 | $this->bookmarkService = new BookmarkFileService($this->conf, $history, $mutex, true); |
69 | 71 | ||
70 | $this->container = new Container(); | 72 | $this->container = new Container(); |
71 | $this->container['conf'] = $this->conf; | 73 | $this->container['conf'] = $this->conf; |
@@ -78,7 +80,7 @@ class GetTagsTest extends \PHPUnit\Framework\TestCase | |||
78 | /** | 80 | /** |
79 | * After every test, remove the test datastore. | 81 | * After every test, remove the test datastore. |
80 | */ | 82 | */ |
81 | public function tearDown() | 83 | protected function tearDown(): void |
82 | { | 84 | { |
83 | @unlink(self::$testDatastore); | 85 | @unlink(self::$testDatastore); |
84 | } | 86 | } |
diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php index 2a3cc15a..c73f6d3b 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use malkusch\lock\mutex\NoMutex; | ||
5 | use Shaarli\Api\Exceptions\ApiBadParametersException; | 6 | use Shaarli\Api\Exceptions\ApiBadParametersException; |
6 | use Shaarli\Bookmark\BookmarkFileService; | 7 | use Shaarli\Bookmark\BookmarkFileService; |
7 | use Shaarli\Bookmark\LinkDB; | 8 | use Shaarli\Bookmark\LinkDB; |
@@ -12,7 +13,7 @@ use Slim\Http\Environment; | |||
12 | use Slim\Http\Request; | 13 | use Slim\Http\Request; |
13 | use Slim\Http\Response; | 14 | use Slim\Http\Response; |
14 | 15 | ||
15 | class PutTagTest extends \PHPUnit\Framework\TestCase | 16 | class PutTagTest extends \Shaarli\TestCase |
16 | { | 17 | { |
17 | /** | 18 | /** |
18 | * @var string datastore to test write operations | 19 | * @var string datastore to test write operations |
@@ -62,8 +63,9 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
62 | /** | 63 | /** |
63 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. | 64 | * Before every test, instantiate a new Api with its config, plugins and bookmarks. |
64 | */ | 65 | */ |
65 | public function setUp() | 66 | protected function setUp(): void |
66 | { | 67 | { |
68 | $mutex = new NoMutex(); | ||
67 | $this->conf = new ConfigManager('tests/utils/config/configJson'); | 69 | $this->conf = new ConfigManager('tests/utils/config/configJson'); |
68 | $this->conf->set('resource.datastore', self::$testDatastore); | 70 | $this->conf->set('resource.datastore', self::$testDatastore); |
69 | $this->refDB = new \ReferenceLinkDB(); | 71 | $this->refDB = new \ReferenceLinkDB(); |
@@ -71,7 +73,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
71 | $refHistory = new \ReferenceHistory(); | 73 | $refHistory = new \ReferenceHistory(); |
72 | $refHistory->write(self::$testHistory); | 74 | $refHistory->write(self::$testHistory); |
73 | $this->history = new History(self::$testHistory); | 75 | $this->history = new History(self::$testHistory); |
74 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 76 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $mutex, true); |
75 | 77 | ||
76 | $this->container = new Container(); | 78 | $this->container = new Container(); |
77 | $this->container['conf'] = $this->conf; | 79 | $this->container['conf'] = $this->conf; |
@@ -84,7 +86,7 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
84 | /** | 86 | /** |
85 | * After every test, remove the test datastore. | 87 | * After every test, remove the test datastore. |
86 | */ | 88 | */ |
87 | public function tearDown() | 89 | protected function tearDown(): void |
88 | { | 90 | { |
89 | @unlink(self::$testDatastore); | 91 | @unlink(self::$testDatastore); |
90 | @unlink(self::$testHistory); | 92 | @unlink(self::$testHistory); |
@@ -159,12 +161,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
159 | 161 | ||
160 | /** | 162 | /** |
161 | * Test tag update with an empty new tag name => ApiBadParametersException | 163 | * 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 | */ | 164 | */ |
166 | public function testPutTagEmpty() | 165 | public function testPutTagEmpty() |
167 | { | 166 | { |
167 | $this->expectException(\Shaarli\Api\Exceptions\ApiBadParametersException::class); | ||
168 | $this->expectExceptionMessage('New tag name is required in the request body'); | ||
169 | |||
168 | $tagName = 'gnu'; | 170 | $tagName = 'gnu'; |
169 | $newName = ''; | 171 | $newName = ''; |
170 | 172 | ||
@@ -194,12 +196,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase | |||
194 | 196 | ||
195 | /** | 197 | /** |
196 | * Test tag update on non existent tag => ApiTagNotFoundException. | 198 | * Test tag update on non existent tag => ApiTagNotFoundException. |
197 | * | ||
198 | * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException | ||
199 | * @expectedExceptionMessage Tag not found | ||
200 | */ | 199 | */ |
201 | public function testPutTag404() | 200 | public function testPutTag404() |
202 | { | 201 | { |
202 | $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); | ||
203 | $this->expectExceptionMessage('Tag not found'); | ||
204 | |||
203 | $env = Environment::mock([ | 205 | $env = Environment::mock([ |
204 | 'REQUEST_METHOD' => 'PUT', | 206 | 'REQUEST_METHOD' => 'PUT', |
205 | ]); | 207 | ]); |