willdurand / Negotiation

Content Negotiation tools for PHP.
https://williamdurand.fr/Negotiation/
MIT License
1.41k stars 62 forks source link

getBest returns a value when no acceptable headers match any of the priorities #38

Closed iby closed 10 years ago

iby commented 10 years ago

I'm about to make a pull request for a small bug while discovered the following and want to clarify first. Currently there's only one place where this is found in LanguageNegotiatorTest:

public function testGetBestDoesNotMatchPriorities()
{
    $acceptLanguageHeader = 'en, de';
    $priorities           = array('fr');
    $acceptHeader = $this->negotiator->getBest($acceptLanguageHeader, $priorities);
    $this->assertInstanceOf('Negotiation\AcceptHeader', $acceptHeader);
    $this->assertEquals('en', $acceptHeader->getValue());
}

Basically what happens is: the client says I will accept only en or de, but the only thing we can offer is fr. The rational action is to return null as we can't satisfy the request, but we return en instead (which we can't provide). I am assuming the way this works is wrong?