Skip to content

Commit

Permalink
Throw exceptions when cell methods are missing.
Browse files Browse the repository at this point in the history
Use reflection to capture missing cell methods and raise proper errors
on them.

Refs #3664
  • Loading branch information
markstory committed Jun 8, 2014
1 parent 4e49b63 commit 4ef17b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/View/CellTrait.php
Expand Up @@ -80,9 +80,17 @@ public function cell($cell, $data = [], $options = []) {
$data = array_values($data);
}

call_user_func_array([$cellInstance, $action], $data);

return $cellInstance;
try {
$reflect = new \ReflectionMethod($cellInstance, $action);
$reflect->invokeArgs($cellInstance, $data);
return $cellInstance;
} catch (\ReflectionException $e) {
throw new \BadMethodCallException(sprintf(
'Class %s does not have a "%s" method.',
$className,
$action
));
}
}

}
11 changes: 11 additions & 0 deletions tests/TestCase/View/CellTest.php
Expand Up @@ -147,4 +147,15 @@ public function testUnexistingCell() {
$cell = $this->View->cell('Void::echoThis', ['arg1' => 'v1', 'arg2' => 'v2']);
}

/**
* Tests missing method errors
*
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Class TestApp\View\Cell\ArticlesCell does not have a "nope" method.
* @return void
*/
public function testCellMissingMethod() {
$this->View->cell('Articles::nope');
}

}

0 comments on commit 4ef17b5

Please sign in to comment.