From a6896fa9f031d4aff289dbe7a94b0d1ab8e8b036 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 14 Feb 2023 23:28:43 +0100 Subject: [PATCH] Fix PHPUnit 9.6 deprecations --- .../Tests/ExpressionLanguageTest.php | 19 ++++++++++++++++--- .../Transport/InfobipApiTransportTest.php | 6 +++--- .../Transport/MailgunHttpTransportTest.php | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php index 3daaf63b08a6d..e0cfeef6c372b 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php @@ -311,12 +311,25 @@ public function testNullSafeEvaluateFails($expression, $foo, $message) /** * @dataProvider provideInvalidNullSafe */ - public function testNullSafeCompileFails($expression, $foo) + public function testNullSafeCompileFails($expression) { $expressionLanguage = new ExpressionLanguage(); - $this->expectWarning(); - eval(sprintf('return %s;', $expressionLanguage->compile($expression, ['foo' => 'foo']))); + $this->expectException(\ErrorException::class); + + set_error_handler(static function (int $errno, string $errstr, string $errfile = null, int $errline = null): bool { + if ($errno & (\E_WARNING | \E_USER_WARNING)) { + throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); + } + + return false; + }); + + try { + eval(sprintf('return %s;', $expressionLanguage->compile($expression, ['foo' => 'foo']))); + } finally { + restore_error_handler(); + } } public static function provideInvalidNullSafe() diff --git a/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php b/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php index 107f5d406075c..2218479d6087b 100644 --- a/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php @@ -373,7 +373,7 @@ public function testInfobipResponseShouldNotBeEmpty() $email = $this->basicValidEmail(); $this->expectException(HttpTransportException::class); - $this->expectDeprecationMessage('Unable to send an email: ""'); + $this->expectExceptionMessage('Unable to send an email: ""'); $this->transport->send($email); } @@ -384,7 +384,7 @@ public function testInfobipResponseShouldBeStatusCode200() $email = $this->basicValidEmail(); $this->expectException(HttpTransportException::class); - $this->expectDeprecationMessage('Unable to send an email: "{"requestError": {"serviceException": {"messageId": "string","text": "string"}}}" (code 400)'); + $this->expectExceptionMessage('Unable to send an email: "{"requestError": {"serviceException": {"messageId": "string","text": "string"}}}" (code 400)'); $this->transport->send($email); } @@ -395,7 +395,7 @@ public function testInfobipHttpConnectionFailed() $email = $this->basicValidEmail(); $this->expectException(HttpTransportException::class); - $this->expectDeprecationMessage('Could not reach the remote Infobip server.'); + $this->expectExceptionMessage('Could not reach the remote Infobip server.'); $this->transport->send($email); } diff --git a/src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunHttpTransportTest.php b/src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunHttpTransportTest.php index 370fb38da242b..85342c23368d6 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunHttpTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunHttpTransportTest.php @@ -132,8 +132,8 @@ public function testTagAndMetadataHeaders() $this->assertCount(4, $email->getHeaders()->toArray()); $this->assertSame('foo: bar', $email->getHeaders()->get('foo')->toString()); - $this->assertCount(2, $email->getHeaders()->all('X-Mailgun-Tag')); $tagHeaders = iterator_to_array($email->getHeaders()->all('X-Mailgun-Tag')); + $this->assertCount(2, $tagHeaders); $this->assertSame('X-Mailgun-Tag: password-reset', $tagHeaders[0]->toString()); $this->assertSame('X-Mailgun-Tag: product-name', $tagHeaders[1]->toString()); $this->assertSame('X-Mailgun-Variables: '.json_encode(['Color' => 'blue', 'Client-ID' => '12345']), $email->getHeaders()->get('X-Mailgun-Variables')->toString());