BrowserHasCookie example

use PHPUnit\Framework\TestFailure;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\Test\Constraint\BrowserHasCookie;

class BrowserHasCookieTest extends TestCase
{
    public function testConstraint()
    {
        $browser = $this->getBrowser();
        $constraint = new BrowserHasCookie('foo', '/path');
        $this->assertTrue($constraint->evaluate($browser, '', true));
        $constraint = new BrowserHasCookie('foo', '/path', 'example.com');
        $this->assertTrue($constraint->evaluate($browser, '', true));
        $constraint = new BrowserHasCookie('bar');
        $this->assertFalse($constraint->evaluate($browser, '', true));

        try {
            $constraint->evaluate($browser);
        } catch (ExpectationFailedException $e) {
            $this->assertEquals("Failed asserting that the Browser has cookie \"bar\".\n", TestFailure::exceptionToString($e));

            
new ResponseConstraint\ResponseCookieValueSame($name$expectedValue$path$domain)
        )$message);
    }

    public static function assertResponseIsUnprocessable(string $message = ''): void
    {
        self::assertThatForResponse(new ResponseConstraint\ResponseIsUnprocessable()$message);
    }

    public static function assertBrowserHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
    {
        self::assertThatForClient(new BrowserKitConstraint\BrowserHasCookie($name$path$domain)$message);
    }

    public static function assertBrowserNotHasCookie(string $name, string $path = '/', string $domain = null, string $message = ''): void
    {
        self::assertThatForClient(new LogicalNot(new BrowserKitConstraint\BrowserHasCookie($name$path$domain))$message);
    }

    public static function assertBrowserCookieValueSame(string $name, string $expectedValue, bool $raw = false, string $path = '/', string $domain = null, string $message = ''): void
    {
        self::assertThatForClient(LogicalAnd::fromConstraints(
            new BrowserKitConstraint\BrowserHasCookie($name$path$domain),
            
Home | Imprint | This part of the site doesn't use cookies.