minkphp / Mink

PHP web browser emulator abstraction
https://mink.behat.org/
MIT License
1.6k stars 280 forks source link

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

Open longwave opened 11 months ago

longwave commented 11 months ago

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.

stof commented 11 months ago

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.

andypost commented 11 months ago

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

stof commented 11 months ago

@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.