ResponseStatusCodeSameTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Response;
  15. use Symfony\Component\HttpFoundation\Test\Constraint\ResponseStatusCodeSame;
  16. class ResponseStatusCodeSameTest extends TestCase
  17. {
  18. public function testConstraint()
  19. {
  20. $constraint = new ResponseStatusCodeSame(200);
  21. $this->assertTrue($constraint->evaluate(new Response(), '', true));
  22. $this->assertFalse($constraint->evaluate(new Response('', 404), '', true));
  23. $constraint = new ResponseStatusCodeSame(404);
  24. $this->assertTrue($constraint->evaluate(new Response('', 404), '', true));
  25. $constraint = new ResponseStatusCodeSame(200);
  26. try {
  27. $constraint->evaluate(new Response('', 404));
  28. } catch (ExpectationFailedException $e) {
  29. $this->assertStringContainsString("Failed asserting that the Response status code is 200.\nHTTP/1.0 404 Not Found", TestFailure::exceptionToString($e));
  30. return;
  31. }
  32. $this->fail();
  33. }
  34. }