14 use PHPUnit\Framework\Constraint\Constraint;
24 public function __construct(
string $name,
string $path =
'/',
string $domain =
null)
28 $this->domain = $domain;
36 $str = sprintf(
'has cookie "%s"', $this->name);
37 if (
'/' !== $this->path) {
38 $str .= sprintf(
' with path "%s"', $this->path);
41 $str .= sprintf(
' for domain "%s"', $this->domain);
52 protected function matches($response): bool
54 return null !== $this->getCookie($response);
64 return 'the Response '.$this->toString();
69 $cookies = $response->headers->getCookies();
71 $filteredCookies = array_filter($cookies,
function (
Cookie $cookie) {
72 return $cookie->
getName() === $this->name && $cookie->
getPath() === $this->path && $cookie->
getDomain() === $this->domain;
75 return reset($filteredCookies) ?:
null;