Skip to content

Fix PHPUnit6 issue #25

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

Merged
merged 2 commits into from
May 22, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/FeatureTestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

namespace Http\Client\Tests;

use PHPUnit\Framework\Test;
use PHPUnit\TextUI\ResultPrinter;

class FeatureTestListener extends ResultPrinter
trait FeatureTestListener
{
public function write($buffer)
{
}

public function startTest(Test $test)
protected function doStartTest($test)
{
$feature = $this->extractFeature($test);

Expand All @@ -24,7 +21,7 @@ public function startTest(Test $test)
echo sprintf('%-40.s : ', $feature);
}

public function endTest(Test $test, $time)
protected function doEndTest($test, $time)
{
if (!$this->lastTestFailed) {
echo $this->formatWithColor('fg-green', 'Supported')."\n";
Expand All @@ -35,10 +32,10 @@ public function endTest(Test $test, $time)
$this->lastTestFailed = false;
}

private function extractFeature(Test $test)
private function extractFeature($test)
{
$class = get_class($test);
$method = $test->getName();
$method = $test->getName(false);
$reflection = new \ReflectionMethod($class, $method);

return $this->parseDocBlock($reflection->getDocComment(), '@feature');
Expand Down
32 changes: 32 additions & 0 deletions src/ResultPrinter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Http\Client\Tests;

use PHPUnit\Framework\Test;

// If PHPUnit 6
if (class_exists('\\PHPUnit\\TextUI\\ResultPrinter')) {
class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter {
use FeatureTestListener;
public function startTest(Test $test)
{
return $this->doStartTest($test);
}
public function endTest(Test $test, $time)
{
return $this->doEndTest($test, $time);
}
}
} else {
class ResultPrinter extends \PHPUnit_TextUI_ResultPrinter {
use FeatureTestListener;
public function startTest(\PHPUnit_Framework_Test $test)
{
return $this->doStartTest($test);
}
public function endTest(\PHPUnit_Framework_Test $test, $time)
{
return $this->doEndTest($test, $time);
}
}
}