Skip to content

Commit eb1f7c9

Browse files
authored
Merge pull request #31 from Codeception/fix_tests
Update to PHP 8.2, Codeception 5 and static analysis
2 parents a499352 + b05b628 commit eb1f7c9

File tree

20 files changed

+81
-51
lines changed

20 files changed

+81
-51
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,30 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [8.1, 8.2, 8.3, 8.4]
11+
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

codeception.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
namespace: Tests
2+
support_namespace: Support
3+
4+
settings:
5+
shuffle: true
6+
lint: true
17
paths:
28
tests: tests
39
output: tests/_output
4-
data: tests/_data
5-
support: tests/_support
6-
envs: tests/_envs
7-
actor_suffix: Tester
10+
support: tests/Support
11+
data: tests/Support/Data
12+

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
"homepage": "https://codeception.com/",
2424
"require": {
25-
"php": "^8.1",
25+
"php": "^8.2",
2626
"codeception/codeception": "*@dev",
2727
"codeception/lib-asserts": "^2.2"
2828
},

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A Codeception module containing various assertions.
99

1010
## Requirements
1111

12-
* `PHP 8.1` or higher.
12+
* `PHP 8.2` or higher.
1313

1414
## Installation
1515

src/Codeception/Module/AbstractAsserts.php

Lines changed: 1 addition & 1 deletion
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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Codeception\Module;
66

7+
use Throwable;
8+
9+
use function get_debug_type;
10+
711
/**
812
* Special module for using asserts in your tests.
913
*/
@@ -23,6 +27,7 @@ class Asserts extends AbstractAsserts
2327
* $this->doSomethingBad();
2428
* });
2529
* ```
30+
*
2631
* If you want to check message or throwable code, you can pass them with throwable instance:
2732
* ```php
2833
* <?php
@@ -31,15 +36,13 @@ class Asserts extends AbstractAsserts
3136
* $this->doSomethingBad();
3237
* });
3338
* ```
34-
*
35-
* @param \Throwable|string $throwable
3639
*/
37-
public function expectThrowable($throwable, callable $callback): void
40+
public function expectThrowable(string|Throwable $throwable, callable $callback): void
3841
{
3942
if (is_object($throwable)) {
4043
$class = get_class($throwable);
4144
$msg = $throwable->getMessage();
42-
$code = $throwable->getCode();
45+
$code = (int) $throwable->getCode();
4346
} else {
4447
$class = $throwable;
4548
$msg = null;
@@ -48,7 +51,7 @@ public function expectThrowable($throwable, callable $callback): void
4851

4952
try {
5053
$callback();
51-
} catch (\Throwable $t) {
54+
} catch (Throwable $t) {
5255
$this->checkThrowable($t, $class, $msg, $code);
5356
return;
5457
}
@@ -60,13 +63,17 @@ public function expectThrowable($throwable, callable $callback): void
6063
* Check if the given throwable matches the expected data,
6164
* fail (throws an exception) if it does not.
6265
*/
63-
protected function checkThrowable(\Throwable $throwable, string $expectedClass, ?string $expectedMsg, $expectedCode = null): void
64-
{
66+
protected function checkThrowable(
67+
Throwable $throwable,
68+
string $expectedClass,
69+
?string $expectedMsg,
70+
int|null $expectedCode = null
71+
): void {
6572
if (!($throwable instanceof $expectedClass)) {
6673
$this->fail(sprintf(
6774
"Exception of class '%s' expected to be thrown, but class '%s' was caught",
6875
$expectedClass,
69-
get_class($throwable)
76+
get_debug_type($throwable)
7077
));
7178
}
7279

tests/_data/DummyClass.php renamed to tests/Support/Data/DummyClass.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
declare(strict_types=1);
44

5+
namespace Support\Data;
6+
57
class DummyClass
68
{
79
private int $foo;
8-
10+
911
private static int $staticFoo;
1012
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)