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 May 7, 2024
2 parents 5a836f5 + 0cdf769 commit e41231b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,10 @@
<code><![CDATA[nameAndVersion]]></code>
</InternalMethod>
<MissingThrowsDocblock>
<code><![CDATA[DefaultPrinter::from(
$configuration->logfileTeamcity(),
)]]></code>
<code><![CDATA[OutputFacade::printerFor($configuration->logfileJunit())]]></code>
<code><![CDATA[atLeastVersion]]></code>
<code><![CDATA[build]]></code>
<code><![CDATA[configurationFile]]></code>
Expand Down Expand Up @@ -961,6 +965,9 @@
<MissingThrowsDocblock>
<code><![CDATA[DefaultPrinter::standardError()]]></code>
<code><![CDATA[DefaultPrinter::standardError()]]></code>
<code><![CDATA[DefaultPrinter::standardError()]]></code>
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
<code><![CDATA[DefaultPrinter::standardOutput()]]></code>
Expand Down
7 changes: 0 additions & 7 deletions src/Framework/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use const PHP_EOL;
use function assert;
use function class_exists;
use function defined;
use function extension_loaded;
use function file_exists;
Expand Down Expand Up @@ -399,12 +398,6 @@ private function canTimeLimitBeEnforced(): bool
return $this->timeLimitCanBeEnforced;
}

if (!class_exists(Invoker::class)) {
$this->timeLimitCanBeEnforced = false;

return $this->timeLimitCanBeEnforced;
}

$this->timeLimitCanBeEnforced = (new Invoker)->canInvokeWithTimeout();

return $this->timeLimitCanBeEnforced;
Expand Down
30 changes: 30 additions & 0 deletions src/TextUI/Exception/CannotOpenSocketException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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\TextUI;

use function sprintf;
use RuntimeException;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class CannotOpenSocketException extends RuntimeException implements Exception
{
public function __construct(string $hostname, int $port)
{
parent::__construct(
sprintf(
'Cannot open socket %s:%d',
$hostname,
$port,
),
);
}
}
2 changes: 2 additions & 0 deletions src/TextUI/Output/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Logging\TestDox\TestResultCollection;
use PHPUnit\Runner\DirectoryDoesNotExistException;
use PHPUnit\TestRunner\TestResult\TestResult;
use PHPUnit\TextUI\CannotOpenSocketException;
use PHPUnit\TextUI\Configuration\Configuration;
use PHPUnit\TextUI\InvalidSocketException;
use PHPUnit\TextUI\Output\Default\ProgressPrinter\ProgressPrinter as DefaultProgressPrinter;
Expand Down Expand Up @@ -101,6 +102,7 @@ public static function printResult(TestResult $result, ?array $testDoxResult, Du
}

/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
Expand Down
13 changes: 12 additions & 1 deletion src/TextUI/Output/Printer/DefaultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use function str_replace;
use function str_starts_with;
use PHPUnit\Runner\DirectoryDoesNotExistException;
use PHPUnit\TextUI\CannotOpenSocketException;
use PHPUnit\TextUI\InvalidSocketException;
use PHPUnit\Util\Filesystem;

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

/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
Expand All @@ -45,6 +47,7 @@ public static function from(string $out): self
}

/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
Expand All @@ -54,6 +57,7 @@ public static function standardOutput(): self
}

/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
Expand All @@ -63,6 +67,7 @@ public static function standardError(): self
}

/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
Expand All @@ -77,7 +82,13 @@ private function __construct(string $out)
throw new InvalidSocketException($out);
}

$this->stream = fsockopen($tmp[0], (int) $tmp[1]);
$stream = @fsockopen($tmp[0], (int) $tmp[1]);

if ($stream === false) {
throw new CannotOpenSocketException($tmp[0], (int) $tmp[1]);
}

$this->stream = $stream;
$this->isOpen = true;

return;
Expand Down
15 changes: 11 additions & 4 deletions tests/unit/TextUI/Output/Default/DefaultPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Medium;
use PHPUnit\Framework\TestCase;
use PHPUnit\TextUI\CannotOpenSocketException;
use PHPUnit\TextUI\InvalidSocketException;
use PHPUnit\TextUI\Output\DefaultPrinter;

Expand All @@ -22,11 +23,17 @@ final class DefaultPrinterTest extends TestCase
{
public static function providePrinter(): array
{
return [
[DefaultPrinter::standardOutput()],
[DefaultPrinter::standardError()],
[DefaultPrinter::from('socket://www.example.com:80')],
$data = [
'standard output' => [DefaultPrinter::standardOutput()],
'standard error' => [DefaultPrinter::standardError()],
];

try {
$data['socket'] = [DefaultPrinter::from('socket://www.example.com:80')];
} catch (CannotOpenSocketException $e) {
}

return $data;
}

#[DataProvider('providePrinter')]
Expand Down

0 comments on commit e41231b

Please sign in to comment.