Skip to content

Commit e41231b

Browse files
Merge branch '11.1'
2 parents 5a836f5 + 0cdf769 commit e41231b

File tree

6 files changed

+62
-12
lines changed

6 files changed

+62
-12
lines changed

.psalm/baseline.xml

+7
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@
725725
<code><![CDATA[nameAndVersion]]></code>
726726
</InternalMethod>
727727
<MissingThrowsDocblock>
728+
<code><![CDATA[DefaultPrinter::from(
729+
$configuration->logfileTeamcity(),
730+
)]]></code>
731+
<code><![CDATA[OutputFacade::printerFor($configuration->logfileJunit())]]></code>
728732
<code><![CDATA[atLeastVersion]]></code>
729733
<code><![CDATA[build]]></code>
730734
<code><![CDATA[configurationFile]]></code>
@@ -961,6 +965,9 @@
961965
<MissingThrowsDocblock>
962966
<code><![CDATA[DefaultPrinter::standardError()]]></code>
963967
<code><![CDATA[DefaultPrinter::standardError()]]></code>
968+
<code><![CDATA[DefaultPrinter::standardError()]]></code>
969+
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
970+
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
964971
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
965972
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
966973
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>

src/Framework/TestRunner.php

-7
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 file_exists;
@@ -399,12 +398,6 @@ private function canTimeLimitBeEnforced(): bool
399398
return $this->timeLimitCanBeEnforced;
400399
}
401400

402-
if (!class_exists(Invoker::class)) {
403-
$this->timeLimitCanBeEnforced = false;
404-
405-
return $this->timeLimitCanBeEnforced;
406-
}
407-
408401
$this->timeLimitCanBeEnforced = (new Invoker)->canInvokeWithTimeout();
409402

410403
return $this->timeLimitCanBeEnforced;
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 <[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\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

+2
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

+12-1
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

+11-4
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)