Skip to content

Commit 662d41c

Browse files
Merge branch '10.5' into 11.1
2 parents 900d41f + be8d36b commit 662d41c

File tree

6 files changed

+188
-16
lines changed

6 files changed

+188
-16
lines changed

src/TextUI/Application.php

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,36 @@ public function run(array $argv): int
213213

214214
if ($testDoxResult !== null &&
215215
$configuration->hasLogfileTestdoxHtml()) {
216-
OutputFacade::printerFor($configuration->logfileTestdoxHtml())->print(
217-
(new TestDoxHtmlRenderer)->render($testDoxResult),
218-
);
216+
try {
217+
OutputFacade::printerFor($configuration->logfileTestdoxHtml())->print(
218+
(new TestDoxHtmlRenderer)->render($testDoxResult),
219+
);
220+
} catch (Exception $e) {
221+
EventFacade::emitter()->testRunnerTriggeredWarning(
222+
sprintf(
223+
'Cannot log test results in TestDox HTML format to "%s": %s',
224+
$configuration->logfileTestdoxHtml(),
225+
$e->getMessage(),
226+
),
227+
);
228+
}
219229
}
220230

221231
if ($testDoxResult !== null &&
222232
$configuration->hasLogfileTestdoxText()) {
223-
OutputFacade::printerFor($configuration->logfileTestdoxText())->print(
224-
(new TestDoxTextRenderer)->render($testDoxResult),
225-
);
233+
try {
234+
OutputFacade::printerFor($configuration->logfileTestdoxText())->print(
235+
(new TestDoxTextRenderer)->render($testDoxResult),
236+
);
237+
} catch (Exception $e) {
238+
EventFacade::emitter()->testRunnerTriggeredWarning(
239+
sprintf(
240+
'Cannot log test results in TestDox plain text format to "%s": %s',
241+
$configuration->logfileTestdoxText(),
242+
$e->getMessage(),
243+
),
244+
);
245+
}
226246
}
227247

228248
$result = TestResultFacade::result();
@@ -565,19 +585,39 @@ private function registerLogfileWriters(Configuration $configuration): void
565585
}
566586

567587
if ($configuration->hasLogfileJunit()) {
568-
new JunitXmlLogger(
569-
OutputFacade::printerFor($configuration->logfileJunit()),
570-
EventFacade::instance(),
571-
);
588+
try {
589+
new JunitXmlLogger(
590+
OutputFacade::printerFor($configuration->logfileJunit()),
591+
EventFacade::instance(),
592+
);
593+
} catch (Exception $e) {
594+
EventFacade::emitter()->testRunnerTriggeredWarning(
595+
sprintf(
596+
'Cannot log test results in JUnit XML format to "%s": %s',
597+
$configuration->logfileJunit(),
598+
$e->getMessage(),
599+
),
600+
);
601+
}
572602
}
573603

574604
if ($configuration->hasLogfileTeamcity()) {
575-
new TeamCityLogger(
576-
DefaultPrinter::from(
577-
$configuration->logfileTeamcity(),
578-
),
579-
EventFacade::instance(),
580-
);
605+
try {
606+
new TeamCityLogger(
607+
DefaultPrinter::from(
608+
$configuration->logfileTeamcity(),
609+
),
610+
EventFacade::instance(),
611+
);
612+
} catch (Exception $e) {
613+
EventFacade::emitter()->testRunnerTriggeredWarning(
614+
sprintf(
615+
'Cannot log test results in TeamCity format to "%s": %s',
616+
$configuration->logfileTeamcity(),
617+
$e->getMessage(),
618+
),
619+
);
620+
}
581621
}
582622
}
583623

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Basic;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class SuccessTest extends TestCase
15+
{
16+
public function testOne(): void
17+
{
18+
$this->assertTrue(true);
19+
}
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test runner emits warning when --log-junit is used with an invalid target path
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--log-junit';
8+
$_SERVER['argv'][] = '';
9+
$_SERVER['argv'][] = __DIR__ . '/../_files/basic/SuccessTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
Runtime: %s
18+
19+
. 1 / 1 (100%)
20+
21+
Time: %s, Memory: %s
22+
23+
There was 1 PHPUnit test runner warning:
24+
25+
1) Cannot log test results in JUnit XML format to "": Directory "" does not exist and could not be created
26+
27+
WARNINGS!
28+
Tests: 1, Assertions: 1, Warnings: 1.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test runner emits warning when --log-teamcity is used with an invalid target path
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--log-teamcity';
8+
$_SERVER['argv'][] = '';
9+
$_SERVER['argv'][] = __DIR__ . '/../_files/basic/SuccessTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
Runtime: %s
18+
19+
. 1 / 1 (100%)
20+
21+
Time: %s, Memory: %s
22+
23+
There was 1 PHPUnit test runner warning:
24+
25+
1) Cannot log test results in TeamCity format to "": Directory "" does not exist and could not be created
26+
27+
WARNINGS!
28+
Tests: 1, Assertions: 1, Warnings: 1.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test runner emits warning when --testdox-html is used with an invalid target path
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--testdox-html';
8+
$_SERVER['argv'][] = '';
9+
$_SERVER['argv'][] = __DIR__ . '/../_files/basic/SuccessTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
Runtime: %s
18+
19+
. 1 / 1 (100%)
20+
21+
Time: %s, Memory: %s
22+
23+
There was 1 PHPUnit test runner warning:
24+
25+
1) Cannot log test results in TestDox HTML format to "": Directory "" does not exist and could not be created
26+
27+
WARNINGS!
28+
Tests: 1, Assertions: 1, Warnings: 1.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test runner emits warning when --testdox-text is used with an invalid target path
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--testdox-text';
8+
$_SERVER['argv'][] = '';
9+
$_SERVER['argv'][] = __DIR__ . '/../_files/basic/SuccessTest.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
Runtime: %s
18+
19+
. 1 / 1 (100%)
20+
21+
Time: %s, Memory: %s
22+
23+
There was 1 PHPUnit test runner warning:
24+
25+
1) Cannot log test results in TestDox plain text format to "": Directory "" does not exist and could not be created
26+
27+
WARNINGS!
28+
Tests: 1, Assertions: 1, Warnings: 1.

0 commit comments

Comments
 (0)