|
7 | 7 |
|
8 | 8 | class ErrorHandlerTest extends TestCase |
9 | 9 | { |
| 10 | + public function testCallThenIfRotateWasSucessfull() |
| 11 | + { |
| 12 | + file_put_contents(self::DIR_WORK.'file.log', microtime(true)); |
| 13 | + |
| 14 | + $rotation = new Rotation(); |
| 15 | + |
| 16 | + $thenCalled = false; |
| 17 | + |
| 18 | + $rotation->then(function () use (&$thenCalled) { |
| 19 | + $thenCalled = true; |
| 20 | + })->rotate(self::DIR_WORK.'file.log'); |
| 21 | + |
| 22 | + $this->assertTrue($thenCalled); |
| 23 | + } |
| 24 | + |
| 25 | + public function testNotCallThenIfRotateNotWasSucessfull() |
| 26 | + { |
| 27 | + $rotation = new Rotation(); |
| 28 | + |
| 29 | + $thenCalled = false; |
| 30 | + |
| 31 | + $rotation->then(function () use (&$thenCalled) { |
| 32 | + $thenCalled = true; |
| 33 | + })->rotate(self::DIR_WORK.'file.log'); |
| 34 | + |
| 35 | + $this->assertFalse($thenCalled); |
| 36 | + } |
| 37 | + |
10 | 38 | public function testThrowsException() |
11 | 39 | { |
12 | 40 | $this->expectException(RotationFailed::class); |
@@ -39,4 +67,50 @@ public function testCatchException() |
39 | 67 |
|
40 | 68 | $this->assertFalse($result); |
41 | 69 | } |
| 70 | + |
| 71 | + public function testCallFinallyIfRotateWasSucessfull() |
| 72 | + { |
| 73 | + file_put_contents(self::DIR_WORK.'file.log', microtime(true)); |
| 74 | + |
| 75 | + $rotation = new Rotation(); |
| 76 | + |
| 77 | + $finallyCalled = false; |
| 78 | + |
| 79 | + $rotation->finally(function () use (&$finallyCalled) { |
| 80 | + $finallyCalled = true; |
| 81 | + })->rotate(self::DIR_WORK.'file.log'); |
| 82 | + |
| 83 | + $this->assertTrue($finallyCalled); |
| 84 | + } |
| 85 | + |
| 86 | + public function testCallFinallyIfFileDontExists() |
| 87 | + { |
| 88 | + $rotation = new Rotation(); |
| 89 | + |
| 90 | + $finallyCalled = false; |
| 91 | + |
| 92 | + $rotation->finally(function () use (&$finallyCalled) { |
| 93 | + $finallyCalled = true; |
| 94 | + })->rotate(self::DIR_WORK.'file.log'); |
| 95 | + |
| 96 | + $this->assertTrue($finallyCalled); |
| 97 | + } |
| 98 | + |
| 99 | + public function testCallFinallyIfThrowException() |
| 100 | + { |
| 101 | + $this->expectException(RotationFailed::class); |
| 102 | + |
| 103 | + $rotation = new Rotation(); |
| 104 | + |
| 105 | + touch(self::DIR_WORK.'/file.log'); |
| 106 | + chmod(self::DIR_WORK.'/file.log', 0444); |
| 107 | + |
| 108 | + $finallyCalled = false; |
| 109 | + |
| 110 | + $rotation->finally(function () use (&$finallyCalled) { |
| 111 | + $finallyCalled = true; |
| 112 | + })->rotate(self::DIR_WORK.'file.log'); |
| 113 | + |
| 114 | + $this->assertTrue($finallyCalled); |
| 115 | + } |
42 | 116 | } |
0 commit comments