Skip to content

Commit

Permalink
Merge branch '11.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Apr 30, 2024
2 parents bc14316 + 662d41c commit 6f58a13
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 16 deletions.
72 changes: 56 additions & 16 deletions src/TextUI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,36 @@ public function run(array $argv): int

if ($testDoxResult !== null &&
$configuration->hasLogfileTestdoxHtml()) {
OutputFacade::printerFor($configuration->logfileTestdoxHtml())->print(
(new TestDoxHtmlRenderer)->render($testDoxResult),
);
try {
OutputFacade::printerFor($configuration->logfileTestdoxHtml())->print(
(new TestDoxHtmlRenderer)->render($testDoxResult),
);
} catch (Exception $e) {
EventFacade::emitter()->testRunnerTriggeredWarning(
sprintf(
'Cannot log test results in TestDox HTML format to "%s": %s',
$configuration->logfileTestdoxHtml(),
$e->getMessage(),
),
);
}
}

if ($testDoxResult !== null &&
$configuration->hasLogfileTestdoxText()) {
OutputFacade::printerFor($configuration->logfileTestdoxText())->print(
(new TestDoxTextRenderer)->render($testDoxResult),
);
try {
OutputFacade::printerFor($configuration->logfileTestdoxText())->print(
(new TestDoxTextRenderer)->render($testDoxResult),
);
} catch (Exception $e) {
EventFacade::emitter()->testRunnerTriggeredWarning(
sprintf(
'Cannot log test results in TestDox plain text format to "%s": %s',
$configuration->logfileTestdoxText(),
$e->getMessage(),
),
);
}
}

$result = TestResultFacade::result();
Expand Down Expand Up @@ -565,19 +585,39 @@ private function registerLogfileWriters(Configuration $configuration): void
}

if ($configuration->hasLogfileJunit()) {
new JunitXmlLogger(
OutputFacade::printerFor($configuration->logfileJunit()),
EventFacade::instance(),
);
try {
new JunitXmlLogger(
OutputFacade::printerFor($configuration->logfileJunit()),
EventFacade::instance(),
);
} catch (Exception $e) {
EventFacade::emitter()->testRunnerTriggeredWarning(
sprintf(
'Cannot log test results in JUnit XML format to "%s": %s',
$configuration->logfileJunit(),
$e->getMessage(),
),
);
}
}

if ($configuration->hasLogfileTeamcity()) {
new TeamCityLogger(
DefaultPrinter::from(
$configuration->logfileTeamcity(),
),
EventFacade::instance(),
);
try {
new TeamCityLogger(
DefaultPrinter::from(
$configuration->logfileTeamcity(),
),
EventFacade::instance(),
);
} catch (Exception $e) {
EventFacade::emitter()->testRunnerTriggeredWarning(
sprintf(
'Cannot log test results in TeamCity format to "%s": %s',
$configuration->logfileTeamcity(),
$e->getMessage(),
),
);
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/end-to-end/_files/basic/SuccessTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Basic;

use PHPUnit\Framework\TestCase;

final class SuccessTest extends TestCase
{
public function testOne(): void
{
$this->assertTrue(true);
}
}
28 changes: 28 additions & 0 deletions tests/end-to-end/logging/log-junit-invalid-path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Test runner emits warning when --log-junit is used with an invalid target path
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--log-junit';
$_SERVER['argv'][] = '';
$_SERVER['argv'][] = __DIR__ . '/../_files/basic/SuccessTest.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s

There was 1 PHPUnit test runner warning:

1) Cannot log test results in JUnit XML format to "": Directory "" does not exist and could not be created

WARNINGS!
Tests: 1, Assertions: 1, Warnings: 1.
28 changes: 28 additions & 0 deletions tests/end-to-end/logging/log-teamcity-invalid-path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Test runner emits warning when --log-teamcity is used with an invalid target path
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--log-teamcity';
$_SERVER['argv'][] = '';
$_SERVER['argv'][] = __DIR__ . '/../_files/basic/SuccessTest.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s

There was 1 PHPUnit test runner warning:

1) Cannot log test results in TeamCity format to "": Directory "" does not exist and could not be created

WARNINGS!
Tests: 1, Assertions: 1, Warnings: 1.
28 changes: 28 additions & 0 deletions tests/end-to-end/logging/testdox-html-invalid-path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Test runner emits warning when --testdox-html is used with an invalid target path
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--testdox-html';
$_SERVER['argv'][] = '';
$_SERVER['argv'][] = __DIR__ . '/../_files/basic/SuccessTest.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s

There was 1 PHPUnit test runner warning:

1) Cannot log test results in TestDox HTML format to "": Directory "" does not exist and could not be created

WARNINGS!
Tests: 1, Assertions: 1, Warnings: 1.
28 changes: 28 additions & 0 deletions tests/end-to-end/logging/testdox-text-invalid-path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Test runner emits warning when --testdox-text is used with an invalid target path
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--testdox-text';
$_SERVER['argv'][] = '';
$_SERVER['argv'][] = __DIR__ . '/../_files/basic/SuccessTest.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s

There was 1 PHPUnit test runner warning:

1) Cannot log test results in TestDox plain text format to "": Directory "" does not exist and could not be created

WARNINGS!
Tests: 1, Assertions: 1, Warnings: 1.

0 comments on commit 6f58a13

Please sign in to comment.