Skip to content

Commit c7490ea

Browse files
committed
Move transport creation to tester
1 parent c22f71a commit c7490ea

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

sapi/fpm/tests/fcgi.inc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,24 +444,25 @@ class Client
444444
*/
445445
private $_readWriteTimeout = 5000;
446446

447+
/**
448+
* Data transport instance
449+
* @var Transport
450+
*/
447451
private Transport $transport;
448452

449453
/**
450454
* Constructor
451455
*
452456
* @param string $host Host of the FastCGI application
453457
* @param int $port Port of the FastCGI application
454-
* @param string $transport Transport
458+
* @param Transport $transport Transport
455459
*/
456-
public function __construct($host, $port, string $transport = 'stream')
460+
public function __construct($host, $port, Transport $transport)
457461
{
458462
$this->_host = $host;
459463
$this->_port = $port;
460464

461-
$this->transport = match ($transport) {
462-
'stream' => new StreamTransport(),
463-
'socket' => new SocketTransport(),
464-
};
465+
$this->transport = $transport;
465466
}
466467

467468
/**

sapi/fpm/tests/tester.inc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace FPM;
44

55
use FPM\FastCGI\Client;
6+
use FPM\FastCGI\SocketTransport;
7+
use FPM\FastCGI\StreamTransport;
8+
use FPM\FastCGI\Transport;
69

710
require_once 'fcgi.inc';
811
require_once 'logreader.inc';
@@ -386,6 +389,19 @@ class Tester
386389
$this->clientTransport = $clientTransport;
387390
}
388391

392+
/**
393+
* Creates new client transport.
394+
*
395+
* @return Transport
396+
*/
397+
private function createTransport()
398+
{
399+
return match ($this->clientTransport) {
400+
'stream' => new StreamTransport(),
401+
'socket' => new SocketTransport(),
402+
};
403+
}
404+
389405
/**
390406
* @param string $ini
391407
*/
@@ -936,11 +952,11 @@ class Tester
936952
}
937953

938954
if ( ! $keepAlive) {
939-
return new Client($host, $port, $this->clientTransport);
955+
return new Client($host, $port, $this->createTransport());
940956
}
941957

942958
if ( ! isset($this->clients[$host][$port])) {
943-
$client = new Client($host, $port, $this->clientTransport);
959+
$client = new Client($host, $port, $this->createTransport());
944960
$client->setKeepAlive(true);
945961
$this->clients[$host][$port] = $client;
946962
}

0 commit comments

Comments
 (0)