Make the test suite pass on Drupal10/PHP8.1

Created on 13 March 2023, over 1 year ago
Updated 14 March 2023, over 1 year ago

Problem/Motivation

Make the test suite pass on PHP8.1/D10

See https://www.drupal.org/pift-ci-job/2616309 โ†’

Drupal\Core\Composer\Composer::upgradePHPUnit
PHP Fatal error:  Declaration of Drupal\Tests\potx\Kernel\PotxTest::setUp() must be compatible with Drupal\KernelTests\KernelTestBase::setUp(): void in /var/www/html/modules/contrib/potx/tests/src/Kernel/PotxTest.php on line 24

Steps to reproduce

See https://www.drupal.org/pift-ci-job/2616309 โ†’

Proposed resolution

Make the test go green

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ“Œ Task
Status

Fixed

Version

1.0

Component

Code

Created by

๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Lendude Amsterdam

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

Comments & Activities

  • Issue created by @Lendude
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Lendude Amsterdam
    • Changed all the old assertions where needed
    • Removed all the message logic, since these were producing old style Simpletest messages (which are possitive messages, there PHPUnit expect negative messages), we should remove all the messages in method calls too, but wanted to see if others agree if this was a good place to change this
    • testDrupal8ShippedConfiguration gives an additional error now, so added that error to the test to make it green, not sure if modifying the test is right here or that this error shouldn't be raised and we need to fix this in the code under test
  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    I think the YAML parsing error is new in Drupal 10 due to the more strict parsing? Or is that our own error?

    Re changing the message handling, are our assert*() methods used with message arguments? Sounds like an API change if we are invoking it with explicit messages and now ignoring them?

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Lendude Amsterdam

    The new error comes from Symfony, see #3055189: [Symfony 5] Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0. โ†’ for the core issue. So that sounds like it would be ok to add the new error in the test.

    The ignored $messages are all in private methods, so nothing outside this test can access them, so don't think this would be an API change. But I can totally get that we would want to make the change as small as possible here. The $group parameter is not something we can support though, cause that was a Simpletest specific thing in assertions.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary
    +++ b/tests/src/Kernel/PotxTest.php
    @@ -748,70 +753,49 @@ class TestConstraint {
       /**
        * Assert the lack of a msgid with context in the .po file.
        */
       private function assertNoMsgIdContext($string, $context, $message = '', $group = 'Other') {
    -    if (!$message) {
    -      $message = new FormattableMarkup('No MsgID "@raw" in context "@context" found', ['@raw' => $string, '@context' => $context]);
    -    }
    -    $this->assert(strpos($this->potx_output, 'msgid "' . _potx_format_quoted_string('"' . $string . '"') . '"' . "\nmsgctxt \"" . _potx_format_quoted_string('"' . $context . '"') . '"') === FALSE, $message, $group);
    +    $this->assertFalse(strpos($this->potx_output, 'msgid "' . _potx_format_quoted_string('"' . $string . '"') . '"' . "\nmsgctxt \"" . _potx_format_quoted_string('"' . $context . '"') . '"'));
       }
    

    Well, what I meant is that before this method may have been invoked with a $message which is now ignored. So any uses of it internal in this class would not effectively use that message.

    On top of that the reason we had the custom messages was easier debugging, you got an exact message about which string was not found or found but should not have been there. Now this requires a debug backtrace to find as you only get an "anonymous" assert result.

    If phpunit wants us to swap the positivity of the message, should we adapt to that instead?

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Lendude Amsterdam

    Agreed, let's keep the messages in, think we should just do minimal cleanup here to make it green.

    So this just changes the assertions to use the correct ones, it does remove the $group since that isn't supported in the new assertions.
    Also still removes outputScreenContents since that isn't used anymore and was providing a workaround for a simpletest bug

    Didn't change the messages here, they have been "wrong" since this was converted to phpunit and even with the wrong positivity they are still better than 'failed asserting true is false'. If we care about getting those right we could probably do it in a follow up right?

    • fe483a58 committed on 8.x-1.x
      Issue #3347587 by Lendude, Gรกbor Hojtsy: Make the test suite pass on...
  • Status changed to Fixed over 1 year ago
  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    Agreed, this looks great, thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024