Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Commit f2588c2

Browse files
committed
Add tests for a test run with multiple tests / data sets
1 parent 2751239 commit f2588c2

File tree

2 files changed

+180
-28
lines changed

2 files changed

+180
-28
lines changed

tests/Unit/MarkdownTest.php

Lines changed: 150 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
use PHPUnit\Framework\TestSuite;
1414
use PHPUnit\Framework\Warning;
1515
use PHPUnit\Runner\BaseTestRunner;
16+
use function file_get_contents;
1617
use function getcwd;
1718
use function ob_end_clean;
19+
use function ob_get_clean;
1820
use function ob_start;
1921
use function unlink;
2022
use const DIRECTORY_SEPARATOR;
@@ -45,6 +47,7 @@ protected function setUp() : void
4547
);
4648
$this->testSuite = $this->getTestSuite( 'Unit-Test-Suite' );
4749

50+
$this->markdown->startTestSuite( $this->getTestSuite( '' ) );
4851
$this->markdown->startTestSuite( $this->testSuite );
4952
}
5053

@@ -62,14 +65,21 @@ private function getTestSuite( string $testName ) : TestSuite
6265
*/
6366
protected function tearDown() : void
6467
{
65-
$this->markdown->endTestSuite( $this->testSuite );
68+
if ( null !== $this->markdown )
69+
{
70+
$this->markdown->endTestSuite( $this->getTestSuite( '' ) );
71+
$this->markdown->endTestSuite( $this->getTestSuite( 'UnitTest::testSomething' ) );
72+
$this->markdown->endTestSuite( $this->getTestSuite( 'hollodotme\\PHPUnit\\UnitTest::testSomething' ) );
73+
$this->markdown->endTestSuite( $this->testSuite );
74+
75+
ob_start();
76+
$this->markdown = null;
77+
ob_end_clean();
78+
}
6679

67-
unlink( $this->filePath );
68-
ob_start();
69-
$this->markdown = null;
70-
ob_end_clean();
7180
$this->testSuite = null;
72-
$this->filePath = null;
81+
unlink( $this->filePath );
82+
$this->filePath = null;
7383
}
7484

7585
/**
@@ -150,11 +160,6 @@ private function getTest( string $testName, int $status, ?int $dataSet = null )
150160
return $test;
151161
}
152162

153-
public function testStartTestSuite() : void
154-
{
155-
$this->markTestIncomplete( 'Needs implementation.' );
156-
}
157-
158163
/**
159164
* @throws RuntimeException
160165
* @throws \PHPUnit\Framework\ExpectationFailedException
@@ -275,16 +280,6 @@ public function testAddFailureWithDataSets() : void
275280
);
276281
}
277282

278-
public function testEndTestSuite() : void
279-
{
280-
$this->markTestIncomplete( 'Needs implementation.' );
281-
}
282-
283-
public function testEndTest() : void
284-
{
285-
$this->markTestIncomplete( 'Needs implementation.' );
286-
}
287-
288283
/**
289284
* @throws RuntimeException
290285
* @throws \PHPUnit\Framework\ExpectationFailedException
@@ -405,11 +400,6 @@ public function testAddWarningWithDataSets() : void
405400
);
406401
}
407402

408-
public function testStartTest() : void
409-
{
410-
$this->markTestIncomplete( 'Needs implementation.' );
411-
}
412-
413403
/**
414404
* @throws RuntimeException
415405
* @throws \PHPUnit\Framework\ExpectationFailedException
@@ -470,9 +460,25 @@ public function testAddErrorWithDataSets() : void
470460
);
471461
}
472462

473-
public function test__destruct() : void
463+
/**
464+
* @throws \PHPUnit\Framework\ExpectationFailedException
465+
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
466+
*/
467+
public function testDestruct() : void
474468
{
475-
$this->markTestIncomplete( 'Needs implementation.' );
469+
ob_start();
470+
$this->markdown = null;
471+
$content = ob_get_clean();
472+
473+
$this->assertSame(
474+
"Test results written to markdown file:\n{$this->filePath}\n",
475+
$content
476+
);
477+
478+
$this->assertRegExp(
479+
'#\nReport created at \d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2} \(.+\)$#',
480+
file_get_contents( $this->filePath )
481+
);
476482
}
477483

