From 8da59322002243d4fa2f14ebecb914ae792da8da Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Sun, 18 Dec 2022 13:17:24 +0200 Subject: [PATCH 1/2] Tests for skip annotation and attribute --- tests/cli/RunSkippedCest.php | 80 +++++++++++++++++++ tests/data/skip/codeception.yml | 9 +++ tests/data/skip/tests/_output/.gitignore | 2 + tests/data/skip/tests/_support/UnitTester.php | 21 +++++ .../skip/tests/_support/_generated/.gitignore | 2 + tests/data/skip/tests/unit.suite.yml | 1 + ...lassLevelSkipAnnotationWithMessageCest.php | 19 +++++ ...sLevelSkipAnnotationWithoutMessageCest.php | 19 +++++ ...ClassLevelSkipAttributeWithMessageCest.php | 18 +++++ ...ssLevelSkipAttributeWithoutMessageCest.php | 18 +++++ ...thodLevelSkipAnnotationWithMessageCest.php | 19 +++++ ...dLevelSkipAnnotationWithoutMessageCest.php | 19 +++++ ...ethodLevelSkipAttributeWithMessageCest.php | 18 +++++ ...odLevelSkipAttributeWithoutMessageCest.php | 18 +++++ 14 files changed, 263 insertions(+) create mode 100644 tests/cli/RunSkippedCest.php create mode 100644 tests/data/skip/codeception.yml create mode 100644 tests/data/skip/tests/_output/.gitignore create mode 100644 tests/data/skip/tests/_support/UnitTester.php create mode 100644 tests/data/skip/tests/_support/_generated/.gitignore create mode 100644 tests/data/skip/tests/unit.suite.yml create mode 100644 tests/data/skip/tests/unit/ClassLevelSkipAnnotationWithMessageCest.php create mode 100644 tests/data/skip/tests/unit/ClassLevelSkipAnnotationWithoutMessageCest.php create mode 100644 tests/data/skip/tests/unit/ClassLevelSkipAttributeWithMessageCest.php create mode 100644 tests/data/skip/tests/unit/ClassLevelSkipAttributeWithoutMessageCest.php create mode 100644 tests/data/skip/tests/unit/MethodLevelSkipAnnotationWithMessageCest.php create mode 100644 tests/data/skip/tests/unit/MethodLevelSkipAnnotationWithoutMessageCest.php create mode 100644 tests/data/skip/tests/unit/MethodLevelSkipAttributeWithMessageCest.php create mode 100644 tests/data/skip/tests/unit/MethodLevelSkipAttributeWithoutMessageCest.php diff --git a/tests/cli/RunSkippedCest.php b/tests/cli/RunSkippedCest.php new file mode 100644 index 0000000000..e3a5f4250e --- /dev/null +++ b/tests/cli/RunSkippedCest.php @@ -0,0 +1,80 @@ +amInPath('tests/data/skip'); + $I->executeCommand('run -v --no-ansi unit ClassLevelSkipAnnotationWithMessageCest.php'); + $I->seeInShellOutput("S ClassLevelSkipAnnotationWithMessageCest: Method1"); + $I->seeInShellOutput("S ClassLevelSkipAnnotationWithMessageCest: Method2"); + $I->seeInShellOutput('Skip message'); + $I->seeInShellOutput('OK, but incomplete, skipped, or useless tests!'); + } + + public function classLevelSkipAnnotationWithoutMessage(CliGuy $I): void + { + $I->amInPath('tests/data/skip'); + $I->executeCommand('run -v --no-ansi unit ClassLevelSkipAnnotationWithoutMessageCest.php'); + $I->seeInShellOutput("S ClassLevelSkipAnnotationWithoutMessageCest: Method1"); + $I->seeInShellOutput("S ClassLevelSkipAnnotationWithoutMessageCest: Method2"); + $I->seeInShellOutput('OK, but incomplete, skipped, or useless tests!'); + } + + public function classLevelSkipAttributeWithMessage(CliGuy $I): void + { + $I->amInPath('tests/data/skip'); + $I->executeCommand('run -v --no-ansi unit ClassLevelSkipAttributeWithMessageCest.php'); + $I->seeInShellOutput("S ClassLevelSkipAttributeWithMessageCest: Method1"); + $I->seeInShellOutput("S ClassLevelSkipAttributeWithMessageCest: Method2"); + $I->seeInShellOutput('Skip message'); + $I->seeInShellOutput('OK, but incomplete, skipped, or useless tests!'); + } + + public function classLevelSkipAttributeWithoutMessage(CliGuy $I): void + { + $I->amInPath('tests/data/skip'); + $I->executeCommand('run -v --no-ansi unit ClassLevelSkipAttributeWithoutMessageCest.php'); + $I->seeInShellOutput("S ClassLevelSkipAttributeWithoutMessageCest: Method1"); + $I->seeInShellOutput("S ClassLevelSkipAttributeWithoutMessageCest: Method2"); + $I->seeInShellOutput('OK, but incomplete, skipped, or useless tests!'); + } + + public function methodLevelSkipAnnotationWithMessage(CliGuy $I): void + { + $I->amInPath('tests/data/skip'); + $I->executeCommand('run -v --no-ansi unit MethodLevelSkipAnnotationWithMessageCest.php'); + $I->seeInShellOutput("+ MethodLevelSkipAnnotationWithMessageCest: Method1"); + $I->seeInShellOutput("S MethodLevelSkipAnnotationWithMessageCest: Method2"); + $I->seeInShellOutput('Skip message'); + $I->seeInShellOutput('OK, but incomplete, skipped, or useless tests!'); + } + + public function methodLevelSkipAnnotationWithoutMessage(CliGuy $I): void + { + $I->amInPath('tests/data/skip'); + $I->executeCommand('run -v --no-ansi unit MethodLevelSkipAnnotationWithoutMessageCest.php'); + $I->seeInShellOutput("+ MethodLevelSkipAnnotationWithoutMessageCest: Method1"); + $I->seeInShellOutput("S MethodLevelSkipAnnotationWithoutMessageCest: Method2"); + $I->seeInShellOutput('OK, but incomplete, skipped, or useless tests!'); + } + + public function methodLevelSkipAttributeWithMessage(CliGuy $I): void + { + $I->amInPath('tests/data/skip'); + $I->executeCommand('run -v --no-ansi unit MethodLevelSkipAttributeWithMessageCest.php'); + $I->seeInShellOutput("S MethodLevelSkipAttributeWithMessageCest: Method1"); + $I->seeInShellOutput("+ MethodLevelSkipAttributeWithMessageCest: Method2"); + $I->seeInShellOutput('Skip message'); + $I->seeInShellOutput('OK, but incomplete, skipped, or useless tests!'); + } + + public function methodLevelSkipAttributeWithoutMessage(CliGuy $I): void + { + $I->amInPath('tests/data/skip'); + $I->executeCommand('run -v --no-ansi unit MethodLevelSkipAttributeWithoutMessageCest.php'); + $I->seeInShellOutput("+ MethodLevelSkipAttributeWithoutMessageCest: Method1"); + $I->seeInShellOutput("S MethodLevelSkipAttributeWithoutMessageCest: Method2"); + $I->seeInShellOutput('OK, but incomplete, skipped, or useless tests!'); + } +} diff --git a/tests/data/skip/codeception.yml b/tests/data/skip/codeception.yml new file mode 100644 index 0000000000..23e6178faa --- /dev/null +++ b/tests/data/skip/codeception.yml @@ -0,0 +1,9 @@ +paths: + tests: tests + output: tests/_output + data: tests/_data + support: tests/_support + envs: tests/_envs +actor_suffix: Tester +settings: + colors: false \ No newline at end of file diff --git a/tests/data/skip/tests/_output/.gitignore b/tests/data/skip/tests/_output/.gitignore new file mode 100644 index 0000000000..c96a04f008 --- /dev/null +++ b/tests/data/skip/tests/_output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/tests/data/skip/tests/_support/UnitTester.php b/tests/data/skip/tests/_support/UnitTester.php new file mode 100644 index 0000000000..f652cb5e4c --- /dev/null +++ b/tests/data/skip/tests/_support/UnitTester.php @@ -0,0 +1,21 @@ + Date: Sun, 18 Dec 2022 13:54:40 +0200 Subject: [PATCH 2/2] Fix bugs of skip annotation and attribute See #6615 --- src/Codeception/Test/Metadata.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Codeception/Test/Metadata.php b/src/Codeception/Test/Metadata.php index 2c140ceb68..ef4e2961be 100644 --- a/src/Codeception/Test/Metadata.php +++ b/src/Codeception/Test/Metadata.php @@ -198,12 +198,14 @@ public function setParamsFromAnnotations($annotations): void $params = Annotation::fetchAllAnnotationsFromDocblock((string)$annotations); $this->params = array_merge_recursive($this->params, $params); - // set singular value for some params + $this->setSingularValueForSomeParams(); + } + + private function setSingularValueForSomeParams(): void + { foreach (['skip', 'incomplete'] as $single) { - if (empty($this->params[$single])) { - $this->params[$single] = null; - } else { - $this->params[$single] = (string)($this->params[$single][0] ?? $this->params[$single][1]); + if (is_array($this->params[$single])) { + $this->params[$single] = $this->params[$single][0] ?? $this->params[$single][1] ?? ''; } } } @@ -235,13 +237,12 @@ public function setParamsFromAttributes($attributes): void $this->params[$single] = array_merge(...$this->params[$single]); } - - // set singular value for some params - foreach (['skip', 'incomplete'] as $single) { - $this->params[$single] = empty($this->params[$single]) ? null : (string)$this->params[$single][0]; - } + $this->setSingularValueForSomeParams(); } + /** + * @deprecated + */ public function setParams(array $params): void { $this->params = array_merge_recursive($this->params, $params);