|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Symfony\Component\HttpKernel\Tests\Exception; |
| 4 | + |
| 5 | +use Symfony\Component\HttpKernel\Exception\HttpException; |
| 6 | + |
| 7 | +/** |
| 8 | + * Test the HttpException class. |
| 9 | + */ |
| 10 | +class HttpExceptionTest extends \PHPUnit_Framework_TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * Provides header data for the tests. |
| 14 | + * |
| 15 | + * @return array |
| 16 | + */ |
| 17 | + public function headerDataProvider() |
| 18 | + { |
| 19 | + return array( |
| 20 | + array(array('X-Test' => 'Test')), |
| 21 | + array(array('X-Test' => 1)), |
| 22 | + array( |
| 23 | + array( |
| 24 | + array('X-Test' => 'Test'), |
| 25 | + array('X-Test-2' => 'Test-2'), |
| 26 | + ), |
| 27 | + ), |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Test that the default headers is an empty array. |
| 33 | + */ |
| 34 | + public function testHeadersDefault() |
| 35 | + { |
| 36 | + $exception = new HttpException(200); |
| 37 | + $this->assertSame(array(), $exception->getHeaders()); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Test that setting the headers using the constructor parameter |
| 42 | + * is working as expected. |
| 43 | + * |
| 44 | + * @param array $headers The headers to set. |
| 45 | + * |
| 46 | + * @dataProvider headerDataProvider |
| 47 | + */ |
| 48 | + public function testHeadersConstructor($headers) |
| 49 | + { |
| 50 | + $exception = new HttpException(200, null, null, $headers); |
| 51 | + $this->assertSame($headers, $exception->getHeaders()); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Test that setting the headers using the setter function |
| 56 | + * is working as expected. |
| 57 | + * |
| 58 | + * @param array $headers The headers to set. |
| 59 | + * |
| 60 | + * @dataProvider headerDataProvider |
| 61 | + */ |
| 62 | + public function testHeadersSetter($headers) |
| 63 | + { |
| 64 | + $exception = new HttpException(200); |
| 65 | + $exception->setHeaders($headers); |
| 66 | + $this->assertSame($headers, $exception->getHeaders()); |
| 67 | + } |
| 68 | +} |
0 commit comments