Skip to content

Commit becc518

Browse files
committed
adds lazy file checking to allow for a widget to be created without a
file such that it'll be assigned laters
1 parent fc4f64b commit becc518

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/Widget.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ function __toString(){
4040
* for docs, check \Chevron\Widgets\WidgetInterface
4141
*/
4242
function render(){
43+
if( !file_exists($this->file) ){
44+
throw new \RuntimeException("Not a file: '{$this->file}'");
45+
}
4346
return require($this->file);
4447
}
4548

@@ -61,10 +64,6 @@ function __get($key){
6164
* change the base layout
6265
*/
6366
protected function setFile($file){
64-
if( !file_exists($file) ){
65-
throw new \InvalidArgumentException("Not a file: {$file}");
66-
}
67-
6867
$this->file = $file;
6968
}
7069

tests/PHPUnit/WidgetTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ function test___construct(){
1010
}
1111

1212
/**
13-
* @expectedException \InvalidArgumentException
13+
* @expectedException \RuntimeException
1414
*/
1515
function test___construct_exception(){
1616
$widget = new Widget(__DIR__."/exampleNOTView.php");
1717
$this->assertTrue(($widget InstanceOf Widget));
18+
$widget->render();
1819
}
1920

2021
function test___get(){

0 commit comments

Comments
 (0)