Skip to content

Commit 3680bd0

Browse files
authored
Merge pull request #15 from Codeception/cleanup
feat!: improve typing using phpstan drop phpunit < 11.5
2 parents 06750a6 + 6ec0f7f commit 3680bd0

File tree

6 files changed

+309
-272
lines changed

6 files changed

+309
-272
lines changed

.releaserc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"branches": ["master"],
3+
"tagFormat": "${version}",
4+
"plugins": [
5+
["@semantic-release/commit-analyzer", {
6+
"preset": "conventionalcommits",
7+
"presetConfig": {}
8+
}],
9+
"@semantic-release/github",
10+
"@semantic-release/release-notes-generator"]
11+
}

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"minimum-stability": "RC",
2323

2424
"require": {
25-
"php": "^7.4 | ^8.0",
26-
"ext-dom": "*",
27-
"codeception/phpunit-wrapper": "^7.7.1 | ^8.0.3 | ^9.0"
25+
"php": "^8.2 || ^8.3 || ^8.4",
26+
"phpunit/phpunit": "^11.5 || ^12.0",
27+
"ext-dom": "*"
2828
},
2929
"autoload":{
3030
"classmap": ["src/"]

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- tests/
5+
- src/

src/Codeception/Util/Shared/Asserts.php

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44

55
namespace Codeception\Util\Shared;
66

7-
use Codeception\PHPUnit\TestCase;
8-
use PHPUnit\Framework\Assert as PHPUnitAssert;
7+
use PHPUnit\Framework\Assert;
98
use PHPUnit\Framework\Constraint\Constraint as PHPUnitConstraint;
109
use PHPUnit\Framework\Constraint\LogicalNot;
10+
use ReflectionClass;
1111

1212
trait Asserts
1313
{
1414
use InheritedAsserts;
1515

16-
protected function assert(array $arguments, bool $not = false)
16+
/**
17+
* @param array{0: string} $arguments
18+
*/
19+
protected function assert(array $arguments, bool $not = false): void
1720
{
1821
$not = $not ? 'Not' : '';
1922
$method = ucfirst(array_shift($arguments));
@@ -27,20 +30,31 @@ protected function assert(array $arguments, bool $not = false)
2730
$not = '';
2831
}
2932

30-
call_user_func_array([PHPUnitAssert::class, 'assert' . $not . $method], $arguments);
33+
$fullMethod = "assert{$not}{$method}";
34+
35+
$rc = new ReflectionClass(Assert::class);
36+
if ($rc->hasMethod($fullMethod) && $rc->getMethod($fullMethod)->isStatic()) {
37+
$rc->getMethod($fullMethod)->invokeArgs(null, $arguments);
38+
} else {
39+
throw new \RuntimeException("Method Assert::{$fullMethod} does not exist");
40+
}
3141
}
3242

33-
protected function assertNot($arguments)
43+
/**
44+
* @param array{0: string} $arguments
45+
* @return void
46+
*/
47+
protected function assertNot(array $arguments): void
3448
{
3549
$this->assert($arguments, true);
3650
}
3751

3852
/**
3953
* Asserts that a file does not exist.
4054
*/
41-
protected function assertFileNotExists(string $filename, string $message = '')
55+
protected function assertFileNotExists(string $filename, string $message = ''): void
4256
{
43-
TestCase::assertFileDoesNotExist($filename, $message);
57+
Assert::assertFileDoesNotExist($filename, $message);
4458
}
4559

4660
/**
@@ -49,56 +63,49 @@ protected function assertFileNotExists(string $filename, string $message = '')
4963
* @param mixed $expected
5064
* @param mixed $actual
5165
*/
52-
protected function assertGreaterOrEquals($expected, $actual, string $message = '')
66+
protected function assertGreaterOrEquals($expected, $actual, string $message = ''): void
5367
{
54-
TestCase::assertGreaterThanOrEqual($expected, $actual, $message);
68+
Assert::assertGreaterThanOrEqual($expected, $actual, $message);
5569
}
5670

5771
/**
5872
* Asserts that a variable is empty.
59-
*
60-
* @param mixed $actual
6173
*/
62-
protected function assertIsEmpty($actual, string $message = '')
74+
protected function assertIsEmpty(mixed $actual, string $message = ''): void
6375
{
64-
TestCase::assertEmpty($actual, $message);
76+
Assert::assertEmpty($actual, $message);
6577
}
6678

6779
/**
6880
* Asserts that a value is smaller than or equal to another value.
69-
*
70-
* @param mixed $expected
71-
* @param mixed $actual
7281
*/
73-
protected function assertLessOrEquals($expected, $actual, string $message = '')
82+
protected function assertLessOrEquals(mixed $expected, mixed $actual, string $message = ''): void
7483
{
75-
TestCase::assertLessThanOrEqual($expected, $actual, $message);
84+
Assert::assertLessThanOrEqual($expected, $actual, $message);
7685
}
7786

7887
/**
7988
* Asserts that a string does not match a given regular expression.
8089
*/
81-
protected function assertNotRegExp(string $pattern, string $string, string $message = '')
90+
protected function assertNotRegExp(string $pattern, string $string, string $message = ''): void
8291
{
83-
TestCase::assertDoesNotMatchRegularExpression($pattern, $string, $message);
92+
Assert::assertDoesNotMatchRegularExpression($pattern, $string, $message);
8493
}
8594

8695
/**
8796
* Asserts that a string matches a given regular expression.
8897
*/
89-
protected function assertRegExp(string $pattern, string $string, string $message = '')
98+
protected function assertRegExp(string $pattern, string $string, string $message = ''): void
9099
{
91-
TestCase::assertMatchesRegularExpression($pattern, $string, $message);
100+
Assert::assertMatchesRegularExpression($pattern, $string, $message);
92101
}
93102

94103
/**
95104
* Evaluates a PHPUnit\Framework\Constraint matcher object.
96-
*
97-
* @param mixed $value
98105
*/
99-
protected function assertThatItsNot($value, PHPUnitConstraint $constraint, string $message = '')
106+
protected function assertThatItsNot(mixed $value, PHPUnitConstraint $constraint, string $message = ''): void
100107
{
101108
$constraint = new LogicalNot($constraint);
102-
TestCase::assertThat($value, $constraint, $message);
109+
Assert::assertThat($value, $constraint, $message);
103110
}
104111
}

0 commit comments

Comments
 (0)