ResponseHasCookieTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpFoundation\Tests\Test\Constraint;
  11. use PHPUnit\Framework\ExpectationFailedException;
  12. use PHPUnit\Framework\TestCase;
  13. use PHPUnit\Framework\TestFailure;
  14. use Symfony\Component\HttpFoundation\Cookie;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpFoundation\Test\Constraint\ResponseHasCookie;
  17. class ResponseHasCookieTest extends TestCase
  18. {
  19. public function testConstraint()
  20. {
  21. $response = new Response();
  22. $response->headers->setCookie(Cookie::create('foo', 'bar'));
  23. $constraint = new ResponseHasCookie('foo');
  24. $this->assertTrue($constraint->evaluate($response, '', true));
  25. $constraint = new ResponseHasCookie('bar');
  26. $this->assertFalse($constraint->evaluate($response, '', true));
  27. try {
  28. $constraint->evaluate($response);
  29. } catch (ExpectationFailedException $e) {
  30. $this->assertEquals("Failed asserting that the Response has cookie \"bar\".\n", TestFailure::exceptionToString($e));
  31. return;
  32. }
  33. $this->fail();
  34. }
  35. }