Skip to content

Commit

Permalink
Merge pull request #100 from Codeception/9.0-test.useless-event
Browse files Browse the repository at this point in the history
Backport test.useless event from Codeception 5
  • Loading branch information
Naktibalda authored May 21, 2022
2 parents 7d6b1a5 + ff7f0f7 commit 4c622d0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
php: [7.3, 7.4, 8.0]

env:
CODECEPTION_VERSION: '4.1.x-dev'
CODECEPTION_VERSION: 'dev-4.2-backport-useless-test-event as 4.2.0'

steps:
- name: Checkout code
Expand Down
10 changes: 5 additions & 5 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public function prepareDependencies()

$config['name'] = 'codeception/phpunit-wrapper-test';
$config['require-dev']['codeception/codeception'] = getenv('CODECEPTION_VERSION');
$config['require-dev']['codeception/module-asserts'] = '*';
$config['require-dev']['codeception/module-cli'] = '*';
$config['require-dev']['codeception/module-db'] = '*';
$config['require-dev']['codeception/module-filesystem'] = '*';
$config['require-dev']['codeception/module-phpbrowser'] = '*';
$config['require-dev']['codeception/module-asserts'] = '^1.0 | ^2.0';
$config['require-dev']['codeception/module-cli'] = '^1.0 | ^2.0';
$config['require-dev']['codeception/module-db'] = '^1.0 | ^2.0';
$config['require-dev']['codeception/module-filesystem'] = '^1.0 | ^2.0';
$config['require-dev']['codeception/module-phpbrowser'] = '^1.0.3 | ^2.0.3';
$config['require-dev']['codeception/util-universalframework'] = '*';
$config['replace'] = ['codeception/phpunit-wrapper' => '*'];

Expand Down
2 changes: 2 additions & 0 deletions src/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function __construct(EventDispatcher $dispatcher)
*/
public function addRiskyTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->unsuccessfulTests[] = spl_object_hash($test);
$this->fire('test.useless', new FailEvent($test, $time, $e));
}

public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, float $time) : void
Expand Down
3 changes: 2 additions & 1 deletion src/ResultPrinter/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ protected function endRun():void
'successfulScenarios' => $this->successful,
'failedScenarios' => $this->failed,
'skippedScenarios' => $this->skipped,
'incompleteScenarios' => $this->incomplete
'incompleteScenarios' => $this->incomplete,
'uselessScenarios' => $this->risky,
]
);

Expand Down
19 changes: 11 additions & 8 deletions src/ResultPrinter/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function endTest(\PHPUnit\Framework\Test $test, float $time) : void
$status = 'Skipped';
} elseif ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_INCOMPLETE) {
$status = 'Incomplete';
} elseif ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_RISKY) {
$status = 'Useless';
} elseif ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_ERROR) {
$status = 'ERROR';
} else {
Expand All @@ -43,18 +45,19 @@ public function endTest(\PHPUnit\Framework\Test $test, float $time) : void

protected function endRun() : void
{
$this->write("\nCodeception Results\n");
$this->write(sprintf(
"Successful: %s. Failed: %s. Incomplete: %s. Skipped: %s",
$this->successful,
$this->failed,
$this->skipped,
$this->incomplete
) . "\n");
}

public function printResult(\PHPUnit\Framework\TestResult $result): void
{
$this->write("\nCodeception Results\n");
$this->write(sprintf(
"Successful: %d. Failed: %d. Incomplete: %d. Skipped: %d. Useless: %d",
$this->successful,
$this->failed,
$this->skipped,
$this->incomplete,
$this->risky,
) . "\n");
}

public function write(string $buffer) : void
Expand Down
6 changes: 6 additions & 0 deletions src/ResultPrinter/template/scenarios.html.dist
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
td.scenarioFailed { color: red }
.scenarioSkipped { color: teal; }
.scenarioIncomplete { color: gray; }
.scenarioUseless { color: orange; }
.scenarioStepsTable { margin-left: 10px; display: none; color: #333; }

#stepContainerSummary {
Expand Down Expand Up @@ -213,6 +214,7 @@
<li> <a href="#" title="Failed" onClick="toggleScenarios('scenarioFailed', this.parentElement)"><strong>✗</strong> {failedScenarios}</a></li>
<li> <a href="#" title="Skipped" onClick="toggleScenarios('scenarioSkipped', this.parentElement)"><strong>S</strong> {skippedScenarios}</a></li>
<li> <a href="#" title="Incomplete" onClick="toggleScenarios('scenarioIncomplete', this.parentElement)"><strong>I</strong> {incompleteScenarios}</a></li>
<li> <a href="#" title="Useless" onClick="toggleScenarios('scenarioUseless', this.parentElement)"><strong>U</strong> {uselessScenarios}</a></li>
</ul>
<div class="layout">
{header}
Expand Down Expand Up @@ -240,6 +242,10 @@
<td class="scenarioIncomplete">Incomplete scenarios:</td>
<td class="scenarioIncompleteValue"><strong>{incompleteScenarios}</strong></td>
</tr>
<tr>
<td class="scenarioUseless">Useless scenarios:</td>
<td class="scenarioUselessValue"><strong>{uselessScenarios}</strong></td>
</tr>
</table>
</div>
</td>
Expand Down

0 comments on commit 4c622d0

Please sign in to comment.