run-tests.sh cannot handle unicode in PHPUnit output

Created on 14 January 2025, 8 days ago

Problem/Motivation

run-tests.sh is struggling on emojis that are now in PHPUnit output - yay.

See https://git.drupalcode.org/issue/entity_usage-3499592/-/jobs/4013618

PHP Warning:  DOMDocument::saveXML(): xmlEscapeEntities : char out of range in /builds/issue/entity_usage-3499592/web/core/scripts/run-tests.sh on line 1249

This is happening because of the emoji's in

    Integration (Drupal\Tests\entity_usage\FunctionalJavascript\Integration)
     ✘ Crud tracking
       ┐
       ├ Behat\Mink\Exception\ResponseTextException: The text "There are recorded usages of this entity" was not found anywhere in the text of the current page.
       │
       │ /builds/issue/entity_usage-3499592/vendor/behat/mink/src/WebAssert.php:907
       │ /builds/issue/entity_usage-3499592/vendor/behat/mink/src/WebAssert.php:293
       │ /builds/issue/entity_usage-3499592/web/core/tests/Drupal/Tests/WebAssert.php:979
       │ /builds/issue/entity_usage-3499592/tests/src/FunctionalJavascript/IntegrationTest.php:127
       ┴
     ✔ Link tracking

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

phpunit

Created by

🇬🇧United Kingdom alexpott 🇪🇺🌍

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @alexpott
  • Merge request !10899Make test fail → (Closed) created by alexpott
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Note this does not happen for core tests only contrib because they are using the --xml flag and core is not. If you make a test fail and use the following flags on a test you will see the error --verbose --xml tmp --class '\\Drupal\\Tests\\Core\\Access\\AccessManagerTest'

    For example:

    $ php ./core/scripts/run-tests.sh --php /opt/homebrew/bin/php --sqlite /tmp/coretest.sqlite --dburl mysql://USER:PASSWORD@localhost/drupal8alt --color --non-html --url http://drupal8alt.test/ --verbose --xml tmp --class '\\Drupal\\Tests\\Core\\Access\\AccessManagerTest'
    
    Drupal test run
    Using PHP Binary: /opt/homebrew/bin/php
    ---------------
    
    Tests to be run:
      - \Drupal\Tests\Core\Access\AccessManagerTest
    
    Test run started:
      Tuesday, January 14, 2025 - 09:54
    
    Test summary
    ------------
    
    \Drupal\Tests\Core\Access\AccessManagerTest                    0 passes    1s   1 fails
    
    Test run duration: 0 sec
    
    Detailed test results
    ---------------------
    
    
    ---- \Drupal\Tests\Core\Access\AccessManagerTest ----
    
    
    Status    Group      Filename          Line Function
    --------------------------------------------------------------------------------
    Fail      Other      phpunit-7.xml        0 \Drupal\Tests\Core\Access\AccessMan
        PHPUnit Test failed to complete; Error: PHPUnit 10.5.38 by Sebastian Bergmann and contributors.
    
        Runtime:       PHP 8.3.14
        Configuration: /Volumes/dev/sites/drupal8alt.dev/core/phpunit.xml.dist
    
        F.................                                                18 / 18 (100%)
    
        Time: 00:00.034, Memory: 16.00 MB
    
        Access Manager (Drupal\Tests\Core\Access\AccessManager)
         ✘ Set checks
           ┐
           ├ Failed asserting that true is false.
           │
           │ /Volumes/dev/sites/drupal8alt.dev/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php:136
           ┴
         ✔ Set checks with dynamic access checker
         ✔ Check
         ✔ Check with null account
         ✔ Check conjunctions with data set 0
         ✔ Check conjunctions with data set 1
         ✔ Check conjunctions with data set 2
         ✔ Check conjunctions with data set 3
         ✔ Check conjunctions with data set 4
         ✔ Check conjunctions with data set 5
         ✔ Check named route
         ✔ Check named route with upcasted values
         ✔ Check named route with default value
         ✔ Check named route with non existing route
         ✔ Check exception with data set 0
         ✔ Check exception with data set 1
         ✔ Check exception with data set 2
         ✔ Check exception with data set 3
    
        FAILURES!
        Tests: 18, Assertions: 62, Failures: 1.
    PHP Warning:  DOMDocument::saveXML(): xmlEscapeEntities : char out of range in /Volumes/dev/sites/drupal8alt.dev/core/scripts/run-tests.sh on line 1316
    
    Warning: DOMDocument::saveXML(): xmlEscapeEntities : char out of range in /Volumes/dev/sites/drupal8alt.dev/core/scripts/run-tests.sh on line 1316
    
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Fortunately the fix is very simple.

  • 🇮🇳India abhishek@kumar

    Locate the relevant line in run-tests.sh (near DOMDocument::saveXML) and update it to include the encoding explicitly:

    $dom = new DOMDocument('1.0', 'UTF-8');
    $dom->formatOutput = true;
    

    This ensures that Unicode characters, such as emojis, are processed correctly by DOMDocument.

  • 🇺🇸United States nicxvan

    Simple enough.

    I don't think we test the tester.

    • catch committed 8bc7475d on 11.x
      Issue #3499596 by alexpott: run-tests.sh cannot handle unicode in...
  • 🇬🇧United Kingdom catch

    Committed/pushed to 11.x, thanks!

  • Merge request !10912Fix emoji in test output → (Closed) created by alexpott
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Created https://git.drupalcode.org/project/drupal/-/merge_requests/10912 to handle backport to 11.1.x and further...

  • Pipeline finished with Canceled
    7 days ago
    Total: 125s
    #396781
  • Pipeline finished with Failed
    7 days ago
    Total: 484s
    #396782
    • catch committed 643160f7 on 10.4.x
      Issue #3499596 by alexpott: run-tests.sh cannot handle unicode in...
    • catch committed 25efd2d5 on 10.5.x
      Issue #3499596 by alexpott: run-tests.sh cannot handle unicode in...
    • catch committed 52fafcaa on 11.1.x
      Issue #3499596 by alexpott: run-tests.sh cannot handle unicode in...
  • 🇬🇧United Kingdom catch

    Committed/pushed to 11.1.x and cherry-picked to 10.5.x and 10.4.x, thanks!

Production build 0.71.5 2024