Skip to content

Commit 9926bee

Browse files
committed
Tests: Resolve analysed bugs
1 parent 8ca3db5 commit 9926bee

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

tests/DetectorTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
2+
23
/**
34
* The MIT License (MIT)
45
* Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
6+
*
7+
* @noinspection PhpUnused
58
* @testCase
69
*/
710

@@ -194,22 +197,22 @@ public function testEnabler($testValue): void
194197

195198
public function testMissingEnablerMode(): void
196199
{
197-
Assert::exception(function () {
200+
Assert::exception(static function () {
198201
new Detector(Detector::MODE_FULL);
199202
}, InconsistentEnablerModeException::class);
200203
}
201204

202205
public function testMissingEnabler(): void
203206
{
204-
Assert::exception(function () {
207+
Assert::exception(static function () {
205208
$detector = new Detector(Detector::MODE_SIMPLE);
206209
$detector->getEnabler();
207210
}, InconsistentEnablerModeException::class);
208211
}
209212

210213
public function testMissingEnablerShortcut(): void
211214
{
212-
Assert::exception(function () {
215+
Assert::exception(static function () {
213216
Detector::detect(Detector::MODE_FULL);
214217
}, InconsistentEnablerModeException::class);
215218
}

tests/Plugin/SignUrlTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
2+
23
/**
34
* The MIT License (MIT)
45
* Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
6+
*
7+
* @noinspection PhpUnused
58
* @testCase
69
*/
710

@@ -14,10 +17,11 @@
1417
use Redbitcz\DebugMode\Plugin\SignedUrl;
1518
use Redbitcz\DebugMode\Plugin\SignedUrlVerificationException;
1619
use Tester\Assert;
20+
use Tester\TestCase;
1721

1822
require __DIR__ . '/../bootstrap.php';
1923

20-
class SignUrlTest extends \Tester\TestCase
24+
class SignUrlTest extends TestCase
2125
{
2226
private const KEY_HS256 = "zhYiojmp7O3VYQNuW0C5rS0VgFNgoAvuxW4IdS/0tn8";
2327

@@ -148,18 +152,18 @@ public function testVerifyRequest(): void
148152
Assert::equal($expected, $parsed);
149153
}
150154

151-
public function testSignInvalidUrl()
155+
public function testSignInvalidUrl(): void
152156
{
153-
Assert::exception(function () {
157+
Assert::exception(static function () {
154158
$url = (string)base64_decode('Ly8Eijrg+qawZw==');
155159
$plugin = new SignedUrl(self::KEY_HS256, 'HS256');
156160
$plugin->signUrl($url, 1600000600);
157161
}, LogicException::class);
158162
}
159163

160-
public function testSignRelativeUrl()
164+
public function testSignRelativeUrl(): void
161165
{
162-
Assert::exception(function () {
166+
Assert::exception(static function () {
163167
$url = '/login?email=foo@bar.cz';
164168
$plugin = new SignedUrl(self::KEY_HS256, 'HS256');
165169
$plugin->signUrl($url, 1600000600);
@@ -179,23 +183,23 @@ public function testVerifyPostRequest(): void
179183
$plugin = new SignedUrl(self::KEY_HS256, 'HS256', $audience);
180184
$plugin->setTimestamp($timestamp);
181185
JWT::$timestamp = $timestamp;
182-
Assert::exception(function () use ($plugin, $tokenUrl) {
186+
Assert::exception(static function () use ($plugin, $tokenUrl) {
183187
$plugin->verifyRequest(false, $tokenUrl, 'POST');
184188
}, SignedUrlVerificationException::class, 'HTTP method doesn\'t match signed HTTP method');
185189
}
186190

187191
public function testVerifyInvalidRequest(): void
188192
{
189-
Assert::exception(function () {
193+
Assert::exception(static function () {
190194
$plugin = new SignedUrl(self::KEY_HS256, 'HS256');
191195
$url = (string)base64_decode('Ly8Eijrg+qawZw==');
192196
$plugin->verifyRequest(false, $url, 'GET');
193197
}, SignedUrlVerificationException::class, 'Url is invalid');
194198
}
195199

196-
public function testVerifyInvalidUrl()
200+
public function testVerifyInvalidUrl(): void
197201
{
198-
Assert::exception(function () {
202+
Assert::exception(static function () {
199203
$plugin = new SignedUrl(self::KEY_HS256, 'HS256');
200204
$plugin->verifyUrl('https://host.tld/path?query=value');
201205
}, SignedUrlVerificationException::class, 'No token in URL');
@@ -213,7 +217,7 @@ public function testVerifyUrlWithSuffix(): void
213217
$tokenUrl .= '&fbclid=123456789';
214218

215219
Assert::exception(
216-
function () use ($timestamp, $tokenUrl) {
220+
static function () use ($timestamp, $tokenUrl) {
217221
$plugin = new SignedUrl(self::KEY_HS256, 'HS256');
218222
$plugin->setTimestamp($timestamp);
219223
JWT::$timestamp = $timestamp;

0 commit comments

Comments
 (0)