478484
/**
@@ -540,4 +546,120 @@ public function testAddPassingTestWithDataSets() : void
540546
$this->filePath
541547
);
542548
}
549+
550+
/**
551+
* @throws RuntimeException
552+
* @throws \PHPUnit\Framework\ExpectationFailedException
553+
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
554+
*/
555+
public function testCanAddMultipleTests() : void
556+
{
557+
$testTestSuite = $this->getTestSuite( 'hollodotme\\PHPUnit\\UnitTest' );
558+
559+
$passingTest = $this->getTest( 'testCanHaveSingleTest', BaseTestRunner::STATUS_PASSED );
560+
$passingTest0 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_PASSED, 0 );
561+
$passingTest1 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_PASSED, 1 );
562+
$passingTest2 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_PASSED, 2 );
563+
564+
$riskyTest0 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_RISKY, 3 );
565+
$riskyTest1 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_RISKY, 4 );
566+
$riskyTest2 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_RISKY, 5 );
567+
568+
$skippedTest0 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_SKIPPED, 6 );
569+
$skippedTest1 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_SKIPPED, 7 );
570+
$skippedTest2 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_SKIPPED, 8 );
571+
572+
$incompleteTest0 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_INCOMPLETE, 9 );
573+
$incompleteTest1 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_INCOMPLETE, 10 );
574+
$incompleteTest2 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_INCOMPLETE, 11 );
575+
576+
$warningTest0 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_WARNING, 12 );
577+
$warningTest1 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_WARNING, 13 );
578+
$warningTest2 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_WARNING, 14 );
579+
580+
$failureTest0 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_FAILURE, 15 );
581+
$errorTest0 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_ERROR, 16 );
582+
$errorTest1 = $this->getTest( 'testCanHaveTestWithDataSets', BaseTestRunner::STATUS_ERROR, 17 );
583+
584+
$this->markdown->startTestSuite( $testTestSuite );
585+
586+
$this->markdown->startTest( $passingTest );
587+
$this->markdown->endTest( $passingTest, time() );
588+
589+
$this->markdown->startTest( $passingTest0 );
590+
$this->markdown->endTest( $passingTest0, time() );
591+
592+
$this->markdown->startTest( $passingTest1 );
593+
$this->markdown->endTest( $passingTest1, time() );
594+
595+
$this->markdown->startTest( $passingTest2 );
596+
$this->markdown->endTest( $passingTest2, time() );
597+
598+
$this->markdown->startTest( $riskyTest0 );
599+
$this->markdown->addRiskyTest( $riskyTest0, new Exception( 'DataSet is risky.' ), time() );
600+
$this->markdown->endTest( $riskyTest0, time() );
601+
602+
$this->markdown->startTest( $riskyTest1 );
603+
$this->markdown->addRiskyTest( $riskyTest1, new Exception( 'DataSet is risky.' ), time() );
604+
$this->markdown->endTest( $riskyTest1, time() );
605+
606+
$this->markdown->startTest( $riskyTest2 );
607+
$this->markdown->addRiskyTest( $riskyTest2, new Exception( 'DataSet is risky.' ), time() );
608+
$this->markdown->endTest( $riskyTest2, time() );
609+
610+
$this->markdown->startTest( $skippedTest0 );
611+
$this->markdown->addSkippedTest( $skippedTest0, new Exception( 'DataSet was skipped.' ), time() );
612+
$this->markdown->endTest( $skippedTest0, time() );
613+
614+
$this->markdown->startTest( $skippedTest1 );
615+
$this->markdown->addSkippedTest( $skippedTest1, new Exception( 'DataSet was skipped.' ), time() );
616+
$this->markdown->endTest( $skippedTest1, time() );
617+
618+
$this->markdown->startTest( $skippedTest2 );
619+
$this->markdown->addSkippedTest( $skippedTest2, new Exception( 'DataSet was skipped.' ), time() );
620+
$this->markdown->endTest( $skippedTest2, time() );
621+
622+
$this->markdown->startTest( $incompleteTest0 );
623+
$this->markdown->addIncompleteTest( $incompleteTest0, new Exception( 'DataSet is incomplete.' ), time() );
624+
$this->markdown->endTest( $incompleteTest0, time() );
625+
626+
$this->markdown->startTest( $incompleteTest1 );
627+
$this->markdown->addIncompleteTest( $incompleteTest1, new Exception( 'DataSet is incomplete.' ), time() );
628+
$this->markdown->endTest( $incompleteTest1, time() );
629+
630+
$this->markdown->startTest( $incompleteTest2 );
631+
$this->markdown->addIncompleteTest( $incompleteTest2, new Exception( 'DataSet is incomplete.' ), time() );
632+
$this->markdown->endTest( $incompleteTest2, time() );
633+
634+
$this->markdown->startTest( $warningTest0 );
635+
$this->markdown->addWarning( $warningTest0, new Warning( 'DataSet creates warning.' ), time() );
636+
$this->markdown->endTest( $warningTest0, time() );
637+
638+
$this->markdown->startTest( $warningTest1 );
639+
$this->markdown->addWarning( $warningTest1, new Warning( 'DataSet creates warning.' ), time() );
640+
$this->markdown->endTest( $warningTest1, time() );
641+
642+
$this->markdown->startTest( $warningTest2 );
643+
$this->markdown->addWarning( $warningTest2, new Warning( 'DataSet creates warning.' ), time() );
644+
$this->markdown->endTest( $warningTest2, time() );
645+
646+
$this->markdown->startTest( $failureTest0 );
647+
$this->markdown->addFailure( $failureTest0, new AssertionFailedError( 'DataSet fails.' ), time() );
648+
$this->markdown->endTest( $failureTest0, time() );
649+
650+
$this->markdown->startTest( $errorTest0 );
651+
$this->markdown->addError( $errorTest0, new Error( 'DataSet errors out.' ), time() );
652+
$this->markdown->endTest( $errorTest0, time() );
653+
654+
$this->markdown->startTest( $errorTest1 );
655+
$this->markdown->addError( $errorTest1, new Error( 'DataSet errors out.' ), time() );
656+
$this->markdown->endTest( $errorTest1, time() );
657+
658+
$this->markdown->endTestSuite( $testTestSuite );
659+
660+
$this->assertFileEquals(
661+
__DIR__ . '/Output/_files/MultipleTests.md',
662+
$this->filePath
663+
);
664+
}
543665
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
💚 Passed | 💔 Error | 💔 Failure | 🧡 Warning | 💛 Risky | 💙 Incomplete | 💜 Skipped
2+
3+
# Test suite: Unit-Test-Suite
4+
5+
* Environment: `Testing`
6+
* Base namespace: `hollodotme\PHPUnit`
7+
8+
## UnitTest
9+
10+
- [x] Can Have Single Test (💚 1)
11+
- [ ] Can Have Test With Data Sets (💚 3, 💛 3, 💜 3, 💙 3, 🧡 3, 💔 3)
12+
> 3: DataSet is risky.
13+
> 4: DataSet is risky.
14+
> 5: DataSet is risky.
15+
> 6: DataSet was skipped.
16+
> 7: DataSet was skipped.
17+
> 8: DataSet was skipped.
18+
> 9: DataSet is incomplete.
19+
> 10: DataSet is incomplete.
20+
> 11: DataSet is incomplete.
21+
> 12: DataSet creates warning.
22+
> 13: DataSet creates warning.
23+
> 14: DataSet creates warning.
24+
> 15: DataSet fails.
25+
> 16: DataSet errors out.
26+
> 17: DataSet errors out.
27+
28+
29+
---
30+

0 commit comments

Comments
 (0)