33namespace malkusch \lock \mutex ;
44
55use Eloquent \Liberator \Liberator ;
6+ use malkusch \lock \exception \DeadlineException ;
7+ use malkusch \lock \exception \TimeoutException ;
68use malkusch \lock \util \PcntlTimeout ;
79use PHPUnit \Framework \TestCase ;
810
@@ -24,15 +26,15 @@ class FlockMutexTest extends TestCase
2426 */
2527 private $ file ;
2628
27- protected function setUp ()
29+ protected function setUp (): void
2830 {
2931 parent ::setUp ();
3032
3133 $ this ->file = tempnam (sys_get_temp_dir (), 'flock- ' );
3234 $ this ->mutex = Liberator::liberate (new FlockMutex (fopen ($ this ->file , 'r ' ), 1 ));
3335 }
3436
35- protected function tearDown ()
37+ protected function tearDown (): void
3638 {
3739 unlink ($ this ->file );
3840
@@ -54,12 +56,13 @@ public function testCodeExecutedOutsideLockIsNotThrown(int $strategy)
5456 }
5557
5658 /**
57- * @expectedException \malkusch\lock\exception\TimeoutException
58- * @expectedExceptionMessage Timeout of 1 seconds exceeded.
5959 * @dataProvider dpTimeoutableStrategies
6060 */
6161 public function testTimeoutOccurs (int $ strategy )
6262 {
63+ $ this ->expectException (TimeoutException::class);
64+ $ this ->expectExceptionMessage ('Timeout of 1 seconds exceeded. ' );
65+
6366 $ another_resource = fopen ($ this ->file , 'r ' );
6467 flock ($ another_resource , LOCK_EX );
6568
@@ -84,19 +87,18 @@ public function dpTimeoutableStrategies()
8487 ];
8588 }
8689
87- /**
88- * @expectedException \malkusch\lock\exception\DeadlineException
89- */
9090 public function testNoTimeoutWaitsForever ()
9191 {
92+ $ this ->expectException (DeadlineException::class);
93+
9294 $ another_resource = fopen ($ this ->file , 'r ' );
9395 flock ($ another_resource , LOCK_EX );
9496
9597 $ this ->mutex ->strategy = FlockMutex::STRATEGY_BLOCK ;
9698
9799 $ timebox = new PcntlTimeout (1 );
98100 $ timebox ->timeBoxed (function () {
99- $ this ->mutex ->synchronized (function () {
101+ $ this ->mutex ->synchronized (function (): void {
100102 $ this ->fail ('Did not expect code execution. ' );
101103 });
102104 });
0 commit comments