Skip to content

Commit

Permalink
abstracting a manual event call
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Sep 29, 2012
1 parent a970406 commit 8f61c5e
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions Core/Events/Test/Lib/InfinitasEventTestCase.php
Expand Up @@ -55,6 +55,29 @@ protected function _loadEventClass() {
$this->EventClass = new $this->EventClass();
}

/**
* @brief manuall call an event
*
* This will manually call an event to get the return, for auto testing of triggers
* that do not use complex checks, just standard returns.
*
* @param string $event the name of the event
* @param Event $object the event object that would be passed
*
* @return array
*/
protected function _manualCall($event, $object = null) {
$method = 'on' . ucfirst($event);
$expected = array($event => array(call_user_func_array(array($this->EventClass, $method), array($object))));
$return = current(array_filter($expected[$event]));
$expected[$event] = array();
if($return) {
$expected[$event] = array($this->plugin => $return);
}

return $expected;
}

/**
* @brief test the instance is loaded correctly
*/
Expand All @@ -66,12 +89,7 @@ public function testInstance() {
* @brief test getting the plugins details
*/
public function testPluginRollCall() {
$expected = array('pluginRollCall' => array($this->EventClass->onPluginRollCall()));
$return = current(array_filter($expected['pluginRollCall']));
$expected['pluginRollCall'] = array();
if($return) {
$expected['pluginRollCall'] = array($this->plugin => $return);
}
$expected = $this->_manualCall('pluginRollCall');

$result = $this->Event->trigger($this->ObjectObject, $this->plugin . '.pluginRollCall');
$this->assertEquals($expected, $result);
Expand All @@ -81,12 +99,7 @@ public function testPluginRollCall() {
* @brief test getting additional db configs
*/
public function testRequireDatabaseConfigs() {
$expected = array('requireDatabaseConfigs' => array($this->EventClass->onRequireDatabaseConfigs($this->ModelEvent)));
$return = current(array_filter($expected['requireDatabaseConfigs']));
$expected['requireDatabaseConfigs'] = array();
if($return) {
$expected['requireDatabaseConfigs'] = array($this->plugin => $return);
}
$expected = $this->_manualCall('requireDatabaseConfigs', $this->ObjectEvent);

$result = $this->Event->trigger($this->ModelObject, $this->plugin . '.requireDatabaseConfigs');
$this->assertEquals($expected, $result);
Expand Down

0 comments on commit 8f61c5e

Please sign in to comment.