Skip to content

Commit

Permalink
throw exception in render for invalid model
Browse files Browse the repository at this point in the history
  • Loading branch information
ojhaujjwal committed Aug 23, 2014
1 parent a1347d3 commit f60f2d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/View/Renderer/ImageRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@ public function render($nameOrModel, $values = null)

return $image->get($format);
}

throw new Exception\InvalidArgumentException(sprintf(
'%s expects argument 1 to be an instance of HtImgModule\View\Model\ImageModel, %s provided instead',
__METHOD__,
is_object($nameOrModel) ? get_class($nameOrModel) : gettype($nameOrModel)
));
}
}
8 changes: 8 additions & 0 deletions tests/HtImgModuleTest/View/Renderer/ImageRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use HtImgModule\View\Renderer\ImageRenderer;
use HtImgModule\View\Model\ImageModel;
use Zend\View\Model\ViewModel;

class ImageRendererTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -20,6 +21,13 @@ public function testRender()
$this->assertEquals('image-binary-string', $renderer->render($model));
}

public function testGetExceptionWhenModelIsInvalid()
{
$renderer = new ImageRenderer;
$this->setExpectedException('HtImgModule\Exception\InvalidArgumentException');
$renderer->render(new ViewModel);
}

public function testGetEngine()
{
$renderer = new ImageRenderer;
Expand Down

0 comments on commit f60f2d4

Please sign in to comment.