Skip to content
Snippets Groups Projects
Verified Commit 7fda601b authored by Dave Long's avatar Dave Long
Browse files

Issue #3477366 by andypost: Fix closures in tests for PHP 8.4

(cherry picked from commit 4b330801)
parent 3085a932
No related branches found
No related tags found
1 merge request!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4
Pipeline #338247 passed with warnings
Pipeline: drupal

#338287

    Pipeline: drupal

    #338284

      Pipeline: drupal

      #338280

        +7
        ...@@ -127,9 +127,14 @@ public function testExceptionHandler(): void { ...@@ -127,9 +127,14 @@ public function testExceptionHandler(): void {
        '%line' => 56, '%line' => 56,
        '%file' => $this->getModulePath('error_test') . '/error_test.module', '%file' => $this->getModulePath('error_test') . '/error_test.module',
        ]; ];
        $select = \Drupal::database()->select('bananas_are_awesome', 'b')->fields('b');
        $message = \Drupal::database()->prepareStatement((string) $select, [])->getQueryString();
        $message = str_replace(["\r", "\n"], ' ', $message);
        $error_pdo_exception = [ $error_pdo_exception = [
        '%type' => 'DatabaseExceptionWrapper', '%type' => 'DatabaseExceptionWrapper',
        '@message' => 'SELECT "b".* FROM {bananas_are_awesome} "b"', '@message' => PHP_VERSION_ID >= 80400 ?
        $message :
        'SELECT "b".* FROM {bananas_are_awesome} "b"',
        '%function' => 'Drupal\error_test\Controller\ErrorTestController->triggerPDOException()', '%function' => 'Drupal\error_test\Controller\ErrorTestController->triggerPDOException()',
        '%line' => 64, '%line' => 64,
        '%file' => $this->getModulePath('error_test') . '/error_test.module', '%file' => $this->getModulePath('error_test') . '/error_test.module',
        ...@@ -137,7 +142,9 @@ public function testExceptionHandler(): void { ...@@ -137,7 +142,9 @@ public function testExceptionHandler(): void {
        $error_renderer_exception = [ $error_renderer_exception = [
        '%type' => 'Exception', '%type' => 'Exception',
        '@message' => 'This is an exception that occurs during rendering', '@message' => 'This is an exception that occurs during rendering',
        '%function' => 'Drupal\error_test\Controller\ErrorTestController->Drupal\error_test\Controller\{closure}()', '%function' => PHP_VERSION_ID >= 80400 ?
        'Drupal\error_test\Controller\ErrorTestController->{closure:Drupal\error_test\Controller\ErrorTestController::triggerRendererException():102}()' :
        'Drupal\error_test\Controller\ErrorTestController->Drupal\error_test\Controller\{closure}()',
        '%line' => 82, '%line' => 82,
        '%file' => $this->getModulePath('error_test') . '/error_test.module', '%file' => $this->getModulePath('error_test') . '/error_test.module',
        ]; ];
        ......
        ...@@ -92,11 +92,20 @@ public function testUncaughtException(): void { ...@@ -92,11 +92,20 @@ public function testUncaughtException(): void {
        * Tests displaying an uncaught fatal error. * Tests displaying an uncaught fatal error.
        */ */
        public function testUncaughtFatalError(): void { public function testUncaughtFatalError(): void {
        $fatal_error = [ if (PHP_VERSION_ID >= 80400) {
        '%type' => 'TypeError', $fatal_error = [
        '@message' => 'Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}(): Argument #1 ($test) must be of type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 65', '%type' => 'TypeError',
        '%function' => 'Drupal\error_test\Controller\ErrorTestController->Drupal\error_test\Controller\{closure}()', '@message' => 'Drupal\error_test\Controller\ErrorTestController::{closure:Drupal\error_test\Controller\ErrorTestController::generateFatalErrors():62}(): Argument #1 ($test) must be of type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 65',
        ]; '%function' => 'Drupal\error_test\Controller\ErrorTestController->{closure:Drupal\error_test\Controller\ErrorTestController::generateFatalErrors():62}()',
        ];
        }
        else {
        $fatal_error = [
        '%type' => 'TypeError',
        '@message' => 'Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}(): Argument #1 ($test) must be of type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 65',
        '%function' => 'Drupal\error_test\Controller\ErrorTestController->Drupal\error_test\Controller\{closure}()',
        ];
        }
        $this->drupalGet('error-test/generate-fatal-errors'); $this->drupalGet('error-test/generate-fatal-errors');
        $this->assertSession()->statusCodeEquals(500); $this->assertSession()->statusCodeEquals(500);
        $message = new FormattableMarkup('%type: @message in %function (line ', $fatal_error); $message = new FormattableMarkup('%type: @message in %function (line ', $fatal_error);
        ...@@ -155,7 +164,9 @@ public function testErrorContainer(): void { ...@@ -155,7 +164,9 @@ public function testErrorContainer(): void {
        $this->writeSettings($settings); $this->writeSettings($settings);
        \Drupal::service('kernel')->invalidateContainer(); \Drupal::service('kernel')->invalidateContainer();
        $this->expectedExceptionMessage = 'Drupal\FunctionalTests\Bootstrap\ErrorContainer::Drupal\FunctionalTests\Bootstrap\{closure}(): Argument #1 ($container) must be of type Drupal\FunctionalTests\Bootstrap\ErrorContainer'; $this->expectedExceptionMessage = PHP_VERSION_ID >= 80400 ?
        'Drupal\FunctionalTests\Bootstrap\ErrorContainer::{closure:Drupal\FunctionalTests\Bootstrap\ErrorContainer::get():21}(): Argument #1 ($container) must be of type Drupal\FunctionalTests\Bootstrap\ErrorContainer' :
        'Drupal\FunctionalTests\Bootstrap\ErrorContainer::Drupal\FunctionalTests\Bootstrap\{closure}(): Argument #1 ($container) must be of type Drupal\FunctionalTests\Bootstrap\ErrorContainer';
        $this->drupalGet(''); $this->drupalGet('');
        $this->assertSession()->statusCodeEquals(500); $this->assertSession()->statusCodeEquals(500);
        ......
        ...@@ -49,6 +49,8 @@ public function testCallbackResolver(): void { ...@@ -49,6 +49,8 @@ public function testCallbackResolver(): void {
        function ($suffix) { function ($suffix) {
        return __METHOD__ . '+' . $suffix; return __METHOD__ . '+' . $suffix;
        }, },
        PHP_VERSION_ID >= 80400 ?
        '{closure:Drupal\Tests\Core\Utility\CallableResolverTest::testCallbackResolver():49}' :
        'Drupal\Tests\Core\Utility\{closure}', 'Drupal\Tests\Core\Utility\{closure}',
        ], ],
        'First-class callable function' => [ 'First-class callable function' => [
        ...@@ -61,6 +63,8 @@ function ($suffix) { ...@@ -61,6 +63,8 @@ function ($suffix) {
        ], ],
        'Arrow function' => [ 'Arrow function' => [
        fn($suffix) => __METHOD__ . '+' . $suffix, fn($suffix) => __METHOD__ . '+' . $suffix,
        PHP_VERSION_ID >= 80400 ?
        '{closure:Drupal\Tests\Core\Utility\CallableResolverTest::testCallbackResolver():65}' :
        'Drupal\Tests\Core\Utility\{closure}', 'Drupal\Tests\Core\Utility\{closure}',
        ], ],
        'Static function' => [ 'Static function' => [
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment