drupal-check still reports some deprecations in 1.16 after #3023170: Test for compatibility with Drupal 9.

% drupal-check .
 380/380 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ -----------------------------------------------------------------------------------------------------------------------
  Line   search_api.behat.inc
 ------ -----------------------------------------------------------------------------------------------------------------------
         Class SearchApiSubContext was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ -----------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------
  Line   tests/src/Functional/IntegrationTest.php
 ------ -----------------------------------------------------------------------------------
  907    Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
  1049   Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
  1110   Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
 ------ -----------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------
  Line   tests/src/Kernel/Processor/RenderedItemTest.php
 ------ -----------------------------------------------------------------------------------
  247    Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
 ------ -----------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------
  Line   tests/src/Kernel/System/CommandHelperTest.php
 ------ -----------------------------------------------------------------------------------
  122    Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
  140    Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
  152    Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
  281    Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
  294    Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
 ------ -----------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------
  Line   tests/src/Kernel/System/SerializationTest.php
 ------ -----------------------------------------------------------------------------------
  135    Call to deprecated method assertInternalType() of class PHPUnit\Framework\Assert:
         https://github.com/sebastianbergmann/phpunit/issues/3369
 ------ -----------------------------------------------------------------------------------


 [ERROR] Found 11 errors
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

douggreen created an issue. See original summary.

douggreen’s picture

Title: drupal-check errors in 1.6 » Fix more Drupal 9 comparability warnings found with drupal-check
douggreen’s picture

Version: 8.x-1.16 » 8.x-1.x-dev
effulgentsia’s picture

The test results in #2 are interesting. The Autocomplete test failure only happen on MySQL 5.6 and 5.7. It passes on MySQL 5.5 and MySQL 8, and also on SQLite and PostgreSQL.

On MySQL 5.6 and 5.7, the same failure happens on HEAD as well (without the #2 patch).

drunken monkey’s picture

Title: Fix more Drupal 9 comparability warnings found with drupal-check » Fix usages of the (deprecated) assertInternalType() PhpUnit method
Component: General code » Tests
Status: Needs review » Postponed (maintainer needs more info)

Thanks for reporting this issue!

I unfortunately have no clue about Behat, but in #3115214-12: Add Search API support for Behat Drupal Extension I was assured that the file structure needs to be like this (at the moment). So, yes, I also think that SearchApiSubContext is a false positive. Pretty unfortunate, but probably nothing we can do about it.

The rest are all just assertInternalType(), so I think just having that as the title is much more appropriate. Especially as that’s a third-party deprecation, so I didn’t think it had anything to do with Drupal 9, or was urgent. Checking back now, though, I see that our tests are actually failing on this for Drupal 9. So yes, apparently really something we need to fix.

However, I myself am only on PHPUnit 6.5, so those tests are now failing for me locally with “Call to undefined method”, and composer update phpunit/phpunit fails to do anything. (Trying further, it seems there are once again some version conflicts.) Looking through the change notices, I also don’t see anything about PHPUnit 7 now being required for Drupal 8 (just a bit more trouble in this regard on the horizon). Core’s usual information policy, I guess.

Anyways, I guess my question is: Do you have any concrete information about how contrib modules should handle PHPUnit compatibility at the moment? (Also: Do you know how I can update to PHPUnit 7?)
If we shouldn’t rely on PHPUnit 7 at the moment, then I guess our best option is to ignore/hide those warnings somehow, at least for the moment.

drunken monkey’s picture

NB: Tests on D9 are now also failing on other method calls, namely assertContains() and assertNotContains(), when used with string haystacks. The attached patch revision would fix those as well.

Increasing priority as this keeps us from testing Drupal 9 compatibility.

However, I still need information on whether Drupal 8 code should still support PHPUnit 6. If it should, we’ll have to find a different solution.

Status: Needs review » Needs work

The last submitted patch, 7: 3126751-7--fix_phpunit_deprecations.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

> However, I still need information on whether Drupal 8 code should still support PHPUnit 6. If it should, we’ll have to find a different solution.

Some of the PHPunit 8 replacement methods have been backported to make it possible to be forward-compatible. But you definitely still want to tests to pass against Drupal 8, in other words, assertIsArray() is a no-go currently and you need to use something like assertTrue(is_array()) or just get rid of them in a different way...

  1. +++ b/tests/src/Functional/IntegrationTest.php
    @@ -904,7 +904,7 @@ protected function addFieldsToIndex() {
         $rows = $this->xpath('//*[@id="search-api-data-types-table"]//table/tbody/tr');
    -    $this->assertInternalType('array', $rows);
    +    $this->assertIsArray($rows);
         $this->assertNotEmpty($rows);
     
    

    The is array check here doesn't really serve a purpose. xpath() always returns an array, the not empty check alone should be enough.

  2. +++ b/tests/src/Functional/IntegrationTest.php
    @@ -1046,7 +1046,7 @@ protected function removeFieldsFromIndex() {
         $links = $this->xpath('//a[@data-drupal-selector=:id]', [':id' => 'edit-fields-body-remove']);
         $this->assertNotEmpty($links, 'Found "Remove" link for body field');
    -    $this->assertInternalType('array', $links);
    +    $this->assertIsArray($links);
         $url_target = $this->getAbsoluteUrl($links[0]->getAttribute('href'));
    

    same. And you could write this like this:

    $href = $this->assertSession()->elementExists('css', 'a[data-drupal-selector=edit-fields-body-remove]')->getAttribute('href');
    $url_target = $this->getAbsoluteUrl($href);
    

    (untested)

    The array stuff is just there to avoid a fatal error, the elementExists() will fail with an exception and abort the test if the element doesn't exist.

  3. +++ b/tests/src/Kernel/System/CommandHelperTest.php
    @@ -119,7 +119,7 @@ public function setUp() {
       public function testListCommand() {
         $results = $this->systemUnderTest->indexListCommand();
    -    $this->assertInternalType('array', $results);
    +    $this->assertIsArray($results);
         $this->assertCount(2, $results);
    
    @@ -137,7 +137,7 @@ public function testListCommand() {
         $results = $this->systemUnderTest->indexListCommand();
    -    $this->assertInternalType('array', $results);
    +    $this->assertIsArray($results);
         $this->assertArrayNotHasKey('test_index', $results);
         $this->assertArrayHasKey('second_index', $results);
    

    Same for all of these I think. The following asserts should all fail fairly clearly if it's not an array. assertCount() on NULL gives:

    Argument #2 of PHPUnit\Framework\Assert::assertCount() must be a countable or iterable

drunken monkey’s picture

Status: Needs work » Needs review

Re-triggered the tests and apparently all necessary shims are now in place. After pulling the latest 8.9 commits, the tests pass for me locally, too.
With this, I think this is RTBC?

drunken monkey’s picture

Status: Needs review » Fixed

Alright, then: committed.
Thanks again, everyone!

Status: Fixed » Closed (fixed)

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