Skip to content

Commit 32e7843

Browse files
committed
fix: throw exception if we're unable to connect to php-fpm
1 parent 89190ac commit 32e7843

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/FastCgi/PhpFpmProcess.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Ymir\Runtime\FastCgi;
1515

16+
use hollodotme\FastCGI\Exceptions\ConnectException;
1617
use hollodotme\FastCGI\Exceptions\ReadFailedException;
1718
use hollodotme\FastCGI\Exceptions\TimedoutException;
1819
use hollodotme\FastCGI\Interfaces\ProvidesRequestData;
@@ -99,6 +100,8 @@ public function handle(ProvidesRequestData $request, int $timeoutMs): ProvidesRe
99100
{
100101
try {
101102
$response = $this->client->handle($request, $timeoutMs);
103+
} catch (ConnectException $exception) {
104+
throw new PhpFpmProcessException('Unable to connect to PHP-FPM FastCGI socket');
102105
} catch (ReadFailedException $exception) {
103106
throw new PhpFpmProcessException('PHP-FPM process crashed unexpectedly');
104107
} catch (TimedoutException $exception) {

tests/Unit/FastCgi/PhpFpmProcessTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Ymir\Runtime\Tests\Unit\FastCgi;
1515

16+
use hollodotme\FastCGI\Exceptions\ConnectException;
1617
use PHPUnit\Framework\TestCase;
1718
use Ymir\Runtime\Exception\PhpFpm\PhpFpmProcessException;
1819
use Ymir\Runtime\Exception\PhpFpm\PhpFpmTimeoutException;
@@ -78,6 +79,26 @@ public function testHandle(): void
7879
$this->assertSame($response, $phpFpmProcess->handle($request, 1000));
7980
}
8081

82+
public function testHandleWithConnectException(): void
83+
{
84+
$this->expectException(PhpFpmProcessException::class);
85+
$this->expectExceptionMessage('Unable to connect to PHP-FPM FastCGI socket');
86+
87+
$client = $this->getFastCgiServerClientMock();
88+
$logger = $this->getLoggerMock();
89+
$process = $this->getProcessMock();
90+
$request = $this->getProvidesRequestDataMock();
91+
92+
$client->expects($this->once())
93+
->method('handle')
94+
->with($this->identicalTo($request), 1000)
95+
->willThrowException(new ConnectException('connection refused'));
96+
97+
$phpFpmProcess = new PhpFpmProcess($client, $logger, $process);
98+
99+
$phpFpmProcess->handle($request, 1000);
100+
}
101+
81102
public function testHandleWithProcessStopped(): void
82103
{
83104
$this->expectException(PhpFpmProcessException::class);

0 commit comments

Comments
 (0)