-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #13058: Fixed caught exception thrown during view file renderin…
…g produces wrong output
- Loading branch information
1 parent
17a1d91
commit 0beb593
Showing
3 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace yiiunit\framework\base; | ||
|
||
use Yii; | ||
use yii\base\View; | ||
use yii\helpers\FileHelper; | ||
use yiiunit\TestCase; | ||
|
||
/** | ||
* @group base | ||
*/ | ||
class ViewTest extends TestCase | ||
{ | ||
/** | ||
* @var string path for the test files. | ||
*/ | ||
protected $testViewPath = ''; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->mockApplication(); | ||
$this->testViewPath = Yii::getAlias('@yiiunit/runtime') . DIRECTORY_SEPARATOR . str_replace('\\', '_', get_class($this)) . uniqid(); | ||
FileHelper::createDirectory($this->testViewPath); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
FileHelper::removeDirectory($this->testViewPath); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* @see https://github.com/yiisoft/yii2/issues/13058 | ||
*/ | ||
public function testExceptionOnRenderFile() | ||
{ | ||
$view = new View(); | ||
|
||
$exceptionViewFile = $this->testViewPath . DIRECTORY_SEPARATOR . 'exception.php'; | ||
file_put_contents($exceptionViewFile, <<<PHP | ||
<h1>Exception</h1> | ||
<?php throw new Exception('Test Exception'); ?> | ||
PHP | ||
); | ||
$normalViewFile = $this->testViewPath . DIRECTORY_SEPARATOR . 'no-exception.php'; | ||
file_put_contents($normalViewFile, <<<PHP | ||
<h1>No Exception</h1> | ||
PHP | ||
); | ||
|
||
$obInitialLevel = ob_get_level(); | ||
|
||
try { | ||
$view->renderFile($exceptionViewFile); | ||
} catch (\Exception $e) { | ||
// shutdown exception | ||
} | ||
$view->renderFile($normalViewFile); | ||
|
||
$this->assertEquals($obInitialLevel, ob_get_level()); | ||
} | ||
} |