Skip to content

Commit

Permalink
Test creating response content with invalid source
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Aug 12, 2014
1 parent 62b377e commit 55f75ca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Core/Exception/InvalidArgumentTypeException.php
@@ -0,0 +1,11 @@
<?php
/**
* Thrown when a method is called with an invalid argument type.
*
* PHP.Gt (http://php.gt)
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com)
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses
*/
namespace Gt\Core\Exception;

class InvalidArgumentTypeException extends GtException {}#
5 changes: 4 additions & 1 deletion src/Dispatcher/PageDispatcher.php
Expand Up @@ -97,7 +97,10 @@ public function loadSource($path, $pathFile) {
}

public function createResponseContent($html) {

if(!is_string($html)) {
throw new \Gt\Core\Exception\InvalidArgumentTypeException(
gettype($html) . " is not a string");
}
$domDocument = new \Gt\Response\Dom\Document($html);

return $domDocument;
Expand Down
14 changes: 12 additions & 2 deletions test/Unit/Dispatcher/PageDispatcher.test.php
Expand Up @@ -201,9 +201,19 @@ public function testLoadSourceFromPathWithHeaderFooter($uri) {
$this->assertEquals("header datadummy datafooter data", $source);
}

// public function testCreateResponseContentFromHtml() {
public function testCreateResponseContentFromHtml() {
$html = "<!doctype html><h1>Test!</h1>";
$responseContent = $this->dispatcher->createResponseContent($html);
$this->assertInstanceOf("\Gt\Response\ResponseContent", $responseContent);
$this->assertInstanceOf("\Gt\Response\Dom\Document", $responseContent);
}

// }
public function testCreateResponseContentThrowsTypeException() {
$this->setExpectedException(
"\Gt\Core\Exception\InvalidArgumentTypeException");
$notHtml = new \StdClass();
$responseContent = $this->dispatcher->createResponseContent($notHtml);
}

// public function testGetFilenameRequestedFromUri() {
// // Or index filename if none set.
Expand Down

0 comments on commit 55f75ca

Please sign in to comment.