99 */
1010namespace SebastianBergmann \CodeCoverage \Report \Xml ;
1111
12+ use SebastianBergmann \CodeCoverage \RuntimeException ;
1213use SebastianBergmann \CodeCoverage \TestCase ;
1314
1415class XmlTest extends TestCase
@@ -30,7 +31,11 @@ protected function tearDown(): void
3031
3132 foreach ($ tmpFilesIterator as $ path => $ fileInfo ) {
3233 /* @var \SplFileInfo $fileInfo */
33- \unlink ($ fileInfo ->getPathname ());
34+ if (!\is_dir ($ fileInfo ->getPathname ())) {
35+ \unlink ($ fileInfo ->getPathname ());
36+ } else {
37+ \rmdir ($ fileInfo ->getPathname ());
38+ }
3439 }
3540 }
3641
@@ -64,6 +69,27 @@ public function testForClassWithAnonymousFunction(): void
6469 $ this ->assertFilesEquals ($ expectedFilesPath , self ::$ TEST_TMP_PATH );
6570 }
6671
72+ public function testReportThrowsRuntimeExceptionWhenUnableToCreateTargetDir (): void
73+ {
74+ $ this ->expectException (RuntimeException::class);
75+ $ this ->expectExceptionMessage ("'/foo/bar/baz/' could not be created. " );
76+
77+ $ xml = new Facade ('1.0.0 ' );
78+ $ xml ->process ($ this ->getCoverageForBankAccount (), '/foo/bar/baz ' );
79+ }
80+
81+ public function testReportThrowsRuntimeExceptionWhenUnableToWriteToTargetDir (): void
82+ {
83+ $ target = self ::$ TEST_TMP_PATH . '/non-writable-dir ' ;
84+ @\mkdir ($ target , 0555 );
85+
86+ $ this ->expectException (RuntimeException::class);
87+ $ this ->expectExceptionMessage ("' $ target/' exists but is not writable " );
88+
89+ $ xml = new Facade ('1.0.0 ' );
90+ $ xml ->process ($ this ->getCoverageForBankAccount (), $ target );
91+ }
92+
6793 /**
6894 * @param string $expectedFilesPath
6995 * @param string $actualFilesPath
0 commit comments