Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Sep 23, 2018
1 parent 5262d0d commit 78340f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Http/Response.php
Expand Up @@ -1111,7 +1111,7 @@ public function type($contentType = null)
{
deprecationWarning(
'Response::type() is deprecated. ' .
'Use getType(), setType() or withType() instead.'
'Use setTypeMap(), getType() or withType() instead.'
);

if ($contentType === null) {
Expand All @@ -1138,17 +1138,17 @@ public function type($contentType = null)
}

/**
* Sets a content type into the map.
* Sets a content type definition into the map.
*
* E.g.: setType('xhtml' => ['application/xhtml+xml', 'application/xhtml', 'text/xhtml'])
* E.g.: setType('xhtml' => ['application/xhtml+xml', 'application/xhtml'])
*
* This is needed for RequestHandlerComponent and recognition of types.
*
* @param string $type Content type.
* @param string|array $mimeType Definition of the mime type.
* @return void
*/
public function setType($type, $mimeType)
public function setTypeMap($type, $mimeType)
{
$this->_mimeTypes[$type] = $mimeType;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/TestCase/Http/ResponseTest.php
Expand Up @@ -265,6 +265,30 @@ public function testGetType()
);
}

/**
* @return void
*/
public function testSetTypeMap()
{
$response = new Response();
$response->setTypeMap('ical', 'text/calendar');

$response = $response->withType('ical')->getType();
$this->assertEquals('text/calendar', $response);
}

/**
* @return void
*/
public function testSetTypeMapAsArray()
{
$response = new Response();
$response->setTypeMap('ical', ['text/calendar']);

$response = $response->withType('ical')->getType();
$this->assertEquals('text/calendar', $response);
}

/**
* Tests the withType method
*
Expand Down

0 comments on commit 78340f5

Please sign in to comment.