diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5d4e738..bfbad11 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0] + php: [7.1, 7.2, 7.3, 7.4, 8.0] steps: - name: Checkout code diff --git a/composer.json b/composer.json index aaea20e..c65a50d 100644 --- a/composer.json +++ b/composer.json @@ -1,33 +1,35 @@ { - "name":"codeception/module-asserts", - "description":"Codeception module containing various assertions", - "keywords":["codeception", "asserts", "assertions"], - "homepage":"https://codeception.com/", - "type":"library", - "license":"MIT", - "authors":[ + "name": "codeception/module-asserts", + "description": "Codeception module containing various assertions", + "keywords": [ "codeception", "asserts", "assertions" ], + "homepage": "https://codeception.com/", + "type": "library", + "license": "MIT", + "authors": [ { - "name":"Michael Bodnarchuk" + "name": "Michael Bodnarchuk" }, { - "name":"Gintautas Miselis" + "name": "Gintautas Miselis" }, { - "name":"Gustavo Nieves", + "name": "Gustavo Nieves", "homepage": "https://medium.com/@ganieves" } ], "minimum-stability": "RC", "require": { - "php": ">=5.6.0 <9.0", + "php": "^7.1 || ^8.0", "codeception/lib-asserts": "^1.13.1", "codeception/codeception": "*@dev" }, "conflict": { "codeception/codeception": "<4.0" }, - "autoload":{ - "classmap": ["src/"] + "autoload": { + "classmap": [ + "src/" + ] }, "config": { "classmap-authoritative": true diff --git a/readme.md b/readme.md index ed6cb52..55cd0fc 100644 --- a/readme.md +++ b/readme.md @@ -7,6 +7,10 @@ A Codeception module containing various assertions. +## Requirements + +* `PHP 7.1` or higher. + ## Installation ``` diff --git a/src/Codeception/Module/AbstractAsserts.php b/src/Codeception/Module/AbstractAsserts.php index 9704d5c..6855f3a 100644 --- a/src/Codeception/Module/AbstractAsserts.php +++ b/src/Codeception/Module/AbstractAsserts.php @@ -1,13 +1,15 @@ expectException(MyException::class, function() { - * $this->doSomethingBad(); - * }); - * - * $I->expectException(new MyException(), function() { - * $this->doSomethingBad(); - * }); - * ``` - * If you want to check message or exception code, you can pass them with exception instance: - * ```php - * expectException(new MyException("Don't do bad things"), function() { - * $this->doSomethingBad(); - * }); - * ``` - * - * @deprecated Use expectThrowable() instead - * @param \Exception|string $exception - * @param callable $callback - */ - public function expectException($exception, $callback) - { - Notification::deprecate('Use expectThrowable() instead'); - $this->expectThrowable($exception, $callback); - } - /** * Handles and checks throwables (Exceptions/Errors) called inside the callback function. * Either throwable class name or throwable instance should be provided. @@ -65,10 +34,9 @@ public function expectException($exception, $callback) * }); * ``` * - * @param \Throwable|string $throwable - * @param callable $callback + * @param Throwable|string $throwable */ - public function expectThrowable($throwable, $callback) + public function expectThrowable($throwable, callable $callback): void { if (is_object($throwable)) { $class = get_class($throwable); @@ -82,45 +50,42 @@ public function expectThrowable($throwable, $callback) try { $callback(); - } catch (\Exception $t) { - $this->checkThrowable($t, $class, $msg, $code); - return; - } catch (\Throwable $t) { + } catch (Throwable $t) { $this->checkThrowable($t, $class, $msg, $code); return; } - $this->fail("Expected throwable of class '$class' to be thrown, but nothing was caught"); + $this->fail("Expected throwable of class '{$class}' to be thrown, but nothing was caught"); } /** * Check if the given throwable matches the expected data, * fail (throws an exception) if it does not. - * - * @param \Throwable $throwable - * @param string $expectedClass - * @param string $expectedMsg - * @param int $expectedCode */ - protected function checkThrowable($throwable, $expectedClass, $expectedMsg, $expectedCode) + protected function checkThrowable(Throwable $throwable, string $expectedClass, ?string $expectedMsg, ?int $expectedCode): void { if (!($throwable instanceof $expectedClass)) { $this->fail(sprintf( - "Exception of class '$expectedClass' expected to be thrown, but class '%s' was caught", + "Exception of class '%s' expected to be thrown, but class '%s' was caught", + $expectedClass, get_class($throwable) )); } if (null !== $expectedMsg && $throwable->getMessage() !== $expectedMsg) { $this->fail(sprintf( - "Exception of class '$expectedClass' expected to have message '$expectedMsg', but actual message was '%s'", + "Exception of class '%s' expected to have message '%s', but actual message was '%s'", + $expectedClass, + $expectedMsg, $throwable->getMessage() )); } if (null !== $expectedCode && $throwable->getCode() !== $expectedCode) { $this->fail(sprintf( - "Exception of class '$expectedClass' expected to have code '$expectedCode', but actual code was '%s'", + "Exception of class '%s' expected to have code '%s', but actual code was '%s'", + $expectedClass, + $expectedCode, $throwable->getCode() )); } diff --git a/tests/unit/Codeception/Module/AssertsTest.php b/tests/unit/Codeception/Module/AssertsTest.php index cb00cbe..48230d9 100644 --- a/tests/unit/Codeception/Module/AssertsTest.php +++ b/tests/unit/Codeception/Module/AssertsTest.php @@ -1,5 +1,7 @@