13
13
use PHPUnit \Framework \TestSuite ;
14
14
use PHPUnit \Framework \Warning ;
15
15
use PHPUnit \Runner \BaseTestRunner ;
16
+ use function file_get_contents ;
16
17
use function getcwd ;
17
18
use function ob_end_clean ;
19
+ use function ob_get_clean ;
18
20
use function ob_start ;
19
21
use function unlink ;
20
22
use const DIRECTORY_SEPARATOR ;
@@ -45,6 +47,7 @@ protected function setUp() : void
45
47
);
46
48
$ this ->testSuite = $ this ->getTestSuite ( 'Unit-Test-Suite ' );
47
49
50
+ $ this ->markdown ->startTestSuite ( $ this ->getTestSuite ( '' ) );
48
51
$ this ->markdown ->startTestSuite ( $ this ->testSuite );
49
52
}
50
53
@@ -62,14 +65,21 @@ private function getTestSuite( string $testName ) : TestSuite
62
65
*/
63
66
protected function tearDown () : void
64
67
{
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
+ }
66
79
67
- unlink ( $ this ->filePath );
68
- ob_start ();
69
- $ this ->markdown = null ;
70
- ob_end_clean ();
71
80
$ this ->testSuite = null ;
72
- $ this ->filePath = null ;
81
+ unlink ( $ this ->filePath );
82
+ $ this ->filePath = null ;
73
83
}
74
84
75
85
/**
@@ -150,11 +160,6 @@ private function getTest( string $testName, int $status, ?int $dataSet = null )
150
160
return $ test ;
151
161
}
152
162
153
- public function testStartTestSuite () : void
154
- {
155
- $ this ->markTestIncomplete ( 'Needs implementation. ' );
156
- }
157
-
158
163
/**
159
164
* @throws RuntimeException
160
165
* @throws \PHPUnit\Framework\ExpectationFailedException
@@ -275,16 +280,6 @@ public function testAddFailureWithDataSets() : void
275
280
);
276
281
}
277
282
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
-
288
283
/**
289
284
* @throws RuntimeException
290
285
* @throws \PHPUnit\Framework\ExpectationFailedException
@@ -405,11 +400,6 @@ public function testAddWarningWithDataSets() : void
405
400
);
406
401
}
407
402
408
- public function testStartTest () : void
409
- {
410
- $ this ->markTestIncomplete ( 'Needs implementation. ' );
411
- }
412
-
413
403
/**
414
404
* @throws RuntimeException
415
405
* @throws \PHPUnit\Framework\ExpectationFailedException
@@ -470,9 +460,25 @@ public function testAddErrorWithDataSets() : void
470
460
);
471
461
}
472
462
473
- public function test__destruct () : void
463
+ /**
464
+ * @throws \PHPUnit\Framework\ExpectationFailedException
465
+ * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
466
+ */
467
+ public function testDestruct () : void
474
468
{
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
+ );
476
482
}
477
483
478
484
/**
@@ -540,4 +546,120 @@ public function testAddPassingTestWithDataSets() : void
540
546
$ this ->filePath
541
547
);
542
548
}
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
+ }
543
665
}
0 commit comments