From 63aaaa4a4dafdfde972849761733b121b8f63019 Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Thu, 8 Dec 2022 19:51:03 +0200 Subject: [PATCH] tryTo methods must always return Boolean result Fixes #6559 --- src/Codeception/Step/TryTo.php | 2 ++ tests/data/retries/tests/_support/Helper/Retry.php | 2 +- tests/data/retries/tests/retry.suite.yml | 1 + tests/data/retries/tests/retry/TryToCest.php | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Step/TryTo.php b/src/Codeception/Step/TryTo.php index 95505835f6..cca9eea2b2 100644 --- a/src/Codeception/Step/TryTo.php +++ b/src/Codeception/Step/TryTo.php @@ -46,6 +46,8 @@ public static function getTemplate(Template $template): ?Template return $template ->place('doc', $conditionalDoc) ->place('action', 'tryTo' . ucfirst($action)) + ->place('return', 'return ') + ->place('return_type', ': bool') ->place('step', 'TryTo'); } } diff --git a/tests/data/retries/tests/_support/Helper/Retry.php b/tests/data/retries/tests/_support/Helper/Retry.php index fe97d4e662..fba78cf64f 100644 --- a/tests/data/retries/tests/_support/Helper/Retry.php +++ b/tests/data/retries/tests/_support/Helper/Retry.php @@ -16,7 +16,7 @@ public function _before(\Codeception\TestInterface $test) $this->time = microtime(true); } - public function failAt($amount = 3) + public function failAt($amount = 3): void { if ($this->fails < $amount) { ++$this->fails; diff --git a/tests/data/retries/tests/retry.suite.yml b/tests/data/retries/tests/retry.suite.yml index 0253ef7d76..d0ae7dc981 100644 --- a/tests/data/retries/tests/retry.suite.yml +++ b/tests/data/retries/tests/retry.suite.yml @@ -2,6 +2,7 @@ actor: RetryTester modules: enabled: - \Helper\Retry + - Asserts step_decorators: - Codeception\Step\Retry - Codeception\Step\TryTo \ No newline at end of file diff --git a/tests/data/retries/tests/retry/TryToCest.php b/tests/data/retries/tests/retry/TryToCest.php index 458617d848..cceb5599b4 100644 --- a/tests/data/retries/tests/retry/TryToCest.php +++ b/tests/data/retries/tests/retry/TryToCest.php @@ -7,6 +7,7 @@ class TryToCest #[Group('ignore')] public function ignoreFailure(RetryTester $I) { - $I->tryToFailAt(1); + $result = $I->tryToFailAt(1); + $I->assertFalse($result, 'tryTo must return false on failure'); } }