diff --git a/src/PhpPact/Consumer/Driver/InteractionPart/AbstractInteractionPartDriver.php b/src/PhpPact/Consumer/Driver/InteractionPart/AbstractInteractionPartDriver.php index 59cb2417..8f32e721 100644 --- a/src/PhpPact/Consumer/Driver/InteractionPart/AbstractInteractionPartDriver.php +++ b/src/PhpPact/Consumer/Driver/InteractionPart/AbstractInteractionPartDriver.php @@ -28,8 +28,8 @@ protected function withHeaders(Interaction $interaction, InteractionPart $intera { $headers = $interaction->getHeaders($interactionPart); $partId = match ($interactionPart) { - InteractionPart::REQUEST => $this->client->get('InteractionPart_Request'), - InteractionPart::RESPONSE => $this->client->get('InteractionPart_Response'), + InteractionPart::REQUEST => $this->client->getInteractionPartRequest(), + InteractionPart::RESPONSE => $this->client->getInteractionPartResponse(), }; foreach ($headers as $header => $values) { foreach (array_values($values) as $index => $value) { diff --git a/src/PhpPact/Plugin/Driver/Body/PluginBodyDriver.php b/src/PhpPact/Plugin/Driver/Body/PluginBodyDriver.php index 6e039030..9f985e7f 100644 --- a/src/PhpPact/Plugin/Driver/Body/PluginBodyDriver.php +++ b/src/PhpPact/Plugin/Driver/Body/PluginBodyDriver.php @@ -21,9 +21,9 @@ public function __construct(protected ClientInterface $client) public function registerBody(Interaction|Message $interaction, InteractionPart $interactionPart): void { $body = $interaction instanceof Message ? $interaction->getContents() : $interaction->getBody($interactionPart); - $partId = $interaction instanceof Message ? $this->client->get('InteractionPart_Request') : match ($interactionPart) { - InteractionPart::REQUEST => $this->client->get('InteractionPart_Request'), - InteractionPart::RESPONSE => $this->client->get('InteractionPart_Response'), + $partId = $interaction instanceof Message ? $this->client->getInteractionPartRequest() : match ($interactionPart) { + InteractionPart::REQUEST => $this->client->getInteractionPartRequest(), + InteractionPart::RESPONSE => $this->client->getInteractionPartResponse(), }; switch (true) { case $body instanceof Binary: diff --git a/tests/PhpPact/Consumer/Driver/InteractionPart/RequestDriverTest.php b/tests/PhpPact/Consumer/Driver/InteractionPart/RequestDriverTest.php index 21791197..0d9f1fd7 100644 --- a/tests/PhpPact/Consumer/Driver/InteractionPart/RequestDriverTest.php +++ b/tests/PhpPact/Consumer/Driver/InteractionPart/RequestDriverTest.php @@ -56,8 +56,7 @@ public function testRegisterRequest(): void { $this->client ->expects($this->once()) - ->method('get') - ->with('InteractionPart_Request') + ->method('getInteractionPartRequest') ->willReturn($this->requestPartId); $calls = [ ['pactffi_with_header_v2', $this->interactionHandle, $this->requestPartId, 'header1', 0, 'header-value-1'], diff --git a/tests/PhpPact/Consumer/Driver/InteractionPart/ResponseDriverTest.php b/tests/PhpPact/Consumer/Driver/InteractionPart/ResponseDriverTest.php index 72fbcf11..50180c3b 100644 --- a/tests/PhpPact/Consumer/Driver/InteractionPart/ResponseDriverTest.php +++ b/tests/PhpPact/Consumer/Driver/InteractionPart/ResponseDriverTest.php @@ -46,8 +46,7 @@ public function testRegisterResponse(): void { $this->client ->expects($this->once()) - ->method('get') - ->with('InteractionPart_Response') + ->method('getInteractionPartResponse') ->willReturn($this->responsePartId); $calls = [ ['pactffi_with_header_v2', $this->interactionHandle, $this->responsePartId, 'header1', 0, 'header-value-1'], diff --git a/tests/PhpPact/Plugin/Driver/Body/PluginBodyDriverTest.php b/tests/PhpPact/Plugin/Driver/Body/PluginBodyDriverTest.php index f2884a71..bfb8f5a3 100644 --- a/tests/PhpPact/Plugin/Driver/Body/PluginBodyDriverTest.php +++ b/tests/PhpPact/Plugin/Driver/Body/PluginBodyDriverTest.php @@ -15,7 +15,6 @@ use PhpPact\Plugin\Driver\Body\PluginBodyDriver; use PhpPact\Plugin\Driver\Body\PluginBodyDriverInterface; use PhpPact\Plugin\Exception\PluginBodyNotAddedException; -use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -38,13 +37,6 @@ class PluginBodyDriverTest extends TestCase public function setUp(): void { $this->client = $this->createMock(ClientInterface::class); - $this->client - ->expects($this->once()) - ->method('get') - ->willReturnMap([ - ['InteractionPart_Request', $this->requestPartId], - ['InteractionPart_Response', $this->responsePartId], - ]); $this->driver = new PluginBodyDriver($this->client); $this->interaction = new Interaction(); $this->interaction->setHandle($this->interactionId); @@ -62,6 +54,7 @@ public function setUp(): void #[TestWith([InteractionPart::RESPONSE])] public function testInteractionBinaryBody(InteractionPart $part): void { + $this->expectsGetInteractionPartEnumMethods($part); if ($part === InteractionPart::REQUEST) { $this->interaction->getRequest()->setBody($this->binary); } else { @@ -79,6 +72,7 @@ public function testInteractionBinaryBody(InteractionPart $part): void #[TestWith([InteractionPart::RESPONSE])] public function testMessageBinaryBody(InteractionPart $part): void { + $this->expectsGetInteractionPartEnumMethods(InteractionPart::REQUEST); $this->message->setContents($this->binary); $this->client ->expects($this->never()) @@ -92,6 +86,7 @@ public function testMessageBinaryBody(InteractionPart $part): void #[TestWith([InteractionPart::RESPONSE])] public function testInteractionPlainTextBody(InteractionPart $part): void { + $this->expectsGetInteractionPartEnumMethods($part); if ($part === InteractionPart::REQUEST) { $this->interaction->getRequest()->setBody($this->text); } else { @@ -109,6 +104,7 @@ public function testInteractionPlainTextBody(InteractionPart $part): void #[TestWith([InteractionPart::RESPONSE])] public function testMessagePlainTextBody(InteractionPart $part): void { + $this->expectsGetInteractionPartEnumMethods(InteractionPart::REQUEST); $this->message->setContents($this->text); $this->client ->expects($this->never()) @@ -141,6 +137,7 @@ private function getPluginBodyErrorMessage(int $error): string #[TestWith([7])] public function testRequestJsonBody(int $error): void { + $this->expectsGetInteractionPartEnumMethods(InteractionPart::REQUEST); $this->interaction->getRequest()->setBody($this->json); $this->client ->expects($this->once()) @@ -164,6 +161,7 @@ public function testRequestJsonBody(int $error): void #[TestWith([7])] public function testResponseJsonBody(int $error): void { + $this->expectsGetInteractionPartEnumMethods(InteractionPart::RESPONSE); $this->interaction->getResponse()->setBody($this->json); $this->client ->expects($this->once()) @@ -187,6 +185,7 @@ public function testResponseJsonBody(int $error): void #[TestWith([7])] public function testMessageJsonBody(int $error): void { + $this->expectsGetInteractionPartEnumMethods(InteractionPart::REQUEST); $this->message->setContents($this->json); $this->client ->expects($this->once()) @@ -204,6 +203,7 @@ public function testMessageJsonBody(int $error): void #[TestWith([InteractionPart::RESPONSE])] public function testInteractionMultipartBody(InteractionPart $part): void { + $this->expectsGetInteractionPartEnumMethods($part); if ($part === InteractionPart::REQUEST) { $this->interaction->getRequest()->setBody($this->multipart); } else { @@ -221,6 +221,7 @@ public function testInteractionMultipartBody(InteractionPart $part): void #[TestWith([InteractionPart::RESPONSE])] public function testEmptyInteractionBody(InteractionPart $part): void { + $this->expectsGetInteractionPartEnumMethods($part); $this->client ->expects($this->never()) ->method('call'); @@ -236,4 +237,21 @@ public function testEmptyMessageBody(InteractionPart $part): void ->method('call'); $this->driver->registerBody($this->message, $part); } + + private function expectsGetInteractionPartEnumMethods(InteractionPart $part): void + { + if ($part === InteractionPart::REQUEST) { + $this->client + ->expects($this->once()) + ->method('getInteractionPartRequest') + ->willReturn($this->requestPartId); + $this->client->expects($this->never())->method('getInteractionPartResponse'); + } else { + $this->client->expects($this->never())->method('getInteractionPartRequest'); + $this->client + ->expects($this->once()) + ->method('getInteractionPartResponse') + ->willReturn($this->responsePartId); + } + } }