Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: CI

on: [push, pull_request]
on:
pull_request:

jobs:
tests:
Expand All @@ -27,11 +28,14 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest

- name: Build test actors
run: php vendor/bin/codecept build

- name: Run PHPStan
run: phpstan analyse src
run: phpstan

- name: Run PHPCS
run: phpcs --standard=PSR12 src
run: phpcs --standard=PSR12 src tests

- name: Run test suite
run: php vendor/bin/codecept run
62 changes: 62 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Automated release
on:
push:
branches:
- master
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 8.2, 8.3, 8.4 ]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: phpstan, phpcs

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest

- name: Run PHPStan
run: phpstan

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

- name: Run test suite
run: php vendor/bin/codecept run
release:
name: Automated release
needs:
- tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 22
- run: >
npx
-p "@semantic-release/commit-analyzer"
-p "@semantic-release/release-notes-generator"
-p conventional-changelog-conventionalcommits
-p semantic-release
-- semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
packages: write
contents: write
pull-requests: write
11 changes: 11 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"branches": ["master"],
"tagFormat": "${version}",
"plugins": [
["@semantic-release/commit-analyzer", {
"preset": "conventionalcommits",
"presetConfig": {}
}],
"@semantic-release/github",
"@semantic-release/release-notes-generator"]
}
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "Codeception module containing various assertions",
"license": "MIT",
"type": "library",
"prefer-stable": true,
"keywords": [
"codeception",
"asserts",
Expand All @@ -24,11 +25,15 @@
"require": {
"php": "^8.2",
"codeception/codeception": "*@dev",
"codeception/lib-asserts": "^2.2"
"phpunit/phpunit": "^11.5 | ^12",
"ext-dom": "*"
},
"conflict": {
"codeception/codeception": "<5.0"
},
"provide": {
"codeception/lib-asserts": "^2.2"
},
"minimum-stability": "dev",
"autoload": {
"classmap": [
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 9
paths:
- tests/
- src/
ignoreErrors:
- '#^Call to method Codeception\\Module\\AbstractAsserts::.*\(\) .*will always evaluate to.*$#'
1 change: 0 additions & 1 deletion src/Codeception/Module/AbstractAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ abstract class AbstractAsserts extends Module
assertMatchesRegularExpression as public;
assertNan as public;
assertNotContains as public;
assertNotContainsEquals as public;
assertNotContainsOnly as public;
assertNotCount as public;
assertNotEmpty as public;
Expand Down
111 changes: 111 additions & 0 deletions src/Codeception/Util/Shared/Asserts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

declare(strict_types=1);

namespace Codeception\Util\Shared;

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Constraint\Constraint as PHPUnitConstraint;
use PHPUnit\Framework\Constraint\LogicalNot;
use ReflectionClass;

trait Asserts
{
use InheritedAsserts;

/**
* @param array{0: string} $arguments
*/
protected function assert(array $arguments, bool $not = false): void
{
$not = $not ? 'Not' : '';
$method = ucfirst(array_shift($arguments));
if (($method === 'True') && $not) {
$method = 'False';
$not = '';
}

if (($method === 'False') && $not) {
$method = 'True';
$not = '';
}

$fullMethod = "assert{$not}{$method}";

$rc = new ReflectionClass(Assert::class);
if ($rc->hasMethod($fullMethod) && $rc->getMethod($fullMethod)->isStatic()) {
$rc->getMethod($fullMethod)->invokeArgs(null, $arguments);
} else {
throw new \RuntimeException("Method Assert::{$fullMethod} does not exist");
}
}

/**
* @param array{0: string} $arguments
* @return void
*/
protected function assertNot(array $arguments): void
{
$this->assert($arguments, true);
}

/**
* Asserts that a file does not exist.
*/
protected function assertFileNotExists(string $filename, string $message = ''): void
{
Assert::assertFileDoesNotExist($filename, $message);
}

/**
* Asserts that a value is greater than or equal to another value.
*
* @param mixed $expected
* @param mixed $actual
*/
protected function assertGreaterOrEquals($expected, $actual, string $message = ''): void
{
Assert::assertGreaterThanOrEqual($expected, $actual, $message);
}

/**
* Asserts that a variable is empty.
*/
protected function assertIsEmpty(mixed $actual, string $message = ''): void
{
Assert::assertEmpty($actual, $message);
}

/**
* Asserts that a value is smaller than or equal to another value.
*/
protected function assertLessOrEquals(mixed $expected, mixed $actual, string $message = ''): void
{
Assert::assertLessThanOrEqual($expected, $actual, $message);
}

/**
* Asserts that a string does not match a given regular expression.
*/
protected function assertNotRegExp(string $pattern, string $string, string $message = ''): void
{
Assert::assertDoesNotMatchRegularExpression($pattern, $string, $message);
}

/**
* Asserts that a string matches a given regular expression.
*/
protected function assertRegExp(string $pattern, string $string, string $message = ''): void
{
Assert::assertMatchesRegularExpression($pattern, $string, $message);
}

/**
* Evaluates a PHPUnit\Framework\Constraint matcher object.
*/
protected function assertThatItsNot(mixed $value, PHPUnitConstraint $constraint, string $message = ''): void
{
$constraint = new LogicalNot($constraint);
Assert::assertThat($value, $constraint, $message);
}
}
Loading