Problem/Motivation

When I run the tests locally I get the following error:

$ sudo -u www-data php core/scripts/run-tests.sh --verbose  --color --keep-results --suppress-deprecations --types "Simpletest,PHPUnit-Unit,PHPUnit-Kernel,PHPUnit-Functional" --sqlite "/tmp/simpletest.sqlite" --dburl "mysql://root:root@localhost/d9" --url "http://d9.test" --directory modules/contrib/key_auth

Drupal test run
---------------

Tests to be run:
  - Drupal\Tests\key_auth\Functional\KeyAuthTest

Test run started:
  Monday, September 13, 2021 - 15:30

Test summary
------------

Drupal\Tests\key_auth\Functional\KeyAuthTest                   0 passes   1 fails                            

Test run duration: 28 sec

Detailed test results
---------------------

---- Drupal\Tests\key_auth\Functional\KeyAuthTest ----


Status    Group      Filename          Line Function                            
--------------------------------------------------------------------------------
Fail      Other      phpunit-5.xml        0 Drupal\Tests\key_auth\Functional\Ke
    PHPunit Test failed to complete; Error: PHPUnit 8.5.5 by Sebastian Bergmann
    and contributors.
    
    Testing Drupal\Tests\key_auth\Functional\KeyAuthTest
    ....F                                                               5 / 5
    (100%)
    
    Time: 28.34 seconds, Memory: 10.00 MB
    
    There was 1 failure:
    
    1) Drupal\Tests\key_auth\Functional\KeyAuthTest::testKeyAuth
    Failed asserting that null is false.
    
    /home/user/Work/drupal/d9/web/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:118
    /home/user/Work/drupal/d9/web/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:54
    /home/user/Work/drupal/d9/web/vendor/phpunit/phpunit/src/Framework/Assert.php:2887
    /home/user/Work/drupal/d9/web/vendor/phpunit/phpunit/src/Framework/Assert.php:1567
    /home/user/Work/drupal/d9/web/modules/contrib/key_auth/tests/src/Functional/KeyAuthTest.php:322
    /home/user/Work/drupal/d9/web/modules/contrib/key_auth/tests/src/Functional/KeyAuthTest.php:228
    /home/user/Work/drupal/d9/web/vendor/phpunit/phpunit/src/Framework/TestResult.php:691
    
    FAILURES!
    Tests: 5, Assertions: 64, Failures: 1.
    
    HTML output was generated
    http://d9.test/sites/simpletest/browser_output/Drupal_Tests_key_auth_Functional_KeyAuthTest-30-16044625.html

Steps to reproduce

  1. Install a clean D8 or D9 instance.
  2. Clone the key_auth module in modules/contrib/key_auth (or install module normally)
  3. Run the tests using the command above

I've noticed the testbot on Drupal.org does not have this issue, however I've tested the same setup on D8 and D9 and I get the same error. The problem occurs on KeyAuthTest.php line 316

$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));

A request looks like this:

$ curl -v http://d9.test/key_auth_test?api-key=f382ce82c6f31561952198c682e168b2
*   Trying 127.0.0.1:80...
* TCP_NODELAY set
* Connected to d9.test (127.0.0.1) port 80 (#0)
> GET /key_auth_test?api-key=f382ce82c6f31561952198c682e168b2 HTTP/1.1
> Host: d9.test
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Mon, 13 Sep 2021 12:12:48 GMT
< Server: Apache/2.4.41 (Ubuntu)
< Cache-Control: must-revalidate, no-cache, private
< X-Drupal-Dynamic-Cache: HIT
< X-UA-Compatible: IE=edge
< Content-language: en
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Drupal-Cache-Tags: block_view config:block.block.stark_admin config:block.block.stark_branding config:block.block.stark_local_actions config:block.block.stark_local_tasks config:block.block.stark_messages config:block.block.stark_page_title config:block.block.stark_tools config:block_list config:system.menu.admin config:system.menu.tools config:system.site http_response local_task rendered
< X-Drupal-Cache-Contexts: languages:language_interface route theme url.query_args:_wrapper_format user.permissions user.roles:authenticated
< Expires: Sun, 19 Nov 1978 05:00:00 GMT
< X-Generator: Drupal 9 (https://www.drupal.org)
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8

Therefore the X-Drupal-Cache header is not set.

Proposed resolution

I suppose the correct solution to check for the X-Drupal-Cache header is assertEmpty? Not sure though ...

Comments

cristiroma created an issue. See original summary.

cristiroma’s picture

Title: Running tests does not work » Test testKeyAuth fails: Failed asserting that null is false
Category: Feature request » Support request
cristiroma’s picture

Status: Active » Needs review
StatusFileSize
new518 bytes