Skip to content

Commit 0cdf769

Browse files
Merge branch '10.5' into 11.1
2 parents a6d9e2d + 88448af commit 0cdf769

File tree

6 files changed

+62
-12
lines changed

6 files changed

+62
-12
lines changed

.psalm/baseline.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,10 @@
709709
<code><![CDATA[nameAndVersion]]></code>
710710
</InternalMethod>
711711
<MissingThrowsDocblock>
712+
<code><![CDATA[DefaultPrinter::from(
713+
$configuration->logfileTeamcity(),
714+
)]]></code>
715+
<code><![CDATA[OutputFacade::printerFor($configuration->logfileJunit())]]></code>
712716
<code><![CDATA[atLeastVersion]]></code>
713717
<code><![CDATA[build]]></code>
714718
<code><![CDATA[configurationFile]]></code>
@@ -945,6 +949,9 @@
945949
<MissingThrowsDocblock>
946950
<code><![CDATA[DefaultPrinter::standardError()]]></code>
947951
<code><![CDATA[DefaultPrinter::standardError()]]></code>
952+
<code><![CDATA[DefaultPrinter::standardError()]]></code>
953+
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
954+
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
948955
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
949956
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
950957
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>

src/Framework/TestRunner.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use const PHP_EOL;
1313
use function assert;
14-
use function class_exists;
1514
use function defined;
1615
use function extension_loaded;
1716
use function get_include_path;
@@ -380,12 +379,6 @@ private function canTimeLimitBeEnforced(): bool
380379
return $this->timeLimitCanBeEnforced;
381380
}
382381

383-
if (!class_exists(Invoker::class)) {
384-
$this->timeLimitCanBeEnforced = false;
385-
386-
return $this->timeLimitCanBeEnforced;
387-
}
388-
389382
$this->timeLimitCanBeEnforced = (new Invoker)->canInvokeWithTimeout();
390383

391384
return $this->timeLimitCanBeEnforced;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\TextUI;
11+
12+
use function sprintf;
13+
use RuntimeException;
14+
15+
/**
16+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
17+
*/
18+
final class CannotOpenSocketException extends RuntimeException implements Exception
19+
{
20+
public function __construct(string $hostname, int $port)
21+
{
22+
parent::__construct(
23+
sprintf(
24+
'Cannot open socket %s:%d',
25+
$hostname,
26+
$port,
27+
),
28+
);
29+
}
30+
}

src/TextUI/Output/Facade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PHPUnit\Logging\TestDox\TestResultCollection;
1818
use PHPUnit\Runner\DirectoryDoesNotExistException;
1919
use PHPUnit\TestRunner\TestResult\TestResult;
20+
use PHPUnit\TextUI\CannotOpenSocketException;
2021
use PHPUnit\TextUI\Configuration\Configuration;
2122
use PHPUnit\TextUI\InvalidSocketException;
2223
use PHPUnit\TextUI\Output\Default\ProgressPrinter\ProgressPrinter as DefaultProgressPrinter;
@@ -101,6 +102,7 @@ public static function printResult(TestResult $result, ?array $testDoxResult, Du
101102
}
102103

103104
/**
105+
* @throws CannotOpenSocketException
104106
* @throws DirectoryDoesNotExistException
105107
* @throws InvalidSocketException
106108
*/

src/TextUI/Output/Printer/DefaultPrinter.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use function str_replace;
2121
use function str_starts_with;
2222
use PHPUnit\Runner\DirectoryDoesNotExistException;
23+
use PHPUnit\TextUI\CannotOpenSocketException;
2324
use PHPUnit\TextUI\InvalidSocketException;
2425
use PHPUnit\Util\Filesystem;
2526

@@ -36,6 +37,7 @@ final class DefaultPrinter implements Printer
3637
private bool $isOpen;
3738

3839
/**
40+
* @throws CannotOpenSocketException
3941
* @throws DirectoryDoesNotExistException
4042
* @throws InvalidSocketException
4143
*/
@@ -45,6 +47,7 @@ public static function from(string $out): self
4547
}
4648

4749
/**
50+
* @throws CannotOpenSocketException
4851
* @throws DirectoryDoesNotExistException
4952
* @throws InvalidSocketException
5053
*/
@@ -54,6 +57,7 @@ public static function standardOutput(): self
5457
}
5558

5659
/**
60+
* @throws CannotOpenSocketException
5761
* @throws DirectoryDoesNotExistException
5862
* @throws InvalidSocketException
5963
*/
@@ -63,6 +67,7 @@ public static function standardError(): self
6367
}
6468

6569
/**
70+
* @throws CannotOpenSocketException
6671
* @throws DirectoryDoesNotExistException
6772
* @throws InvalidSocketException
6873
*/
@@ -77,7 +82,13 @@ private function __construct(string $out)
7782
throw new InvalidSocketException($out);
7883
}
7984

80-
$this->stream = fsockopen($tmp[0], (int) $tmp[1]);
85+
$stream = @fsockopen($tmp[0], (int) $tmp[1]);
86+
87+
if ($stream === false) {
88+
throw new CannotOpenSocketException($tmp[0], (int) $tmp[1]);
89+
}
90+
91+
$this->stream = $stream;
8192
$this->isOpen = true;
8293

8394
return;

tests/unit/TextUI/Output/Default/DefaultPrinterTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPUnit\Framework\Attributes\DataProvider;
1414
use PHPUnit\Framework\Attributes\Medium;
1515
use PHPUnit\Framework\TestCase;
16+
use PHPUnit\TextUI\CannotOpenSocketException;
1617
use PHPUnit\TextUI\InvalidSocketException;
1718
use PHPUnit\TextUI\Output\DefaultPrinter;
1819

@@ -22,11 +23,17 @@ final class DefaultPrinterTest extends TestCase
2223
{
2324
public static function providePrinter(): array
2425
{
25-
return [
26-
[DefaultPrinter::standardOutput()],
27-
[DefaultPrinter::standardError()],
28-
[DefaultPrinter::from('socket://www.example.com:80')],
26+
$data = [
27+
'standard output' => [DefaultPrinter::standardOutput()],
28+
'standard error' => [DefaultPrinter::standardError()],
2929
];
30+
31+
try {
32+
$data['socket'] = [DefaultPrinter::from('socket://www.example.com:80')];
33+
} catch (CannotOpenSocketException $e) {
34+
}
35+
36+
return $data;
3037
}
3138

3239
#[DataProvider('providePrinter')]

0 commit comments

Comments
 (0)