From 353189ac0effe8af20b792d82dd7c0d1587426fc Mon Sep 17 00:00:00 2001 From: Gustavo Nieves <64917965+TavoNiievez@users.noreply.github.com> Date: Fri, 3 Dec 2021 07:39:36 -0500 Subject: [PATCH] Update codebase to PHP 7.4 (#15) --- .github/workflows/main.yml | 2 +- AssertThrows.php | 24 +++++++++++------------- composer.json | 2 +- tests/AssertThrowsTest.php | 17 +++++++++-------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9a0040e..c8293a6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php: [7.1, 7.2, 7.3, 7.4, 8.0] + php: [7.4, 8.0, 8.1] steps: - name: Checkout code diff --git a/AssertThrows.php b/AssertThrows.php index bffbb57..e2fc16e 100644 --- a/AssertThrows.php +++ b/AssertThrows.php @@ -1,4 +1,6 @@ -getMessage()); @@ -32,12 +30,12 @@ private function checkException(?string $message, Throwable $exception) /** * Asserts that callback throws an exception * - * @param $throws + * @param string|Throwable $throws * @param callable $func * @param mixed ...$params * @throws Throwable */ - public function assertThrows($throws, callable $func, ...$params) + public function assertThrows($throws, callable $func, array $params = []) { $this->assertThrowsWithMessage($throws, null, $func, $params); } @@ -51,7 +49,7 @@ public function assertThrows($throws, callable $func, ...$params) * @param mixed ...$params * @throws Throwable */ - public function assertThrowsWithMessage($throws, ?string $message, callable $func, ...$params) + public function assertThrowsWithMessage($throws, ?string $message, callable $func, array $params = []) { if ($throws instanceof Throwable) { $message = $throws->getMessage(); @@ -63,7 +61,7 @@ public function assertThrowsWithMessage($throws, ?string $message, callable $fun } try { - if ($params) { + if ($params !== []) { call_user_func_array($func, $params); } else { call_user_func($func); @@ -119,7 +117,7 @@ public function assertThrowsWithMessage($throws, ?string $message, callable $fun * @param callable $func * @param mixed ...$params */ - public function assertDoesNotThrow($throws, callable $func, ...$params) + public function assertDoesNotThrow($throws, callable $func, array $params = []) { $this->assertDoesNotThrowWithMessage($throws, null, $func, $params); } @@ -132,7 +130,7 @@ public function assertDoesNotThrow($throws, callable $func, ...$params) * @param callable $func * @param mixed ...$params */ - public function assertDoesNotThrowWithMessage($throws, ?string $message, callable $func, ...$params) + public function assertDoesNotThrowWithMessage($throws, ?string $message, callable $func, array $params = []) { if ($throws instanceof Throwable) { $message = $throws->getMessage(); @@ -140,7 +138,7 @@ public function assertDoesNotThrowWithMessage($throws, ?string $message, callabl } try { - if ($params) { + if ($params !== []) { call_user_func_array($func, $params); } else { call_user_func($func); @@ -165,7 +163,7 @@ public function assertDoesNotThrowWithMessage($throws, ?string $message, callabl $actualMessage = $exception->getMessage(); - if ($message != $actualMessage) { + if ($message !== $actualMessage) { Assert::assertNotSame($message, $actualMessage); return; } diff --git a/composer.json b/composer.json index f40695e..9d5e322 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "phpunit/phpunit": "^7.5|^8.0|^9.0" + "phpunit/phpunit": "^8.0|^9.0" }, "autoload": { "psr-4": { diff --git a/tests/AssertThrowsTest.php b/tests/AssertThrowsTest.php index f6eea0d..51d655d 100644 --- a/tests/AssertThrowsTest.php +++ b/tests/AssertThrowsTest.php @@ -1,4 +1,6 @@ -assertThrowsWithMessage(MyException::class, 'hello', function() { throw new MyException('hallo'); }); - } catch (AssertionFailedError $e) { + } catch (AssertionFailedError $error) { $this->assertEquals( "Exception message 'hello' was expected, but 'hallo' was received", - $e->getMessage() + $error->getMessage() ); return; } + $this->fail('Ups :('); } @@ -66,12 +69,11 @@ public function testAssertThrowsWithParams() Exception::class, 'foobar', $func, - 'foo', - 'bar' + ['foo', 'bar'] ); } - public function testAssertDoesNotThrow(): void + public function testAssertDoesNotThrow() { $func = function (): void { throw new Exception('foo'); @@ -88,7 +90,6 @@ public function testAssertDoesNotThrow(): void } } - final class MyException extends Exception { -} \ No newline at end of file +}