Skip to content

Commit

Permalink
Fixing tests, post->success
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Clarke committed Aug 25, 2015
1 parent bf3837e commit 9aa6d29
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/IEventHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function pre(array $args);
* If the event throws an exception or fatal error, this method will not be called.
* @param $args array of arguments
*/
public function post(array $args);
public function success(array $args);

/**
* This method gets called if the event failed for any reason. The arguments passed should be the same as IEventHook::pre
Expand Down
15 changes: 11 additions & 4 deletions src/mongo/MongoGraph.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,25 @@ private function add_tarray_to_index($tarray)
$predObjects = array();
foreach ($tarray as $key=>$value)
{
if($key[0] != '_')
if (empty($key))
{
throw new \Tripod\Exceptions\Exception("The predicate cannot be an empty string");
}
else if($key[0] != '_')
{
$predicate = $this->qname_to_uri($key);
$graphValueObject = $this->toGraphValueObject($value);
// Only add if valid values have been found
if (!empty($graphValueObject)) {
if (!empty($graphValueObject))
{
$predObjects[$predicate] = $graphValueObject;
}
}
else if($key == "_id"){
else if($key == "_id")
{
// If the subject is invalid then throw an exception
if(!isset($value['r']) || !$this->isValidResource($value['r'])){
if(!isset($value['r']) || !$this->isValidResource($value['r']))
{
throw new \Tripod\Exceptions\Exception("The subject cannot be an empty string");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/base/DriverBase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class DriverBase
* constants for the supported hook functions that can be applied
*/
const HOOK_FN_PRE = "pre";
const HOOK_FN_POST = "post";
const HOOK_FN_SUCCESS = "success";
const HOOK_FN_FAILURE = "failure";

/**
Expand Down Expand Up @@ -389,7 +389,7 @@ protected function applyHooks($fn,$hooks,$args=array())
{
switch ($fn) {
case $this::HOOK_FN_PRE:
case $this::HOOK_FN_POST:
case $this::HOOK_FN_SUCCESS:
case $this::HOOK_FN_FAILURE:
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/delegates/Updates.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function saveChanges(
$this->queueAsyncOperations($subjectsAndPredicatesOfChange,$contextAlias);
}

$this->applyHooks($this::HOOK_FN_POST,$this->saveChangesHooks,array(
$this->applyHooks($this::HOOK_FN_SUCCESS,$this->saveChangesHooks,array(
"pod"=>$this->getPodName(),
"oldGraph"=>$oldGraph,
"newGraph"=>$newGraph,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mongo/MongoGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function addTripodArrayContainingInvalidPredicates_Provider(){
public function testAddTripodArrayContainingEmptyPredicate()
{
// Should not be able to label ''
$this->setExpectedException('\Tripod\Exceptions\LabellerException');
$this->setExpectedException('\Tripod\Exceptions\Exception','The predicate cannot be an empty string');
$doc = array(
"_id"=>array("r"=>"http://talisaspire.com/works/4d101f63c10a6-2", "c"=>"http://talisaspire.com/works/4d101f63c10a6-2"),
"_version"=>0,
Expand Down
28 changes: 14 additions & 14 deletions test/unit/mongo/MongoTripodDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1980,14 +1980,14 @@ public function testRemoveInertLocks()
/** START: saveChangesHooks tests */
public function testRegisteredHooksAreCalled()
{
$mockHookA = $this->getMock("TestSaveChangesHookA", array('pre', 'post'), array(), '', false);
$mockHookB = $this->getMock("TestSaveChangesHookB", array('pre', 'post'), array(), '', false);
$mockHookA = $this->getMock("TestSaveChangesHookA", array('pre', 'success'), array(), '', false);
$mockHookB = $this->getMock("TestSaveChangesHookB", array('pre', 'success'), array(), '', false);

$mockHookA->expects($this->once())->method("pre");
$mockHookA->expects($this->once())->method("post");
$mockHookA->expects($this->once())->method("success");
$mockHookA->expects($this->never())->method("failure");
$mockHookB->expects($this->once())->method("pre");
$mockHookB->expects($this->once())->method("post");
$mockHookB->expects($this->once())->method("success");
$mockHookB->expects($this->never())->method("failure");

$this->tripod->registerHook(\Tripod\IEventHook::EVENT_SAVE_CHANGES,$mockHookA);
Expand All @@ -1996,7 +1996,7 @@ public function testRegisteredHooksAreCalled()
$this->tripod->saveChanges(new \Tripod\ExtendedGraph(),new \Tripod\ExtendedGraph());
}

