Skip to content

Commit 8049e6f

Browse files
committed
Code standards updated to PHP 7.1
1 parent d560943 commit 8049e6f

File tree

6 files changed

+45
-70
lines changed

6 files changed

+45
-70
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
11+
php: [7.1, 7.2, 7.3, 7.4, 8.0]
1212

1313
steps:
1414
- name: Checkout code

composer.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
{
2-
"name":"codeception/module-asserts",
3-
"description":"Codeception module containing various assertions",
4-
"keywords":["codeception", "asserts", "assertions"],
5-
"homepage":"https://codeception.com/",
6-
"type":"library",
7-
"license":"MIT",
8-
"authors":[
2+
"name": "codeception/module-asserts",
3+
"description": "Codeception module containing various assertions",
4+
"keywords": [ "codeception", "asserts", "assertions" ],
5+
"homepage": "https://codeception.com/",
6+
"type": "library",
7+
"license": "MIT",
8+
"authors": [
99
{
10-
"name":"Michael Bodnarchuk"
10+
"name": "Michael Bodnarchuk"
1111
},
1212
{
13-
"name":"Gintautas Miselis"
13+
"name": "Gintautas Miselis"
1414
},
1515
{
16-
"name":"Gustavo Nieves",
16+
"name": "Gustavo Nieves",
1717
"homepage": "https://medium.com/@ganieves"
1818
}
1919
],
2020
"minimum-stability": "RC",
2121
"require": {
22-
"php": ">=5.6.0 <9.0",
22+
"php": "^7.1 || ^8.0",
2323
"codeception/lib-asserts": "^1.13.1",
2424
"codeception/codeception": "*@dev"
2525
},
2626
"conflict": {
2727
"codeception/codeception": "<4.0"
2828
},
29-
"autoload":{
30-
"classmap": ["src/"]
29+
"autoload": {
30+
"classmap": [
31+
"src/"
32+
]
3133
},
3234
"config": {
3335
"classmap-authoritative": true

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
A Codeception module containing various assertions.
99

10+
## Requirements
11+
12+
* `PHP 7.1` or higher.
13+
1014
## Installation
1115

1216
```

src/Codeception/Module/AbstractAsserts.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Codeception\Module;
46

5-
use Codeception\Module as CodeceptionModule;
6-
use Codeception\Util\Shared\Asserts as SharedAsserts;
7+
use Codeception\Module;
8+
use Codeception\Util\Shared\Asserts;
79

8-
abstract class AbstractAsserts extends CodeceptionModule
10+
abstract class AbstractAsserts extends Module
911
{
10-
use SharedAsserts {
12+
use Asserts {
1113
assertArrayHasKey as public;
1214
assertArrayNotHasKey as public;
1315
assertClassHasAttribute as public;

src/Codeception/Module/Asserts.php

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,16 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Codeception\Module;
46

5-
use Codeception\Lib\Notification;
7+
use Throwable;
68

79
/**
810
* Special module for using asserts in your tests.
911
*/
1012
class Asserts extends AbstractAsserts
1113
{
12-
/**
13-
* Handles and checks exception called inside callback function.
14-
* Either exception class name or exception instance should be provided.
15-
*
16-
* ```php
17-
* <?php
18-
* $I->expectException(MyException::class, function() {
19-
* $this->doSomethingBad();
20-
* });
21-
*
22-
* $I->expectException(new MyException(), function() {
23-
* $this->doSomethingBad();
24-
* });
25-
* ```
26-
* If you want to check message or exception code, you can pass them with exception instance:
27-
* ```php
28-
* <?php
29-
* // will check that exception MyException is thrown with "Don't do bad things" message
30-
* $I->expectException(new MyException("Don't do bad things"), function() {
31-
* $this->doSomethingBad();
32-
* });
33-
* ```
34-
*
35-
* @deprecated Use expectThrowable() instead
36-
* @param \Exception|string $exception
37-
* @param callable $callback
38-
*/
39-
public function expectException($exception, $callback)
40-
{
41-
Notification::deprecate('Use expectThrowable() instead');
42-
$this->expectThrowable($exception, $callback);
43-
}
44-
4514
/**
4615
* Handles and checks throwables (Exceptions/Errors) called inside the callback function.
4716
* Either throwable class name or throwable instance should be provided.
@@ -65,10 +34,9 @@ public function expectException($exception, $callback)
6534
* });
6635
* ```
6736
*
68-
* @param \Throwable|string $throwable
69-
* @param callable $callback
37+
* @param Throwable|string $throwable
7038
*/
71-
public function expectThrowable($throwable, $callback)
39+
public function expectThrowable($throwable, callable $callback): void
7240
{
7341
if (is_object($throwable)) {
7442
$class = get_class($throwable);
@@ -82,45 +50,42 @@ public function expectThrowable($throwable, $callback)
8250

8351
try {
8452
$callback();
85-
} catch (\Exception $t) {
86-
$this->checkThrowable($t, $class, $msg, $code);
87-
return;
88-
} catch (\Throwable $t) {
53+
} catch (Throwable $t) {
8954
$this->checkThrowable($t, $class, $msg, $code);
9055
return;
9156
}
9257

93-
$this->fail("Expected throwable of class '$class' to be thrown, but nothing was caught");
58+
$this->fail("Expected throwable of class '{$class}' to be thrown, but nothing was caught");
9459
}
9560

9661
/**
9762
* Check if the given throwable matches the expected data,
9863
* fail (throws an exception) if it does not.
99-
*
100-
* @param \Throwable $throwable
101-
* @param string $expectedClass
102-
* @param string $expectedMsg
103-
* @param int $expectedCode
10464
*/
105-
protected function checkThrowable($throwable, $expectedClass, $expectedMsg, $expectedCode)
65+
protected function checkThrowable(Throwable $throwable, string $expectedClass, ?string $expectedMsg, ?int $expectedCode): void
10666
{
10767
if (!($throwable instanceof $expectedClass)) {
10868
$this->fail(sprintf(
109-
"Exception of class '$expectedClass' expected to be thrown, but class '%s' was caught",
69+
"Exception of class '%s' expected to be thrown, but class '%s' was caught",
70+
$expectedClass,
11071
get_class($throwable)
11172
));
11273
}
11374

11475
if (null !== $expectedMsg && $throwable->getMessage() !== $expectedMsg) {
11576
$this->fail(sprintf(
116-
"Exception of class '$expectedClass' expected to have message '$expectedMsg', but actual message was '%s'",
77+
"Exception of class '%s' expected to have message '%s', but actual message was '%s'",
78+
$expectedClass,
79+
$expectedMsg,
11780
$throwable->getMessage()
11881
));
11982
}
12083

12184
if (null !== $expectedCode && $throwable->getCode() !== $expectedCode) {
12285
$this->fail(sprintf(
123-
"Exception of class '$expectedClass' expected to have code '$expectedCode', but actual code was '%s'",
86+
"Exception of class '%s' expected to have code '%s', but actual code was '%s'",
87+
$expectedClass,
88+
$expectedCode,
12489
$throwable->getCode()
12590
));
12691
}

tests/unit/Codeception/Module/AssertsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace unit\Codeception\Module;
46

57
use Codeception\Lib\ModuleContainer;
@@ -11,7 +13,7 @@
1113
use RuntimeException;
1214
use stdClass;
1315

14-
class AssertsTest extends TestCase
16+
final class AssertsTest extends TestCase
1517
{
1618
/** @var Asserts */
1719
protected $module;

0 commit comments

Comments
 (0)