14 use PHPUnit\Framework\Constraint\Constraint;
25 public function __construct(
string $name,
string $value,
string $path =
'/',
string $domain =
null)
28 $this->value = $value;
30 $this->domain = $domain;
38 $str = sprintf(
'has cookie "%s"', $this->name);
39 if (
'/' !== $this->path) {
40 $str .= sprintf(
' with path "%s"', $this->path);
43 $str .= sprintf(
' for domain "%s"', $this->domain);
45 $str .= sprintf(
' with value "%s"', $this->value);
55 protected function matches($response): bool
62 return $this->value === $cookie->getValue();
72 return 'the Response '.$this->toString();
77 $cookies = $response->headers->getCookies();
79 $filteredCookies = array_filter($cookies,
function (
Cookie $cookie) {
80 return $cookie->
getName() === $this->name && $cookie->
getPath() === $this->path && $cookie->
getDomain() === $this->domain;
83 return reset($filteredCookies) ?:
null;