Skip to content

Commit b1216d2

Browse files
authored
feat: add PHPStan extensions (web-push-libs#440)
- detect deprecated functions - check PHPUnit
1 parent 999bf76 commit b1216d2

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
4343
"ext-gmp": "Optional for performance."
4444
},
4545
"require-dev": {
46-
"phpunit/phpunit": "^11.5.46|^12.5.2",
47-
"phpstan/phpstan": "^2.1.33",
4846
"friendsofphp/php-cs-fixer": "^v3.92.2",
49-
"symfony/polyfill-iconv": "^1.33",
50-
"phpstan/phpstan-strict-rules": "^2.0"
47+
"phpstan/phpstan": "^2.1.33",
48+
"phpstan/phpstan-deprecation-rules": "^2.0",
49+
"phpstan/phpstan-phpunit": "^2.0",
50+
"phpstan/phpstan-strict-rules": "^2.0",
51+
"phpunit/phpunit": "^11.5.46|^12.5.2",
52+
"symfony/polyfill-iconv": "^1.33"
5153
},
5254
"autoload": {
5355
"psr-4": {

phpstan.neon

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,35 @@ parameters:
22
level: 7
33
paths:
44
- src
5+
- tests
56
reportUnmatchedIgnoredErrors: false
67
checkMissingOverrideMethodAttribute: true
78
tipsOfTheDay: false
89
treatPhpDocTypesAsCertain: false
910
ignoreErrors:
1011
- identifier: missingType.iterableValue
12+
paths:
13+
- src/Encryption.php
14+
- src/MessageSentReport.php
15+
- src/Notification.php
16+
- src/Subscription.php
17+
- src/Utils.php
18+
- src/VAPID.php
19+
- src/WebPush.php
20+
- path: tests/
21+
identifiers:
22+
- argument.type
23+
- closure.unusedUse
24+
- foreach.valueOverwrite
25+
- missingType.iterableValue
26+
- property.dynamicName
27+
- staticMethod.dynamicCall
1128
strictRules:
1229
booleansInConditions: false
1330
disallowedEmpty: false
1431

1532
includes:
33+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
34+
- vendor/phpstan/phpstan-phpunit/extension.neon
35+
- vendor/phpstan/phpstan-phpunit/rules.neon
1636
- vendor/phpstan/phpstan-strict-rules/rules.neon

tests/PushServiceTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function browserProvider(): array
5353
/**
5454
* Selenium tests are flakey so add retries.
5555
*/
56-
public function retryTest($retryCount, $test): void
56+
public function retryTest(int $retryCount, callable $test): void
5757
{
5858
// just like above without checking the annotation
5959
for ($i = 0; $i < $retryCount; $i++) {
@@ -74,12 +74,12 @@ public function retryTest($retryCount, $test): void
7474
* Run integration tests with browsers
7575
*/
7676
#[dataProvider('browserProvider')]
77-
public function testBrowsers($browserId, $options): void
77+
public function testBrowsers(string $browserId, array $options): void
7878
{
7979
$this->retryTest(2, $this->createClosureTest($browserId, $options));
8080
}
8181

82-
protected function createClosureTest($browserId, $options): callable
82+
protected function createClosureTest(string $browserId, array $options): callable
8383
{
8484
return function () use ($browserId, $options): void {
8585
$this->webPush = new WebPush($options);
@@ -126,7 +126,6 @@ protected function createClosureTest($browserId, $options): callable
126126

127127
$subscription = new Subscription($endpoint, $p256dh, $auth, $contentEncoding);
128128
$report = $this->webPush->sendOneNotification($subscription, $payload);
129-
$this->assertInstanceOf(MessageSentReport::class, $report);
130129
$this->assertTrue($report->isSuccess());
131130

132131
$dataString = json_encode([
@@ -158,7 +157,7 @@ protected function createClosureTest($browserId, $options): callable
158157
};
159158
}
160159

161-
private function getResponse($ch)
160+
private function getResponse(CurlHandle $ch): mixed
162161
{
163162
$resp = curl_exec($ch);
164163

tests/WebPushTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ private static function setCiEnvironment(): void
116116
self::$keys['standard'] = $keys->{'p256dh'};
117117
}
118118

119-
/**
120-
* @throws ErrorException
121-
*/
122119
public static function notificationProvider(): array
123120
{
124121
self::setUpBeforeClass(); // dirty hack of PHPUnit limitation
125122

126123
return [
127-
[new Subscription(self::$endpoints['standard'] ?: '', self::$keys['standard'] ?: '', self::$tokens['standard'] ?: ''), '{"message":"Comment ça va ?","tag":"general"}'],
124+
[
125+
new Subscription(self::$endpoints['standard'] ?? '', self::$keys['standard'] ?? '', self::$tokens['standard'] ?? ''),
126+
'{"message":"Comment ça va ?","tag":"general"}',
127+
],
128128
];
129129
}
130130

0 commit comments

Comments
 (0)