From 987dd5a4eb61d2fb679d11dec64ff3f3313ac846 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 4 Feb 2023 08:49:13 +0000 Subject: [PATCH 1/2] Use PHPUnit 9.6 to run Symfony's test suite --- phpunit | 6 ++---- .../ConfigurationTest.php | 20 ++++++++++++++++--- .../Extension/Core/Type/ButtonTypeTest.php | 2 +- .../Extension/Core/Type/FormTypeTest.php | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/phpunit b/phpunit index e26fecd73cc9d..3ab931750e179 100755 --- a/phpunit +++ b/phpunit @@ -10,12 +10,10 @@ if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) { exit(1); } if (!getenv('SYMFONY_PHPUNIT_VERSION')) { - if (\PHP_VERSION_ID < 70200) { - putenv('SYMFONY_PHPUNIT_VERSION=7.5'); - } elseif (\PHP_VERSION_ID < 70300) { + if (\PHP_VERSION_ID < 70300) { putenv('SYMFONY_PHPUNIT_VERSION=8.5.26'); } else { - putenv('SYMFONY_PHPUNIT_VERSION=9.5'); + putenv('SYMFONY_PHPUNIT_VERSION=9.6'); } } if (!getenv('SYMFONY_PATCH_TYPE_DECLARATIONS') && \PHP_VERSION_ID >= 70300) { diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php index a5e2fc8951875..9263a0b1ca23c 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php @@ -482,10 +482,24 @@ public function testBaselineFileWriteError() { $filename = $this->createFile(); chmod($filename, 0444); - $this->expectError(); - $this->expectErrorMessageMatches('/[Ff]ailed to open stream: Permission denied/'); $configuration = Configuration::fromUrlEncodedString('generateBaseline=true&baselineFile='.urlencode($filename)); - $configuration->writeBaseline(); + + $this->expectException(\ErrorException::class); + $this->expectExceptionMessageMatches('/[Ff]ailed to open stream: Permission denied/'); + + set_error_handler(static function(int $errno, string $errstr, string $errfile = null, int $errline = null) { + if ($errno & (E_WARNING | E_WARNING)) { + throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); + } + + return false; + }); + + try { + $configuration->writeBaseline(); + } finally { + restore_error_handler(); + } } public function testExistingIgnoreFile() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php index afb5f820827d8..0125631c582c6 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php @@ -72,7 +72,7 @@ public function testFormAttrOnChild() public function testFormAttrAsBoolWithNoId() { $this->expectException(LogicException::class); - $this->expectErrorMessage('form_attr'); + $this->expectExceptionMessage('form_attr'); $this->factory ->createNamedBuilder('', FormType::class, null, [ 'form_attr' => true, diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 3f535d89a5cbc..1d2ff4ff12003 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -809,7 +809,7 @@ public function testFormAttrOnChild() public function testFormAttrAsBoolWithNoId() { $this->expectException(LogicException::class); - $this->expectErrorMessage('form_attr'); + $this->expectExceptionMessage('form_attr'); $this->factory ->createNamedBuilder('', self::TESTED_TYPE, null, [ 'form_attr' => true, From d43f48b8a9f494a81a77cd1e0b2fecb027854375 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 14 Feb 2023 23:28:43 +0100 Subject: [PATCH 2/2] 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());