Skip to content

Commit 3a721be

Browse files
committed
Progress on tests
1 parent 4b53852 commit 3a721be

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Homestead.yaml
1111
npm-debug.log
1212
yarn-error.log
1313
.env
14+
.phpunit.result.cache

phpunit.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinter"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Test suite">
14+
<directory suffix="Test.php">./tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<php>
18+
<env name="APP_ENV" value="testing"/>
19+
</php>
20+
</phpunit>

tests/Output.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Sempro\PHPUnitPrettyPrinter\Tests;
4+
5+
use Exception;
6+
7+
class OutputTest extends \PHPUnit\Framework\TestCase
8+
{
9+
public function testSuccess(): void
10+
{
11+
$this->assertTrue(true);
12+
}
13+
14+
public function testFail(): void
15+
{
16+
$this->assertTrue(false);
17+
}
18+
19+
public function testError(): void
20+
{
21+
throw new Exception('error');
22+
}
23+
24+
public function testSkip(): void
25+
{
26+
$this->markTestSkipped('skipped');
27+
}
28+
29+
public function testIncomplete(): void
30+
{
31+
$this->markTestIncomplete('incomplete');
32+
}
33+
}

tests/PrinterTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Sempro\PHPUnitPrettyPrinter\Tests;
4+
5+
class PrinterTest extends \PHPUnit\Framework\TestCase
6+
{
7+
public function testFirstTestShouldPass()
8+
{
9+
$lines = $this->getOutput();
10+
11+
$this->assertStringContainsString('✓ success', $lines[4]);
12+
}
13+
14+
public function testSecondTestShouldFail()
15+
{
16+
$lines = $this->getOutput();
17+
18+
$this->assertStringContainsString('x fail', $lines[5]);
19+
}
20+
21+
public function testThirdTestShouldThrowAnError()
22+
{
23+
$lines = $this->getOutput();
24+
25+
$this->assertStringContainsString('⚈ error', $lines[6]);
26+
}
27+
28+
public function testForthTestShouldBeSkipped()
29+
{
30+
$lines = $this->getOutput();
31+
32+
$this->assertStringContainsString('→ skip', $lines[7]);
33+
}
34+
35+
public function testFifthTestShouldBeIncomplete()
36+
{
37+
$lines = $this->getOutput();
38+
39+
$this->assertStringContainsString('∅ incomplete', $lines[8]);
40+
}
41+
42+
private function getOutput(): array
43+
{
44+
$command = [
45+
"vendor/bin/phpunit",
46+
"tests/Output.php",
47+
"--printer 'Sempro\PHPUnitPrettyPrinter\PrettyPrinter'",
48+
];
49+
50+
exec(implode(' ', $command), $out);
51+
52+
return $out;
53+
}
54+
}

0 commit comments

Comments
 (0)