refactor: move buspro socket framing into SocketTransport
This commit is contained in:
1 parent
e51664df6c
commit
3c81c79819
4 files changed
+289
-277
No files matched your search
+12
-34
@@ -2,24 +2,17 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet;
|
||||
namespace App\Tests\BusProNet\Transport;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\DataProcessor\BookingDataProcessor;
|
||||
use App\BusProNet\DataProcessor\VoucherSalePayloadBuilder;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Exception\ImmediateConnectionCloseException;
|
||||
use App\BusProNet\XmlParser\ApiResponseParser;
|
||||
use App\Service\RequestIdGenerator;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use App\BusProNet\Transport\SocketTransport;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
class ApiClientReceiveTest extends TestCase
|
||||
class SocketTransportTest extends TestCase
|
||||
{
|
||||
private ?ApiClient $apiClient = null;
|
||||
private ?SocketTransport $transport = null;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -27,24 +20,9 @@ class ApiClientReceiveTest extends TestCase
|
||||
$this->logger = $this->createStub(LoggerInterface::class);
|
||||
}
|
||||
|
||||
private function apiClient(): ApiClient
|
||||
private function transport(): SocketTransport
|
||||
{
|
||||
return $this->apiClient ??= new ApiClient(
|
||||
$this->createStub(SerializerInterface::class),
|
||||
$this->createStub(ApiResponseParser::class),
|
||||
$this->createStub(FilesystemOperator::class),
|
||||
$this->logger,
|
||||
$this->createStub(BookingDataProcessor::class),
|
||||
new VoucherSalePayloadBuilder(),
|
||||
new RequestStack(),
|
||||
new RequestIdGenerator(),
|
||||
[
|
||||
'bpn_username' => 'test',
|
||||
'bpn_password' => 'test',
|
||||
'bpn_api_ip' => '127.0.0.1',
|
||||
'bpn_api_ports' => [9000],
|
||||
],
|
||||
);
|
||||
return $this->transport ??= new SocketTransport($this->logger, '127.0.0.1', [9000]);
|
||||
}
|
||||
|
||||
public function testEmptyResponseThrowsImmediateConnectionCloseException(): void
|
||||
@@ -137,20 +115,20 @@ class ApiClientReceiveTest extends TestCase
|
||||
|
||||
private function invokeReceive($socket): string
|
||||
{
|
||||
$method = new \ReflectionMethod(ApiClient::class, 'receive');
|
||||
$method = new \ReflectionMethod(SocketTransport::class, 'receive');
|
||||
|
||||
return $method->invoke($this->apiClient(), $socket);
|
||||
return $method->invoke($this->transport(), $socket);
|
||||
}
|
||||
|
||||
private function setOperationStartTime(): void
|
||||
{
|
||||
$property = new \ReflectionProperty(ApiClient::class, 'operationStartTime');
|
||||
$property->setValue($this->apiClient(), microtime(true));
|
||||
$property = new \ReflectionProperty(SocketTransport::class, 'operationStartTime');
|
||||
$property->setValue($this->transport(), microtime(true));
|
||||
}
|
||||
|
||||
private function setSelectedPort(int $port): void
|
||||
{
|
||||
$property = new \ReflectionProperty(ApiClient::class, 'selectedPort');
|
||||
$property->setValue($this->apiClient(), $port);
|
||||
$property = new \ReflectionProperty(SocketTransport::class, 'selectedPort');
|
||||
$property->setValue($this->transport(), $port);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user