Skip to content

Commit b05b628

Browse files
committed
Add PHPStan and PHP Code Sniffer
1 parent 0a3fac6 commit b05b628

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

.github/workflows/main.yml

+20-13
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@ jobs:
1111
php: [8.2, 8.3, 8.4]
1212

1313
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@v4
14+
- name: Checkout code
15+
uses: actions/checkout@v4
1616

17-
- name: Setup PHP
18-
uses: shivammathur/setup-php@v2
19-
with:
20-
php-version: ${{ matrix.php }}
21-
coverage: none
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php }}
21+
coverage: none
22+
tools: phpstan, phpcs
2223

23-
- name: Validate composer.json and composer.lock
24-
run: composer validate
24+
- name: Validate composer.json and composer.lock
25+
run: composer validate
2526

26-
- name: Install dependencies
27-
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
27+
- name: Install dependencies
28+
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
2829

29-
- name: Run test suite
30-
run: php vendor/bin/codecept run
30+
- name: Run PHPStan
31+
run: phpstan analyse src
32+
33+
- name: Run PHPCS
34+
run: phpcs --standard=PSR12 src
35+
36+
- name: Run test suite
37+
run: php vendor/bin/codecept run

src/Codeception/Module/AbstractAsserts.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@ abstract class AbstractAsserts extends Module
147147
markTestIncomplete as public;
148148
markTestSkipped as public;
149149
}
150-
}
150+
}

src/Codeception/Module/Asserts.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Codeception\Module;
66

77
use Throwable;
8+
89
use function get_debug_type;
910

1011
/**
@@ -26,6 +27,7 @@ class Asserts extends AbstractAsserts
2627
* $this->doSomethingBad();
2728
* });
2829
* ```
30+
*
2931
* If you want to check message or throwable code, you can pass them with throwable instance:
3032
* ```php
3133
* <?php
@@ -40,7 +42,7 @@ public function expectThrowable(string|Throwable $throwable, callable $callback)
4042
if (is_object($throwable)) {
4143
$class = get_class($throwable);
4244
$msg = $throwable->getMessage();
43-
$code = $throwable->getCode();
45+
$code = (int) $throwable->getCode();
4446
} else {
4547
$class = $throwable;
4648
$msg = null;
@@ -61,8 +63,12 @@ public function expectThrowable(string|Throwable $throwable, callable $callback)
6163
* Check if the given throwable matches the expected data,
6264
* fail (throws an exception) if it does not.
6365
*/
64-
protected function checkThrowable(Throwable $throwable, string $expectedClass, ?string $expectedMsg, int|null $expectedCode = null): void
65-
{
66+
protected function checkThrowable(
67+
Throwable $throwable,
68+
string $expectedClass,
69+
?string $expectedMsg,
70+
int|null $expectedCode = null
71+
): void {
6672
if (!($throwable instanceof $expectedClass)) {
6773
$this->fail(sprintf(
6874
"Exception of class '%s' expected to be thrown, but class '%s' was caught",

0 commit comments

Comments
 (0)