Skip to content

Update codebase to PHP 7.4 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2021
Merged
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"minimum-stability": "RC",

"require": {
"php": ">=5.6.0 <9.0",
"php": "^7.4 | ^8.0",
"ext-dom": "*",
"codeception/phpunit-wrapper": ">6.0.15 <6.1.0 | ^6.6.1 | ^7.7.1 | ^8.0.3 | ^9.0"
"codeception/phpunit-wrapper": "^7.7.1 | ^8.0.3 | ^9.0"
},
"autoload":{
"classmap": ["src/"]
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Library shared by Codeception core and Asserts module
# Codeception Lib Asserts

Library shared by Codeception core and Asserts module.

## Installation

Expand Down
62 changes: 23 additions & 39 deletions src/Codeception/Util/Shared/Asserts.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?php

declare(strict_types=1);

namespace Codeception\Util\Shared;

use Codeception\PHPUnit\TestCase;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Assert as PHPUnitAssert;
use PHPUnit\Framework\Constraint\Constraint as PHPUnitConstraint;
use PHPUnit\Framework\Constraint\LogicalNot;

trait Asserts
{
use InheritedAsserts;

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

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

call_user_func_array(['\PHPUnit\Framework\Assert', 'assert' . $not . $method], $arguments);
call_user_func_array([PHPUnitAssert::class, 'assert' . $not . $method], $arguments);
}

protected function assertNot($arguments)
Expand All @@ -37,82 +37,66 @@ protected function assertNot($arguments)

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

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

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

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

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

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

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