Skip to content

Commit ca656a5

Browse files
committed
Unit test for [Catch exceptions in decorated method and rethrow after releasing lock]
1 parent 23c78b2 commit ca656a5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Tests/DecoratorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,20 @@ public function testFileDriverWithArrayArgument()
8989
$p->stop();
9090
return $this->assertTrue(true);
9191
}
92+
93+
/**
94+
* @expectedException \Exception
95+
* @expectedExceptionMessage something exception
96+
*/
97+
public function testLockedMethodThatThrowsException() {
98+
$decorator = new Decorator(new TestService(), 'test_service');
99+
$lock = new Lock();
100+
$lock->setDriver(new Debug())->setMethod('doSomething');
101+
$decorator->addLock($lock);
102+
103+
$decorator->doSomething(function() {
104+
throw new \Exception('something exception');
105+
});
106+
}
92107

93108
}

Tests/Stubs/TestService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public function doNothing()
2626

2727
}
2828

29+
public function doSomething($something)
30+
{
31+
call_user_func($something);
32+
}
33+
2934
}

0 commit comments

Comments
 (0)