public function testRegisteredPostHooksAreNotCalledOnException()
public function testRegisteredSuccessHooksAreNotCalledOnException()
{
$this->setExpectedException('\Tripod\Exceptions\Exception','Could not validate');

Expand All @@ -2008,15 +2008,15 @@ public function testRegisteredPostHooksAreNotCalledOnException()
);

/* @var $mockHookA \Tripod\IEventHook|PHPUnit_Framework_MockObject_MockObject*/
$mockHookA = $this->getMock("TestSaveChangesHookA", array('pre', 'post', 'failure'), array(), '', false);
$mockHookA = $this->getMock("TestSaveChangesHookA", array('pre', 'success', 'failure'), array(), '', false);
/* @var $mockHookB \Tripod\IEventHook|PHPUnit_Framework_MockObject_MockObject*/
$mockHookB = $this->getMock("TestSaveChangesHookB", array('pre', 'post', 'failure'), array(), '', false);
$mockHookB = $this->getMock("TestSaveChangesHookB", array('pre', 'success', 'failure'), array(), '', false);

$mockHookA->expects($this->once())->method("pre");
$mockHookA->expects($this->never())->method("post");
$mockHookA->expects($this->never())->method("success");
$mockHookA->expects($this->once())->method("failure");
$mockHookB->expects($this->once())->method("pre");
$mockHookB->expects($this->never())->method("post");
$mockHookB->expects($this->never())->method("success");
$mockHookB->expects($this->once())->method("failure");

$tripodUpdate->registerSaveChangesEventHook($mockHookA);
Expand All @@ -2028,14 +2028,14 @@ public function testRegisteredPostHooksAreNotCalledOnException()

public function testMisbehavingHookDoesNotPreventSaveOrInterfereWithOtherHooks()
{
$mockHookA = $this->getMock("TestSaveChangesHookA", array('pre', 'post'), array(), '', false);
$mockHookB = $this->getMock("TestSaveChangesHookB", array('pre', 'post'), array(), '', false);
$mockHookA = $this->getMock("TestSaveChangesHookA", array('pre', 'success'), array(), '', false);
$mockHookB = $this->getMock("TestSaveChangesHookB", array('pre', 'success'), array(), '', false);

$mockHookA->expects($this->once())->method("pre")->will($this->throwException(new Exception("Misbehaving hook")));
$mockHookA->expects($this->once())->method("post")->will($this->throwException(new Exception("Misbehaving hook")));
$mockHookA->expects($this->once())->method("success")->will($this->throwException(new Exception("Misbehaving hook")));
$mockHookA->expects($this->never())->method("failure");
$mockHookB->expects($this->once())->method("pre");
$mockHookB->expects($this->once())->method("post");
$mockHookB->expects($this->once())->method("success");
$mockHookB->expects($this->never())->method("failure");

$this->tripod->registerHook(\Tripod\IEventHook::EVENT_SAVE_CHANGES,$mockHookA);
Expand Down Expand Up @@ -2065,7 +2065,7 @@ public function pre(array $args)
* If the event throws an exception or fatal error, this method will not be called.
* @param $args array of arguments
*/
public function post(array $args)
public function success(array $args)
{
// do nothing
}
Expand Down

0 comments on commit 9aa6d29

Please sign in to comment.