123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace Symfony\Component\BrowserKit\Test\Constraint;
- use PHPUnit\Framework\Constraint\Constraint;
- use Symfony\Component\BrowserKit\AbstractBrowser;
- final class BrowserHasCookie extends Constraint
- {
- private $name;
- private $path;
- private $domain;
- public function __construct(string $name, string $path = '/', string $domain = null)
- {
- $this->name = $name;
- $this->path = $path;
- $this->domain = $domain;
- }
-
- public function toString(): string
- {
- $str = sprintf('has cookie "%s"', $this->name);
- if ('/' !== $this->path) {
- $str .= sprintf(' with path "%s"', $this->path);
- }
- if ($this->domain) {
- $str .= sprintf(' for domain "%s"', $this->domain);
- }
- return $str;
- }
-
- protected function matches($browser): bool
- {
- return null !== $browser->getCookieJar()->get($this->name, $this->path, $this->domain);
- }
-
- protected function failureDescription($browser): string
- {
- return 'the Browser '.$this->toString();
- }
- }
|