Skip to content

Add .phpt tests for the printer #5

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 1 commit into from
Jan 19, 2020
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
23 changes: 23 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Github Actions printer for PHPUnit Test Suite">
<directory suffix=".phpt">./test/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
8 changes: 6 additions & 2 deletions src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ protected function printDefectTrace(TestFailure $defect): void
{
$e = $defect->thrownException();

$firstError = explode(PHP_EOL, (string)$e)[2];
list($path, $line) = explode(":", $firstError);
$errorLines = array_filter(
explode(PHP_EOL, (string)$e),
function($l){ return $l; }
);

list($path, $line) = explode(":", end($errorLines));

if (!$path) {
list($path, $line) = $this->getReflectionFromTest($defect->getTestName());
Expand Down
49 changes: 49 additions & 0 deletions test/_files/PrinterStatesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

class PrinterStatesTest extends PHPUnit\Framework\TestCase
{
public function testSuccess()
{
$this->assertTrue(true);
}

public function testFailure()
{
$this->assertTrue(false);
}

public function testError()
{
strpos();
}

public function testMissing()
{
$this->isMissing();
}

public function testSkipped()
{
$this->markTestSkipped('Skipped');
}

public function testWarning()
{
throw new PHPUnit\Framework\Warning("This is a test warning");
}

public function testRisky()
{
throw new PHPUnit\Framework\RiskyTestError("This is a risky test");
}

public function testNoAssertions()
{
}

public function testIncomplete()
{
$this->markTestIncomplete('Incomplete');
}
}

16 changes: 16 additions & 0 deletions test/_files/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
printerFile="../../src/Printer.php"
printerClass="mheap\GithubActionsReporter\Printer"
processIsolation="false"
stopOnFailure="false"
bootstrap="../../vendor/autoload.php"
>

</phpunit>
23 changes: 23 additions & 0 deletions test/states-test.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
phpunit -c tests/_files/phpunit.xml tests/_files/PrinterStatesTest.php
--FILE--
<?php
$_SERVER['TERM'] = 'xterm';
$_SERVER['argv'][1] = '-c';
$_SERVER['argv'][2] = dirname(__FILE__).'/_files/phpunit.xml';
$_SERVER['argv'][3] = '--colors=always';
$_SERVER['argv'][4] = dirname(__FILE__).'/_files/PrinterStatesTest.php';

require_once(dirname(dirname(__FILE__))).'/vendor/autoload.php';

PHPUnit\TextUI\Command::main();
?>
--EXPECTF--
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.

::error file=test/_files/PrinterStatesTest.php,line=17::strpos() expects at least 2 parameters, 0 given
::error file=test/_files/PrinterStatesTest.php,line=22::Call to undefined method PrinterStatesTest::isMissing()
::warning file=test/_files/PrinterStatesTest.php,line=32::This is a test warning
::error file=test/_files/PrinterStatesTest.php,line=12::Failed asserting that false is true.
::warning file=test/_files/PrinterStatesTest.php,line=37::This is a risky test
::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions