Skip to content

[3.x] Add PHPStan to test environment with max level #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add PHPStan to test environment
  • Loading branch information
clue committed Jun 12, 2023
commit 303107b1a7ae8be1cfd4dde62cf3e8acd6514afd
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,25 @@ jobs:
if: ${{ matrix.php >= 7.3 }}
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}

PHPStan:
name: PHPStan (PHP ${{ matrix.php }})
runs-on: ubuntu-22.04
strategy:
matrix:
php:
- 8.2
- 8.1
- 8.0
- 7.4
- 7.3
- 7.2
- 7.1
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
- run: composer install
- run: vendor/bin/phpstan
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ To run the test suite, go to the project root and run:
vendor/bin/phpunit
```

On top of this, we use PHPStan on level 3 to ensure type safety across the project:

```bash
vendor/bin/phpstan
```

## License

MIT, see [LICENSE file](LICENSE).
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"react/promise": "^3.0 || ^2.8 || ^1.2.1"
},
"require-dev": {
"phpstan/phpstan": "1.10.18 || 1.4.10",
"phpunit/phpunit": "^9.5 || ^7.5"
},
"autoload": {
Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
level: 3

paths:
- src/
- tests/

reportUnmatchedIgnoredErrors: false
ignoreErrors:
# ignore generic usage like `PromiseInterface<T>` until fixed upstream
- '/^PHPDoc .* contains generic type React\\Promise\\PromiseInterface<.+> but interface React\\Promise\\PromiseInterface is not generic\.$/'
4 changes: 2 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function delay(float $seconds): void
* });
* ```
*
* @param callable(...$args):\Generator<mixed,PromiseInterface,mixed,mixed> $function
* @param callable(mixed ...$args):\Generator<mixed,PromiseInterface,mixed,mixed> $function
* @param mixed ...$args Optional list of additional arguments that will be passed to the given `$function` as is
* @return PromiseInterface<mixed>
* @since 3.0.0
Expand Down Expand Up @@ -437,9 +437,9 @@ function series(iterable $tasks): PromiseInterface
assert($tasks instanceof \Iterator);
}

/** @var callable():void $next */
$taskCallback = function ($result) use (&$results, &$next) {
$results[] = $result;
assert($next instanceof \Closure);
$next();
};

Expand Down
4 changes: 4 additions & 0 deletions tests/CoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function testCancelCoroutineWillReturnRejectedPromiseWhenCancellingPendin
});
});

assert(method_exists($promise, 'cancel'));
$promise->cancel();

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

assert(method_exists($promise, 'cancel'));
$promise->cancel();

$promise->then($this->expectCallableOnceWith(42));
Expand All @@ -150,6 +152,7 @@ public function testCancelCoroutineWillReturnPendigPromiseWhenCancellingFirstPro
}
});

assert(method_exists($promise, 'cancel'));
$promise->cancel();

$promise->then($this->expectCallableNever(), $this->expectCallableNever());
Expand Down Expand Up @@ -209,6 +212,7 @@ public function testCoroutineShouldNotCreateAnyGarbageReferencesForPromiseReject
});
});

assert(method_exists($promise, 'cancel'));
$promise->cancel();
unset($promise);

Expand Down
1 change: 1 addition & 0 deletions tests/ParallelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function () use (&$cancelled) {
);

$promise = React\Async\parallel($tasks);
assert(method_exists($promise, 'cancel'));
$promise->cancel();

$this->assertSame(2, $cancelled);
Expand Down
1 change: 1 addition & 0 deletions tests/SeriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ function () use (&$cancelled) {
);

$promise = React\Async\series($tasks);
assert(method_exists($promise, 'cancel'));
$promise->cancel();

$this->assertSame(1, $cancelled);
Expand Down
1 change: 1 addition & 0 deletions tests/WaterfallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ function () use (&$cancelled) {
);

$promise = React\Async\waterfall($tasks);
assert(method_exists($promise, 'cancel'));
$promise->cancel();

$this->assertSame(1, $cancelled);
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy