Skip to content

Commit 353189a

Browse files
authored
Update codebase to PHP 7.4 (#15)
1 parent 540ea60 commit 353189a

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
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: [7.1, 7.2, 7.3, 7.4, 8.0]
11+
php: [7.4, 8.0, 8.1]
1212

1313
steps:
1414
- name: Checkout code

AssertThrows.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace Codeception;
46

@@ -8,10 +10,6 @@
810

911
trait AssertThrows
1012
{
11-
/**
12-
* @param string|null $message
13-
* @param Throwable $exception
14-
*/
1513
private function checkException(?string $message, Throwable $exception)
1614
{
1715
$actualMessage = strtolower($exception->getMessage());
@@ -32,12 +30,12 @@ private function checkException(?string $message, Throwable $exception)
3230
/**
3331
* Asserts that callback throws an exception
3432
*
35-
* @param $throws
33+
* @param string|Throwable $throws
3634
* @param callable $func
3735
* @param mixed ...$params
3836
* @throws Throwable
3937
*/
40-
public function assertThrows($throws, callable $func, ...$params)
38+
public function assertThrows($throws, callable $func, array $params = [])
4139
{
4240
$this->assertThrowsWithMessage($throws, null, $func, $params);
4341
}
@@ -51,7 +49,7 @@ public function assertThrows($throws, callable $func, ...$params)
5149
* @param mixed ...$params
5250
* @throws Throwable
5351
*/
54-
public function assertThrowsWithMessage($throws, ?string $message, callable $func, ...$params)
52+
public function assertThrowsWithMessage($throws, ?string $message, callable $func, array $params = [])
5553
{
5654
if ($throws instanceof Throwable) {
5755
$message = $throws->getMessage();
@@ -63,7 +61,7 @@ public function assertThrowsWithMessage($throws, ?string $message, callable $fun
6361
}
6462

6563
try {
66-
if ($params) {
64+
if ($params !== []) {
6765
call_user_func_array($func, $params);
6866
} else {
6967
call_user_func($func);
@@ -119,7 +117,7 @@ public function assertThrowsWithMessage($throws, ?string $message, callable $fun
119117
* @param callable $func
120118
* @param mixed ...$params
121119
*/
122-
public function assertDoesNotThrow($throws, callable $func, ...$params)
120+
public function assertDoesNotThrow($throws, callable $func, array $params = [])
123121
{
124122
$this->assertDoesNotThrowWithMessage($throws, null, $func, $params);
125123
}
@@ -132,15 +130,15 @@ public function assertDoesNotThrow($throws, callable $func, ...$params)
132130
* @param callable $func
133131
* @param mixed ...$params
134132
*/
135-
public function assertDoesNotThrowWithMessage($throws, ?string $message, callable $func, ...$params)
133+
public function assertDoesNotThrowWithMessage($throws, ?string $message, callable $func, array $params = [])
136134
{
137135
if ($throws instanceof Throwable) {
138136
$message = $throws->getMessage();
139137
$throws = get_class($throws);
140138
}
141139

142140
try {
143-
if ($params) {
141+
if ($params !== []) {
144142
call_user_func_array($func, $params);
145143
} else {
146144
call_user_func($func);
@@ -165,7 +163,7 @@ public function assertDoesNotThrowWithMessage($throws, ?string $message, callabl
165163

166164
$actualMessage = $exception->getMessage();
167165

168-
if ($message != $actualMessage) {
166+
if ($message !== $actualMessage) {
169167
Assert::assertNotSame($message, $actualMessage);
170168
return;
171169
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require": {
17-
"phpunit/phpunit": "^7.5|^8.0|^9.0"
17+
"phpunit/phpunit": "^8.0|^9.0"
1818
},
1919
"autoload": {
2020
"psr-4": {

tests/AssertThrowsTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
use Codeception\AssertThrows;
46
use PHPUnit\Framework\Assert;
@@ -35,13 +37,14 @@ public function testExceptionMessageFails()
3537
$this->assertThrowsWithMessage(MyException::class, 'hello', function() {
3638
throw new MyException('hallo');
3739
});
38-
} catch (AssertionFailedError $e) {
40+
} catch (AssertionFailedError $error) {
3941
$this->assertEquals(
4042
"Exception message 'hello' was expected, but 'hallo' was received",
41-
$e->getMessage()
43+
$error->getMessage()
4244
);
4345
return;
4446
}
47+
4548
$this->fail('Ups :(');
4649
}
4750

@@ -66,12 +69,11 @@ public function testAssertThrowsWithParams()
6669
Exception::class,
6770
'foobar',
6871
$func,
69-
'foo',
70-
'bar'
72+
['foo', 'bar']
7173
);
7274
}
7375

74-
public function testAssertDoesNotThrow(): void
76+
public function testAssertDoesNotThrow()
7577
{
7678
$func = function (): void {
7779
throw new Exception('foo');
@@ -88,7 +90,6 @@ public function testAssertDoesNotThrow(): void
8890
}
8991
}
9092

91-
9293
final class MyException extends Exception {
9394

94-
}
95+
}

0 commit comments

Comments
 (0)