2020use function str_replace ;
2121use function str_starts_with ;
2222use PHPUnit \Runner \DirectoryDoesNotExistException ;
23+ use PHPUnit \TextUI \CannotOpenSocketException ;
2324use PHPUnit \TextUI \InvalidSocketException ;
2425use 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 ;
0 commit comments