for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Pitchart\Phlunit\Constraint\HttpResponse;
use PHPUnit\Framework\Constraint\Constraint;
use Psr\Http\Message\ResponseInterface;
final class HasHeader extends Constraint
{
/**
* @var int|string
*/
private $key;
* @param int|string $key
public function __construct($key)
$this->key = $key;
}
* Returns a string representation of the constraint.
*
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
* @return string
public function toString(): string
return 'has the header ' . $this->exporter()->export($this->key);
* Evaluates the constraint for parameter $other. Returns true if the
* constraint is met, false otherwise.
* @param mixed $other value or object to evaluate
protected function matches($other): bool
if ($other instanceof ResponseInterface) {
return \array_key_exists($this->key, $other->getHeaders());
return false;
* Returns the description of the failure
* The beginning of failure messages is "Failed asserting that" in most
* cases. This method should return the second part of that sentence.
* @param mixed $other evaluated value or object
protected function failureDescription($other): string
return 'a HTTP Response ' . $this->toString();