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

Skip to content

[HttpKernel] added a setter for the headers property in the HttpException #17111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpKernel/Exception/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ public function getHeaders()
{
return $this->headers;
}

/**
* Set response headers.
*
* @param array $headers Response headers.
*/
public function setHeaders(array $headers)
{
$this->headers = $headers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

/**
* Test the AccessDeniedHttpException class.
*/
class AccessDeniedHttpExceptionTest extends HttpExceptionTest
{
/**
* Test that the default headers is an empty array.
*/
public function testHeadersDefault()
{
$exception = new AccessDeniedHttpException();
$this->assertSame(array(), $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new AccessDeniedHttpException();
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

/**
* Test the BadRequestHttpException class.
*/
class BadRequestHttpExceptionTest extends HttpExceptionTest
{
/**
* Test that the default headers is an empty array.
*/
public function testHeadersDefault()
{
$exception = new BadRequestHttpException();
$this->assertSame(array(), $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new BadRequestHttpException();
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\ConflictHttpException;

/**
* Test the ConflictHttpException class.
*/
class ConflictHttpExceptionTest extends HttpExceptionTest
{
/**
* Test that the default headers is an empty array.
*/
public function testHeadersDefault()
{
$exception = new ConflictHttpException();
$this->assertSame(array(), $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new ConflictHttpException();
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\GoneHttpException;

/**
* Test the GoneHttpException class.
*/
class GoneHttpExceptionTest extends HttpExceptionTest
{
/**
* Test that the default headers is an empty array.
*/
public function testHeadersDefault()
{
$exception = new GoneHttpException();
$this->assertSame(array(), $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new GoneHttpException();
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\HttpException;

/**
* Test the HttpException class.
*/
class HttpExceptionTest extends \PHPUnit_Framework_TestCase
{
/**
* Provides header data for the tests.
*
* @return array
*/
public function headerDataProvider()
{
return array(
array(array('X-Test' => 'Test')),
array(array('X-Test' => 1)),
array(
array(
array('X-Test' => 'Test'),
array('X-Test-2' => 'Test-2'),
),
),
);
}

/**
* Test that the default headers is an empty array.
*/
public function testHeadersDefault()
{
$exception = new HttpException(200);
$this->assertSame(array(), $exception->getHeaders());
}

/**
* Test that setting the headers using the constructor parameter
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersConstructor($headers)
{
$exception = new HttpException(200, null, null, $headers);
$this->assertSame($headers, $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new HttpException(200);
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\LengthRequiredHttpException;

/**
* Test the LengthRequiredHttpException class.
*/
class LengthRequiredHttpExceptionTest extends HttpExceptionTest
{
/**
* Test that the default headers is an empty array.
*/
public function testHeadersDefault()
{
$exception = new LengthRequiredHttpException();
$this->assertSame(array(), $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new LengthRequiredHttpException();
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;

/**
* Test the MethodNotAllowedHttpException class.
*/
class MethodNotAllowedHttpExceptionTest extends HttpExceptionTest
{
/**
* Test that the default headers is set as expected.
*/
public function testHeadersDefault()
{
$exception = new MethodNotAllowedHttpException(array('GET', 'PUT'));
$this->assertSame(array('Allow' => 'GET, PUT'), $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new MethodNotAllowedHttpException(array('GET'));
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;

/**
* Test the NotAcceptableHttpException class.
*/
class NotAcceptableHttpExceptionTest extends HttpExceptionTest
{
/**
* Test that the default headers is an empty array.
*/
public function testHeadersDefault()
{
$exception = new NotAcceptableHttpException();
$this->assertSame(array(), $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new NotAcceptableHttpException();
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\HttpKernel\Tests\Exception;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* Test the NotFoundHttpException class.
*/
class NotFoundHttpExceptionTest extends HttpExceptionTest
{
/**
* Test that the default headers is an empty array.
*/
public function testHeadersDefault()
{
$exception = new NotFoundHttpException();
$this->assertSame(array(), $exception->getHeaders());
}

/**
* Test that setting the headers using the setter function
* is working as expected.
*
* @param array $headers The headers to set.
*
* @dataProvider headerDataProvider
*/
public function testHeadersSetter($headers)
{
$exception = new NotFoundHttpException();
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
}
Loading