Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix skip issues #6617

Merged
merged 2 commits into from Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/Codeception/Test/Metadata.php
Expand Up @@ -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] ?? '';
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
80 changes: 80 additions & 0 deletions tests/cli/RunSkippedCest.php
@@ -0,0 +1,80 @@
<?php

class RunSkippedCest
{
public function classLevelSkipAnnotationWithMessage(CliGuy $I): void
{
$I->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!');
}
}
9 changes: 9 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions tests/data/skip/tests/_output/.gitignore
@@ -0,0 +1,2 @@
*
!.gitignore
21 changes: 21 additions & 0 deletions tests/data/skip/tests/_support/UnitTester.php
@@ -0,0 +1,21 @@
<?php

/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method self execute($callable)
* @method self expectTo($prediction)
* @method self expect($prediction)
* @method self amGoingTo($argumentation)
* @method self am($role)
* @method self lookForwardTo($achieveValue)
* @method self comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
}
2 changes: 2 additions & 0 deletions tests/data/skip/tests/_support/_generated/.gitignore
@@ -0,0 +1,2 @@
*
!.gitignore
1 change: 1 addition & 0 deletions tests/data/skip/tests/unit.suite.yml
@@ -0,0 +1 @@
actor: UnitTester
@@ -0,0 +1,19 @@
<?php

namespace Unit;

use UnitTester;

/**
* @skip Skip message
*/
class ClassLevelSkipAnnotationWithMessageCest
{
public function method1(UnitTester $I)
{
}

public function method2(UnitTester $I)
{
}
}
@@ -0,0 +1,19 @@
<?php

namespace Unit;

use UnitTester;

/**
* @skip
*/
class ClassLevelSkipAnnotationWithoutMessageCest
{
public function method1(UnitTester $I)
{
}

public function method2(UnitTester $I)
{
}
}
@@ -0,0 +1,18 @@
<?php

namespace Unit;

use Codeception\Attribute\Skip;
use UnitTester;

#[Skip('Skip message')]
class ClassLevelSkipAttributeWithMessageCest
{
public function method1(UnitTester $I)
{
}

public function method2(UnitTester $I)
{
}
}
@@ -0,0 +1,18 @@
<?php

namespace Unit;

use Codeception\Attribute\Skip;
use UnitTester;

#[Skip]
class ClassLevelSkipAttributeWithoutMessageCest
{
public function method1(UnitTester $I)
{
}

public function method2(UnitTester $I)
{
}
}
@@ -0,0 +1,19 @@
<?php

namespace Unit;

use UnitTester;

class MethodLevelSkipAnnotationWithMessageCest
{
public function method1(UnitTester $I)
{
}

/**
* @skip Skip message
*/
public function method2(UnitTester $I)
{
}
}
@@ -0,0 +1,19 @@
<?php

namespace Unit;

use UnitTester;

class MethodLevelSkipAnnotationWithoutMessageCest
{
public function method1(UnitTester $I)
{
}

/**
* @skip
*/
public function method2(UnitTester $I)
{
}
}
@@ -0,0 +1,18 @@
<?php

namespace Unit;

use Codeception\Attribute\Skip;
use UnitTester;

class MethodLevelSkipAttributeWithMessageCest
{
#[Skip('Skip message')]
public function method1(UnitTester $I)
{
}

public function method2(UnitTester $I)
{
}
}
@@ -0,0 +1,18 @@
<?php

namespace Unit;

use Codeception\Attribute\Skip;
use UnitTester;

class MethodLevelSkipAttributeWithoutMessageCest
{
public function method1(UnitTester $I)
{
}

#[Skip]
public function method2(UnitTester $I)
{
}
}