Skip to content

Commit 303107b

Browse files
committed
Add PHPStan to test environment
1 parent 73ee629 commit 303107b

File tree

10 files changed

+50
-2
lines changed

10 files changed

+50
-2
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/.gitattributes export-ignore
22
/.github/ export-ignore
33
/.gitignore export-ignore
4+
/phpstan.neon.dist export-ignore
45
/phpunit.xml.dist export-ignore
56
/phpunit.xml.legacy export-ignore
67
/tests/ export-ignore

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,25 @@ jobs:
3030
if: ${{ matrix.php >= 7.3 }}
3131
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
3232
if: ${{ matrix.php < 7.3 }}
33+
34+
PHPStan:
35+
name: PHPStan (PHP ${{ matrix.php }})
36+
runs-on: ubuntu-22.04
37+
strategy:
38+
matrix:
39+
php:
40+
- 8.2
41+
- 8.1
42+
- 8.0
43+
- 7.4
44+
- 7.3
45+
- 7.2
46+
- 7.1
47+
steps:
48+
- uses: actions/checkout@v3
49+
- uses: shivammathur/setup-php@v2
50+
with:
51+
php-version: ${{ matrix.php }}
52+
coverage: none
53+
- run: composer install
54+
- run: vendor/bin/phpstan

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ To run the test suite, go to the project root and run:
426426
vendor/bin/phpunit
427427
```
428428

429+
On top of this, we use PHPStan on level 3 to ensure type safety across the project:
430+
431+
```bash
432+
vendor/bin/phpstan
433+
```
434+
429435
## License
430436

431437
MIT, see [LICENSE file](LICENSE).

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"react/promise": "^3.0 || ^2.8 || ^1.2.1"
3232
},
3333
"require-dev": {
34+
"phpstan/phpstan": "1.10.18 || 1.4.10",
3435
"phpunit/phpunit": "^9.5 || ^7.5"
3536
},
3637
"autoload": {

phpstan.neon.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
level: 3
3+
4+
paths:
5+
- src/
6+
- tests/
7+
8+
reportUnmatchedIgnoredErrors: false
9+
ignoreErrors:
10+
# ignore generic usage like `PromiseInterface<T>` until fixed upstream
11+
- '/^PHPDoc .* contains generic type React\\Promise\\PromiseInterface<.+> but interface React\\Promise\\PromiseInterface is not generic\.$/'

src/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function delay(float $seconds): void
294294
* });
295295
* ```
296296
*
297-
* @param callable(...$args):\Generator<mixed,PromiseInterface,mixed,mixed> $function
297+
* @param callable(mixed ...$args):\Generator<mixed,PromiseInterface,mixed,mixed> $function
298298
* @param mixed ...$args Optional list of additional arguments that will be passed to the given `$function` as is
299299
* @return PromiseInterface<mixed>
300300
* @since 3.0.0
@@ -437,9 +437,9 @@ function series(iterable $tasks): PromiseInterface
437437
assert($tasks instanceof \Iterator);
438438
}
439439

440-
/** @var callable():void $next */
441440
$taskCallback = function ($result) use (&$results, &$next) {
442441
$results[] = $result;
442+
assert($next instanceof \Closure);
443443
$next();
444444
};
445445

tests/CoroutineTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function testCancelCoroutineWillReturnRejectedPromiseWhenCancellingPendin
114114
});
115115
});
116116

117+
assert(method_exists($promise, 'cancel'));
117118
$promise->cancel();
118119

119120
$promise->then(null, $this->expectCallableOnceWith(new \RuntimeException('Operation cancelled')));
@@ -131,6 +132,7 @@ public function testCancelCoroutineWillReturnFulfilledPromiseWhenCancellingPendi
131132
}
132133
});
133134

135+
assert(method_exists($promise, 'cancel'));
134136
$promise->cancel();
135137

136138
$promise->then($this->expectCallableOnceWith(42));
@@ -150,6 +152,7 @@ public function testCancelCoroutineWillReturnPendigPromiseWhenCancellingFirstPro
150152
}
151153
});
152154

155+
assert(method_exists($promise, 'cancel'));
153156
$promise->cancel();
154157

155158
$promise->then($this->expectCallableNever(), $this->expectCallableNever());
@@ -209,6 +212,7 @@ public function testCoroutineShouldNotCreateAnyGarbageReferencesForPromiseReject
209212
});
210213
});
211214

215+
assert(method_exists($promise, 'cancel'));
212216
$promise->cancel();
213217
unset($promise);
214218

tests/ParallelTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ function () use (&$cancelled) {
193193
);
194194

195195
$promise = React\Async\parallel($tasks);
196+
assert(method_exists($promise, 'cancel'));
196197
$promise->cancel();
197198

198199
$this->assertSame(2, $cancelled);

tests/SeriesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ function () use (&$cancelled) {
185185
);
186186

187187
$promise = React\Async\series($tasks);
188+
assert(method_exists($promise, 'cancel'));
188189
$promise->cancel();
189190

190191
$this->assertSame(1, $cancelled);

tests/WaterfallTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ function () use (&$cancelled) {
199199
);
200200

201201
$promise = React\Async\waterfall($tasks);
202+
assert(method_exists($promise, 'cancel'));
202203
$promise->cancel();
203204

204205
$this->assertSame(1, $cancelled);

0 commit comments

Comments
 (0)