Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 540c321

Browse files
committed
added a setter for the headers property in the HttpException
1 parent 09efd06 commit 540c321

17 files changed

+888
-0
lines changed

src/Symfony/Component/HttpKernel/Exception/HttpException.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,14 @@ public function getHeaders()
3838
{
3939
return $this->headers;
4040
}
41+
42+
/**
43+
* Set response headers.
44+
*
45+
* @param array $headers Response headers.
46+
*/
47+
public function setHeaders(array $headers)
48+
{
49+
$this->headers = $headers;
50+
}
4151
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Symfony\Component\HttpKernel\Tests\Exception;
4+
5+
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
6+
7+
/**
8+
* Test the AccessDeniedHttpException class.
9+
*/
10+
class AccessDeniedHttpExceptionTest 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 AccessDeniedHttpException();
37+
$this->assertSame(array(), $exception->getHeaders());
38+
}
39+
40+
/**
41+
* Test that setting the headers using the setter function
42+
* is working as expected.
43+
*
44+
* @param array $headers The headers to set.
45+
*
46+
* @dataProvider headerDataProvider
47+
*/
48+
public function testHeadersSetter($headers)
49+
{
50+
$exception = new AccessDeniedHttpException();
51+
$exception->setHeaders($headers);
52+
$this->assertSame($headers, $exception->getHeaders());
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Symfony\Component\HttpKernel\Tests\Exception;
4+
5+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
6+
7+
/**
8+
* Test the BadRequestHttpException class.
9+
*/
10+
class BadRequestHttpExceptionTest 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 BadRequestHttpException();
37+
$this->assertSame(array(), $exception->getHeaders());
38+
}
39+
40+
/**
41+
* Test that setting the headers using the setter function
42+
* is working as expected.
43+
*
44+
* @param array $headers The headers to set.
45+
*
46+
* @dataProvider headerDataProvider
47+
*/
48+
public function testHeadersSetter($headers)
49+
{
50+
$exception = new BadRequestHttpException();
51+
$exception->setHeaders($headers);
52+
$this->assertSame($headers, $exception->getHeaders());
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Symfony\Component\HttpKernel\Tests\Exception;
4+
5+
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
6+
7+
/**
8+
* Test the ConflictHttpException class.
9+
*/
10+
class ConflictHttpExceptionTest 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 ConflictHttpException();
37+
$this->assertSame(array(), $exception->getHeaders());
38+
}
39+
40+
/**
41+
* Test that setting the headers using the setter function
42+
* is working as expected.
43+
*
44+
* @param array $headers The headers to set.
45+
*
46+
* @dataProvider headerDataProvider
47+
*/
48+
public function testHeadersSetter($headers)
49+
{
50+
$exception = new ConflictHttpException();
51+
$exception->setHeaders($headers);
52+
$this->assertSame($headers, $exception->getHeaders());
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Symfony\Component\HttpKernel\Tests\Exception;
4+
5+
use Symfony\Component\HttpKernel\Exception\GoneHttpException;
6+
7+
/**
8+
* Test the GoneHttpException class.
9+
*/
10+
class GoneHttpExceptionTest 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 GoneHttpException();
37+
$this->assertSame(array(), $exception->getHeaders());
38+
}
39+
40+
/**
41+
* Test that setting the headers using the setter function
42+
* is working as expected.
43+
*
44+
* @param array $headers The headers to set.
45+
*
46+
* @dataProvider headerDataProvider
47+
*/
48+
public function testHeadersSetter($headers)
49+
{
50+
$exception = new GoneHttpException();
51+
$exception->setHeaders($headers);
52+
$this->assertSame($headers, $exception->getHeaders());
53+
}
54+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Symfony\Component\HttpKernel\Tests\Exception;
4+
5+
use Symfony\Component\HttpKernel\Exception\LengthRequiredHttpException;
6+
7+
/**
8+
* Test the LengthRequiredHttpException class.
9+
*/
10+
class LengthRequiredHttpExceptionTest 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 LengthRequiredHttpException();
37+
$this->assertSame(array(), $exception->getHeaders());
38+
}
39+
40+
/**
41+
* Test that setting the headers using the setter function
42+
* is working as expected.
43+
*
44+
* @param array $headers The headers to set.
45+
*
46+
* @dataProvider headerDataProvider
47+
*/
48+
public function testHeadersSetter($headers)
49+
{
50+
$exception = new LengthRequiredHttpException();
51+
$exception->setHeaders($headers);
52+
$this->assertSame($headers, $exception->getHeaders());
53+
}
54+
}

0 commit comments

Comments
 (0)