Skip to content

Commit 2ebbbf2

Browse files
lyrixxsebastianbergmann
authored andcommitted
Print new line only if message is not empty
1 parent 52d00f3 commit 2ebbbf2

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/Runner/ShutdownHandler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ private static function register(): void
4646
register_shutdown_function(
4747
static function (): void
4848
{
49-
print rtrim(self::$message) . PHP_EOL;
49+
$message = rtrim(self::$message);
50+
51+
if ($message === '') {
52+
return;
53+
}
54+
55+
print self::$message . PHP_EOL;
5056
},
5157
);
5258
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class WithExitTest extends TestCase
15+
{
16+
public function testWithMessage(): void
17+
{
18+
$this->assertTrue(true);
19+
$this->assertTrue(true);
20+
21+
exit('My Custom Exit Message');
22+
}
23+
24+
public function testWithoutMessage(): void
25+
{
26+
$this->assertTrue(true);
27+
$this->assertTrue(true);
28+
29+
exit(1);
30+
}
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
--FILE--
3+
<?php
4+
$phpunit = __DIR__ . '/../../../../phpunit';
5+
passthru(\sprintf('php %s --do-not-cache-result --no-configuration %s/WithExitTest.php --filter testWithMessage',$phpunit, __DIR__,));
6+
echo "\n------\n";
7+
passthru(\sprintf('php %s --do-not-cache-result --no-configuration %s/WithExitTest.php --filter testWithoutMessage',$phpunit, __DIR__,));
8+
echo "\n------\n";
9+
echo PHP_EOL;
10+
--EXPECTF--
11+
%s by Sebastian Bergmann and contributors.
12+
13+
Runtime: %s
14+
15+
My Custom Exit MessageFatal error: Premature end of PHP process when running PHPUnit\TestFixture\WithExitTest::testWithMessage.
16+
17+
------
18+
%s by Sebastian Bergmann and contributors.
19+
20+
Runtime: %s
21+
22+
Fatal error: Premature end of PHP process when running PHPUnit\TestFixture\WithExitTest::testWithoutMessage.
23+
24+
------
25+

0 commit comments

Comments
 (0)