From 9aa6d297294c71b167bcc636a880a0ae48478bca Mon Sep 17 00:00:00 2001 From: Chris Clarke Date: Tue, 25 Aug 2015 16:50:28 +0100 Subject: [PATCH] Fixing tests, post->success --- src/IEventHook.php | 2 +- src/mongo/MongoGraph.class.php | 15 ++++++++---- src/mongo/base/DriverBase.class.php | 4 ++-- src/mongo/delegates/Updates.class.php | 2 +- test/unit/mongo/MongoGraphTest.php | 2 +- test/unit/mongo/MongoTripodDriverTest.php | 28 +++++++++++------------ 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/IEventHook.php b/src/IEventHook.php index b8b71274..a46da36c 100644 --- a/src/IEventHook.php +++ b/src/IEventHook.php @@ -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 diff --git a/src/mongo/MongoGraph.class.php b/src/mongo/MongoGraph.class.php index 436131c9..f4924854 100644 --- a/src/mongo/MongoGraph.class.php +++ b/src/mongo/MongoGraph.class.php @@ -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"); } } diff --git a/src/mongo/base/DriverBase.class.php b/src/mongo/base/DriverBase.class.php index 134d8394..bf5f8ac7 100644 --- a/src/mongo/base/DriverBase.class.php +++ b/src/mongo/base/DriverBase.class.php @@ -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"; /** @@ -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: diff --git a/src/mongo/delegates/Updates.class.php b/src/mongo/delegates/Updates.class.php index fded50a0..edf6d2de 100644 --- a/src/mongo/delegates/Updates.class.php +++ b/src/mongo/delegates/Updates.class.php @@ -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, diff --git a/test/unit/mongo/MongoGraphTest.php b/test/unit/mongo/MongoGraphTest.php index 92fbf591..1f0f484f 100644 --- a/test/unit/mongo/MongoGraphTest.php +++ b/test/unit/mongo/MongoGraphTest.php @@ -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, diff --git a/test/unit/mongo/MongoTripodDriverTest.php b/test/unit/mongo/MongoTripodDriverTest.php index c75a84fe..590977db 100755 --- a/test/unit/mongo/MongoTripodDriverTest.php +++ b/test/unit/mongo/MongoTripodDriverTest.php @@ -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); @@ -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'); @@ -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); @@ -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); @@ -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 }