diff --git a/src/Core/Retry/CommandRetry.php b/src/Core/Retry/CommandRetry.php index cbbdf828ec1..a505e9ee139 100644 --- a/src/Core/Retry/CommandRetry.php +++ b/src/Core/Retry/CommandRetry.php @@ -61,8 +61,8 @@ public function run(callable $action) { $retryCount = 0; $lastException = null; - while ($this->retries > $retryCount) { - $retryCount++; + + do { try { return $action(); } catch (Exception $e) { @@ -71,7 +71,7 @@ public function run(callable $action) throw $e; } } - } + } while ($this->retries > $retryCount++); if ($lastException !== null) { throw $lastException; diff --git a/tests/TestCase/Core/Retry/CommandRetryTest.php b/tests/TestCase/Core/Retry/CommandRetryTest.php index 43d50393f65..50853b85326 100644 --- a/tests/TestCase/Core/Retry/CommandRetryTest.php +++ b/tests/TestCase/Core/Retry/CommandRetryTest.php @@ -49,13 +49,13 @@ public function testRetry() ->method('shouldRetry') ->will($this->returnCallback(function ($e, $c) use ($exception, &$count) { $this->assertSame($e, $exception); - $this->assertEquals($c, $count); + $this->assertEquals($c + 1, $count); return true; })); $retry = new CommandRetry($strategy, 5); - $retry->run($action); + $this->assertEquals(4, $retry->run($action)); } /** @@ -72,7 +72,7 @@ public function testExceedAttempts() $strategy = $this->getMockBuilder(RetryStrategyInterface::class)->getMock(); $strategy - ->expects($this->exactly(3)) + ->expects($this->exactly(4)) ->method('shouldRetry') ->will($this->returnCallback(function ($e) use ($exception) { return true; diff --git a/tests/TestCase/Database/ConnectionTest.php b/tests/TestCase/Database/ConnectionTest.php index 772ae8f3fa1..796775a8c53 100644 --- a/tests/TestCase/Database/ConnectionTest.php +++ b/tests/TestCase/Database/ConnectionTest.php @@ -1249,7 +1249,8 @@ public function testAutomaticReconnect() ->method('prepare') ->will($this->returnValue($statement)); - $this->assertSame($statement, $conn->query('SELECT 1')); + $res = $conn->query('SELECT 1'); + $this->assertInstanceOf('Cake\Database\StatementInterface', $res); } /**