Skip to content

Commit fb4067e

Browse files
committed
feat!: import lib-asserts, drop it as a dependency, require phpunit 11.5 automated releases
1 parent eb1f7c9 commit fb4067e

File tree

9 files changed

+1562
-28
lines changed

9 files changed

+1562
-28
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
2929

3030
- name: Run PHPStan
31-
run: phpstan analyse src
31+
run: phpstan
3232

3333
- name: Run PHPCS
3434
run: phpcs --standard=PSR12 src

.github/workflows/release.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Automated release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
tests:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
php: [ 8.2, 8.3, 8.4 ]
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: ${{ matrix.php }}
20+
coverage: none
21+
tools: phpstan, phpcs
22+
23+
- name: Validate composer.json and composer.lock
24+
run: composer validate
25+
26+
- name: Install dependencies
27+
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
28+
29+
- name: Run PHPStan
30+
run: phpstan
31+
32+
- name: Run PHPCS
33+
run: phpcs --standard=PSR12 src
34+
35+
- name: Run test suite
36+
run: php vendor/bin/codecept run
37+
release:
38+
name: Automated release
39+
needs:
40+
- tests
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
persist-credentials: false
47+
- uses: actions/setup-node@v4
48+
with:
49+
node-version: 22
50+
- run: >
51+
npx
52+
-p "@semantic-release/commit-analyzer"
53+
-p "@semantic-release/release-notes-generator"
54+
-p conventional-changelog-conventionalcommits
55+
-p semantic-release
56+
-- semantic-release
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
permissions:
60+
packages: write
61+
contents: write
62+
pull-requests: write

.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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "Codeception module containing various assertions",
44
"license": "MIT",
55
"type": "library",
6+
"prefer-stable": true,
67
"keywords": [
78
"codeception",
89
"asserts",
@@ -24,11 +25,14 @@
2425
"require": {
2526
"php": "^8.2",
2627
"codeception/codeception": "*@dev",
27-
"codeception/lib-asserts": "^2.2"
28+
"phpunit/phpunit": "^11.5 | ^12"
2829
},
2930
"conflict": {
3031
"codeception/codeception": "<5.0"
3132
},
33+
"provide": {
34+
"codeception/lib-asserts": "^2.2"
35+
},
3236
"minimum-stability": "dev",
3337
"autoload": {
3438
"classmap": [

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/
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Codeception\Util\Shared;
6+
7+
use PHPUnit\Framework\Assert;
8+
use PHPUnit\Framework\Constraint\Constraint as PHPUnitConstraint;
9+
use PHPUnit\Framework\Constraint\LogicalNot;
10+
use ReflectionClass;
11+
12+
trait Asserts
13+
{
14+
use InheritedAsserts;
15+
16+
/**
17+
* @param array{0: string} $arguments
18+
*/
19+
protected function assert(array $arguments, bool $not = false): void
20+
{
21+
$not = $not ? 'Not' : '';
22+
$method = ucfirst(array_shift($arguments));
23+
if (($method === 'True') && $not) {
24+
$method = 'False';
25+
$not = '';
26+
}
27+
28+
if (($method === 'False') && $not) {
29+
$method = 'True';
30+
$not = '';
31+
}
32+
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+
}
41+
}
42+
43+
/**
44+
* @param array{0: string} $arguments
45+
* @return void
46+
*/
47+
protected function assertNot(array $arguments): void
48+
{
49+
$this->assert($arguments, true);
50+
}
51+
52+
/**
53+
* Asserts that a file does not exist.
54+
*/
55+
protected function assertFileNotExists(string $filename, string $message = ''): void
56+
{
57+
Assert::assertFileDoesNotExist($filename, $message);
58+
}
59+
60+
/**
61+
* Asserts that a value is greater than or equal to another value.
62+
*
63+
* @param mixed $expected
64+
* @param mixed $actual
65+
*/
66+
protected function assertGreaterOrEquals($expected, $actual, string $message = ''): void
67+
{
68+
Assert::assertGreaterThanOrEqual($expected, $actual, $message);
69+
}
70+
71+
/**
72+
* Asserts that a variable is empty.
73+
*/
74+
protected function assertIsEmpty(mixed $actual, string $message = ''): void
75+
{
76+
Assert::assertEmpty($actual, $message);
77+
}
78+
79+
/**
80+
* Asserts that a value is smaller than or equal to another value.
81+
*/
82+
protected function assertLessOrEquals(mixed $expected, mixed $actual, string $message = ''): void
83+
{
84+
Assert::assertLessThanOrEqual($expected, $actual, $message);
85+
}
86+
87+
/**
88+
* Asserts that a string does not match a given regular expression.
89+
*/
90+
protected function assertNotRegExp(string $pattern, string $string, string $message = ''): void
91+
{
92+
Assert::assertDoesNotMatchRegularExpression($pattern, $string, $message);
93+
}
94+
95+
/**
96+
* Asserts that a string matches a given regular expression.
97+
*/
98+
protected function assertRegExp(string $pattern, string $string, string $message = ''): void
99+
{
100+
Assert::assertMatchesRegularExpression($pattern, $string, $message);
101+
}
102+
103+
/**
104+
* Evaluates a PHPUnit\Framework\Constraint matcher object.
105+
*/
106+
protected function assertThatItsNot(mixed $value, PHPUnitConstraint $constraint, string $message = ''): void
107+
{
108+
$constraint = new LogicalNot($constraint);
109+
Assert::assertThat($value, $constraint, $message);
110+
}
111+
}

0 commit comments

Comments
 (0)