@@ -30,7 +30,7 @@ public function testDatabaseImmediatlyAvailable(): void
3030 {
3131 $ schemaManager = $ this ->createMock (AbstractSchemaManager::class);
3232 $ schemaManager ->expects ($ this ->once ())
33- ->method ('listTables ' )
33+ ->method ('introspectTables ' )
3434 ->willReturn (['x ' ]);
3535
3636 $ connection = $ this ->createMock (Connection::class);
@@ -48,13 +48,19 @@ public function testDatabaseImmediatlyAvailable(): void
4848
4949 public function testDatabaseAvailableAfterRetry (): void
5050 {
51+ $ callCount = 0 ;
5152 $ schemaManager = $ this ->createMock (AbstractSchemaManager::class);
5253 $ schemaManager ->expects ($ this ->any ())
53- ->method ('listTables ' )
54- ->will ($ this ->onConsecutiveCalls (
55- $ this ->throwException (new RuntimeException ('Connection failed. ' )),
56- $ this ->returnValue (['x ' ]),
57- ));
54+ ->method ('introspectTables ' )
55+ ->willReturnCallback (static function () use (&$ callCount ) {
56+ ++$ callCount ;
57+ if ($ callCount === 1 ) {
58+ // phpcs:ignore Brainbits.Exception.GlobalException.GlobalException
59+ throw new RuntimeException ('Connection failed. ' );
60+ }
61+
62+ return ['x ' ];
63+ });
5864
5965 $ connection = $ this ->createMock (Connection::class);
6066 $ connection ->expects ($ this ->any ())
@@ -69,20 +75,15 @@ public function testDatabaseAvailableAfterRetry(): void
6975 $ this ->assertSame (0 , $ result );
7076
7177 preg_match_all ('/Connection failed/ ' , $ tester ->getDisplay (), $ match );
72- $ this ->assertCount (1 , $ match [0 ] ?? [] );
78+ $ this ->assertCount (1 , $ match [0 ]);
7379 }
7480
7581 public function testDatabaseFailAfterRetry (): void
7682 {
7783 $ schemaManager = $ this ->createMock (AbstractSchemaManager::class);
7884 $ schemaManager ->expects ($ this ->any ())
79- ->method ('listTables ' )
80- ->will ($ this ->onConsecutiveCalls (
81- $ this ->throwException (new RuntimeException ('Connection failed. ' )),
82- $ this ->throwException (new RuntimeException ('Connection failed. ' )),
83- $ this ->throwException (new RuntimeException ('Connection failed. ' )),
84- $ this ->throwException (new RuntimeException ('Connection failed. ' )),
85- ));
85+ ->method ('introspectTables ' )
86+ ->willThrowException (new RuntimeException ('Connection failed. ' ));
8687
8788 $ connection = $ this ->createMock (Connection::class);
8889 $ connection ->expects ($ this ->any ())
@@ -97,6 +98,6 @@ public function testDatabaseFailAfterRetry(): void
9798 $ this ->assertSame (200 , $ result );
9899
99100 preg_match_all ('/Connection failed/ ' , $ tester ->getDisplay (), $ match );
100- $ this ->assertCount (4 , $ match [0 ] ?? [] );
101+ $ this ->assertCount (4 , $ match [0 ]);
101102 }
102103}
0 commit comments