Skip to content

Commit

Permalink
[HttpKernel] added a setter for the headers property in the HttpExcep…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
smatyas authored and fabpot committed Jan 25, 2016
1 parent e9e4869 commit 6a1080f
Show file tree
Hide file tree
Showing 17 changed files with 623 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpKernel/Exception/HttpException.php
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;
}
}
@@ -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());
}
}
@@ -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());
}
}
@@ -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());
}
}
@@ -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());
}
}
@@ -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());
}
}
@@ -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());
}
}
@@ -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());
}
}
@@ -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());
}
}
@@ -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());
}
}

0 comments on commit 6a1080f

Please sign in to comment.