Skip to content

Commit fb290e5

Browse files
The test is created for the retry methods
1 parent 4e49e0d commit fb290e5

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/unit/MaxRetryTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Zeus\Mock\Tests\unit;
4+
5+
use PHPUnit\Framework\Attributes\Test;
6+
use PHPUnit\Framework\TestCase;
7+
use ReflectionException;
8+
use RuntimeException;
9+
use Zeus\Mock\Exceptions\MaxRetriedException;
10+
use Zeus\Mock\MockObjectFactory;
11+
use Zeus\Mock\Tests\stubs\Date;
12+
13+
class MaxRetryTest extends TestCase
14+
{
15+
16+
/**
17+
* @throws ReflectionException
18+
*/
19+
#[Test]
20+
public function retryWithoutAnyException(): void
21+
{
22+
23+
$mockObjectFactory = new MockObjectFactory();
24+
$counter = 0;
25+
$mockObjectFactory->retry(3, 'now', function () use (&$counter) {
26+
++$counter;
27+
if ($counter < 3) {
28+
throw new RuntimeException();
29+
}
30+
return $counter;
31+
});
32+
33+
$dateInstance = $mockObjectFactory->createMock(Date::class);
34+
35+
36+
$this->assertEquals(3, $dateInstance->now());
37+
38+
}
39+
40+
/**
41+
* @throws ReflectionException
42+
*/
43+
#[Test]
44+
public function retryCatchException(): void
45+
{
46+
$mockObjectFactory = new MockObjectFactory();
47+
$mockObjectFactory->retry(3, 'now', fn() => 5 / 0);
48+
49+
$dateInstance = $mockObjectFactory->createMock(Date::class);
50+
$this->expectException(MaxRetriedException::class);
51+
52+
$dateInstance->now();
53+
}
54+
}

0 commit comments

Comments
 (0)