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

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
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
18 changes: 18 additions & 0 deletions library/Zend/View/Exception/UnexpectedValueException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\View\Exception;

/**
* Unexpected value exception
*/
class UnexpectedValueException extends \UnexpectedValueException
implements ExceptionInterface
{
}
9 changes: 8 additions & 1 deletion library/Zend/View/Renderer/PhpRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,19 @@ public function render($nameOrModel, $values = null)
}
try {
ob_start();
include $this->__file;
$includeReturn = include $this->__file;
$this->__content = ob_get_clean();
} catch (\Exception $ex) {
ob_end_clean();
throw $ex;
}
if ($includeReturn === false && empty($this->__content)) {
throw new Exception\UnexpectedValueException(sprintf(
'%s: Unable to render template "%s"; file include failed',
__METHOD__,
$this->__file
));
}
}

$this->setVars(array_pop($this->__varsCache));
Expand Down
33 changes: 33 additions & 0 deletions tests/ZendTest/View/PhpRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,39 @@ public function testRendererRaisesExceptionIfResolverCannotResolveTemplate()
$test = $this->renderer->render('should-not-find-this');
}

public function invalidTemplateFiles()
{
return array(
array('/does/not/exists'),
array('.')
);
}

/**
* @dataProvider invalidTemplateFiles
*/
public function testRendererRaisesExceptionIfResolvedTemplateIsInvalid($template)
{
$resolver = new TemplateMapResolver(array(
'invalid' => $template,
));

set_error_handler(function ($errno, $errstr) { return true; }, E_WARNING);

$this->renderer->setResolver($resolver);

try {
$this->renderer->render('invalid');
$caught = false;
} catch(\Exception $e) {
$caught = $e;
}

restore_error_handler();
$this->assertInstanceOf('Zend\View\Exception\UnexpectedValueException', $caught);
$this->assertContains('file include failed', $caught->getMessage());
}

/**
* @group view-model
*/
Expand Down