Mink icon indicating copy to clipboard operation
Mink copied to clipboard

responseHeaderEquals() can no longer be used to check for existence

Open longwave opened this issue 7 months ago • 3 comments

Previously in Drupal we used responseHeaderEquals() to check for the non-existence of a header by looking for NULL:

    $this->assertSession()->responseHeaderEquals('Access-Control-Allow-Origin', NULL);

Since Mink 1.11 this no longer works as $value is typed as string, although getResponseHeader() can still return NULL:

    public function responseHeaderEquals(string $name, string $value)
    {
        $actual = $this->session->getResponseHeader($name);

There appears to be no supported way to check that a header does not exist. We had in fact already added responseHeader[Not]Exists() helper methods to Drupal, but after upgrading to Mink 1.11 we found we had not converted all cases to use them.

longwave avatar Dec 10 '23 16:12 longwave

In 1.10.0, the documented signature of the method was already saying that the type for $value was string: https://github.com/minkphp/Mink/blob/v1.10.0/src/WebAssert.php#L149-L156

The fact that you passed null and it worked was an undefined behavior.

stof avatar Dec 11 '23 13:12 stof

As headers are strings, how any of them can be NULL? For example the Access-Control-Allow-Origin exists or missing

andypost avatar Dec 11 '23 14:12 andypost

@andypost I think this was working by luck because getResponseHeader returns null when the header is missing (so this was testing that the header is missing by comparing it to null). But this was never intended to work.

stof avatar Dec 11 '23 17:12 stof