Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295516

TypeError: strcasecmp() error when running tests on core/modules/system/tests/src/Functional/Routing/RouterTest.php

$
0
0

Problem/Motivation

I was running some tests in a Drupal 11.0.10 instance (DDEV, PHP 8.3):

$ ./vendor/bin/phpunit -c web/core/phpunit.xml ./web/core/modules/system/tests/src/Functional/Routing/RouterTest.php

and I am hitting this error:

daniel@drupal:/var/www/html$ ./vendor/bin/phpunit -c web/core/phpunit.xml ./web/core/modules/system/tests/src/Functional/Routing/RouterTest.php
PHPUnit 10.5.45 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.14
Configuration: /var/www/html/web/core/phpunit.xml

E.............                                                    14 / 14 (100%)

HTML output was generated.
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-255-28550090.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-256-10338684.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-257-10338684.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-258-10338684.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-259-10338684.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-260-49606092.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-261-49606092.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-262-45676727.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-263-76088657.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-264-24547444.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-265-12070873.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-266-43380184.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-267-43380184.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-268-43380184.html

....

dev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-274-43380184.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-275-43380184.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-276-43380184.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-277-43380184.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-278-33436292.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-279-79848419.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-280-79848419.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-281-79848419.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-282-79848419.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-283-24906904.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-284-69988493.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-285-69988493.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-286-69988493.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-287-69988493.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-288-69988493.html
http://drupal.11.0.10.ddev.site/sites/simpletest/browser_output/Drupal_Tests_system_Functional_Routing_RouterTest-289-69988493.html


Time: 00:45.135, Memory: 6.00 MB

There was 1 error:

1) Drupal\Tests\system\Functional\Routing\RouterTest::testFinishResponseSubscriber

TypeError: strcasecmp(): Argument #1 ($string1) must be of type string, null given

/var/www/html/web/core/modules/system/tests/src/Functional/Routing/RouterTest.php:49

ERRORS!
Tests: 14, Assertions: 75, Errors: 1.

Screenshot:

Screenshot of error running Core RouterTest tests

Steps to reproduce

1. Install latest Drupal 11 release, or make sure your current D11 has phpunit installed.
2. From the directory where the ./vendor directory is located, run:

./vendor/bin/phpunit -c web/core/phpunit.xml ./web/core/modules/system/tests/src/Functional/Routing/RouterTest.php

You'll see the error mentioned above

Proposed resolution

If you take a look at this snippet from RouterTest.php (lines 49-51):

    if (strcasecmp($session->getResponseHeader('vary'), 'accept-encoding') !== 0) {
      $this->assertSession()->responseHeaderDoesNotExist('Vary');
    }

You can add a small validation to check if $session->getResponseHeader('vary') is empty or not before calling strcasecmp(), something like this:

    if (strcasecmp($session->getResponseHeader('vary') ?? "", 'accept-encoding') !== 0) {
      $this->assertSession()->responseHeaderDoesNotExist('Vary');
    }

After that the tests passed:

Screenshot of RouteTest tests succeded

But the main question is: Are the tests expecting the Vary header from FinishResponseSubscriber to have a value? I am not sure about that.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 295516

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>