-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from xp-framework/refactor/extract-ouput
Extract output into a dedicated class
- Loading branch information
Showing
12 changed files
with
519 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php namespace xp\test; | ||
|
||
use util\cmd\Console; | ||
|
||
/** | ||
* Dot output adds a "." to the console for every finished test, | ||
* wrapping the lines at 72 characters. | ||
*/ | ||
class Dots extends Report { | ||
use Summary; | ||
|
||
private $offset; | ||
|
||
/** Called when test run starts */ | ||
public function start($sources) { | ||
Console::write('['); | ||
$this->offset= 1; | ||
} | ||
|
||
/** Called when a test finished */ | ||
public function finished($group, $test, $outcome) { | ||
Console::write('.'); | ||
|
||
if (++$this->offset > 72) { | ||
Console::writeLine(); | ||
$this->offset= 0; | ||
} | ||
} | ||
|
||
/** | ||
* Print out summary of test run | ||
* | ||
* @param test.execution.Metrics $metrices | ||
* @param float $overall | ||
* @param [:test.Outcome] $failures | ||
* @return void | ||
*/ | ||
public function summary($metrics, $overall, $failures) { | ||
Console::writeLine(']'); | ||
Console::writeLine(); | ||
|
||
$this->failures($failures); | ||
$this->metrics($metrics, $overall); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php namespace xp\test; | ||
|
||
use util\cmd\Console; | ||
|
||
/** | ||
* Grouped output, the default output mechanism, using console colors | ||
* and a progress bar while running a test group. | ||
*/ | ||
class Grouped extends Report { | ||
use Summary; | ||
|
||
const PROGRESS= ['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷']; | ||
const GROUPS= [ | ||
'success' => "\033[42;1;37m PASS \033[0m", | ||
'failure' => "\033[41;1;37m FAIL \033[0m", | ||
'stopped' => "\033[47;1;30m STOP \033[0m", | ||
'skipped' => "\033[43;1;37m SKIP \033[0m", | ||
]; | ||
const CASES= [ | ||
'success' => "\033[32m✓\033[0m", | ||
'failure' => "\033[31m⨯\033[0m", | ||
'skipped' => "\033[33m⦾\033[0m", | ||
]; | ||
const COUNTS= [ | ||
'success' => "\033[32m%d succeeded\033[0m", | ||
'failure' => "\033[31m%d failed\033[0m", | ||
'skipped' => "\033[33m%d skipped\033[0m", | ||
]; | ||
|
||
/** | ||
* Enter a group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @return void | ||
*/ | ||
public function enter($group) { | ||
Console::writef("\r> \033[44;1;37m RUN… \033[0m \033[37m%s\033[0m", $group->name()); | ||
} | ||
|
||
/** | ||
* Running a given test | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param test.execution.TestCase $test | ||
* @param int $n | ||
* @return void | ||
*/ | ||
public function running($group, $test, $n) { | ||
Console::writef("\r%s", self::PROGRESS[$n % 8]); // sizeof(self::PROGRESS) | ||
} | ||
|
||
/** | ||
* Report test case summary. Used by `pass()` and `fail()`. | ||
* | ||
* @param test.Outcome[] $results | ||
* @return void | ||
*/ | ||
private function summarize($results) { | ||
foreach ($results as $outcome) { | ||
$kind= $outcome->kind(); | ||
Console::write(' ', self::CASES[$kind], ' ', str_replace("\n", "\n ", $outcome->test)); | ||
switch ($kind) { | ||
case 'success': Console::writeLine(); break; | ||
case 'skipped': { | ||
Console::writeLinef("\033[1;32;3m // Skip%s\033[0m", $outcome->reason ? ": {$outcome->reason}" : ''); | ||
break; | ||
} | ||
case 'failure': { | ||
Console::writeLinef("\033[1;32;3m // Fail: %s\033[0m", $outcome->reason); | ||
break; | ||
} | ||
} | ||
} | ||
Console::writeLine(); | ||
} | ||
|
||
/** | ||
* Pass an entire group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param test.Outcome[] $results | ||
* @return void | ||
*/ | ||
public function pass($group, $results) { | ||
Console::writeLinef("\r> %s \033[37m%s\033[0m", self::GROUPS['success'], $group->name()); | ||
$this->summarize($results); | ||
} | ||
|
||
/** | ||
* Fail an entire group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param test.Outcome[] $results | ||
* @return void | ||
*/ | ||
public function fail($group, $results) { | ||
Console::writeLinef("\r> %s \033[37m%s\033[0m", self::GROUPS['failure'], $group->name()); | ||
$this->summarize($results); | ||
} | ||
|
||
/** | ||
* Skip an entire group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param string $reason | ||
* @return void | ||
*/ | ||
public function skip($group, $reason) { | ||
Console::writeLinef( | ||
"\r> %s \033[37m%s\033[1;32;3m // %s\033[0m\n", | ||
self::GROUPS['skipped'], | ||
$group->name(), | ||
$reason | ||
); | ||
} | ||
|
||
/** | ||
* Stop an entire group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param string $reason | ||
* @return void | ||
*/ | ||
public function stop($group, $reason) { | ||
Console::writeLinef( | ||
"\r> %s \033[37m%s\033[1;32;3m // %s\033[0m", | ||
self::GROUPS['stopped'], | ||
$group->name(), | ||
$reason | ||
); | ||
} | ||
|
||
/** | ||
* Print out summary of test run | ||
* | ||
* @param test.execution.Metrics $metrices | ||
* @param float $overall | ||
* @param [:test.Outcome] $failures | ||
* @return void | ||
*/ | ||
public function summary($metrics, $overall, $failures) { | ||
$this->failures($failures); | ||
$this->metrics($metrics, $overall); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php namespace xp\test; | ||
|
||
abstract class Report { | ||
|
||
/** | ||
* Called when the test run starts | ||
* | ||
* @param test.source.Sources $sources | ||
* @return void | ||
*/ | ||
public function start($sources) { } | ||
|
||
/** | ||
* Called when entering a group. The group ends with one of the following: | ||
* | ||
* - `pass()` - All of the tests in this group passed | ||
* - `fail()` - At least one of the tests failed | ||
* - `skip()` - The entire group was skipped | ||
* - `stop()` - The entire group errored | ||
* | ||
* @param test.execution.TestClass $group | ||
* @return void | ||
*/ | ||
public function enter($group) { } | ||
|
||
/** | ||
* Running a given test | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param test.execution.TestCase $test | ||
* @param int $n | ||
* @return void | ||
*/ | ||
public function running($group, $test, $n) { } | ||
|
||
/** | ||
* Finished running a given test | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param test.execution.TestCase $test | ||
* @param test.Outcome $outcome | ||
* @return void | ||
*/ | ||
public function finished($group, $test, $outcome) { } | ||
|
||
/** | ||
* Pass an entire group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param test.Outcome[] $results | ||
* @return void | ||
*/ | ||
public function pass($group, $results) { } | ||
|
||
/** | ||
* Fail an entire group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param test.Outcome[] $results | ||
* @return void | ||
*/ | ||
public function fail($group, $results) { } | ||
|
||
/** | ||
* Skip an entire group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param string $reason | ||
* @return void | ||
*/ | ||
public function skip($group, $reason) { } | ||
|
||
/** | ||
* Stop an entire group | ||
* | ||
* @param test.execution.TestClass $group | ||
* @param string $reason | ||
* @return void | ||
*/ | ||
public function stop($group, $reason) { } | ||
|
||
/** | ||
* Print out summary of test run | ||
* | ||
* @param test.execution.Metrics $metrices | ||
* @param float $overall | ||
* @param [:test.Outcome] $failures | ||
* @return void | ||
*/ | ||
public function summary($metrics, $overall, $failures) { } | ||
} |
Oops, something went wrong.