File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments