-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
145 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/PhpPact/Consumer/Driver/Interaction/Part/AbstractPartDriver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction\Part; | ||
|
||
use PhpPact\Consumer\Driver\Interaction\InteractionDriverInterface; | ||
use PhpPact\Consumer\Exception\InteractionBodyNotAddedException; | ||
use PhpPact\FFI\ClientInterface; | ||
|
||
abstract class AbstractPartDriver implements PartDriverInterface | ||
{ | ||
public function __construct( | ||
protected ClientInterface $client, | ||
protected InteractionDriverInterface $interactionDriver | ||
) { | ||
} | ||
|
||
public function withBody(?string $contentType = null, ?string $body = null): void | ||
{ | ||
if (is_null($body)) { | ||
return; | ||
} | ||
$success = $this->client->call('pactffi_with_body', $this->getInteractionId(), $this->getPart(), $contentType, $body); | ||
if (!$success) { | ||
throw new InteractionBodyNotAddedException(); | ||
} | ||
} | ||
|
||
public function withHeaders(array $headers): void | ||
{ | ||
foreach ($headers as $header => $values) { | ||
foreach (array_values($values) as $index => $value) { | ||
$this->client->call('pactffi_with_header_v2', $this->getInteractionId(), $this->getPart(), (string) $header, (int) $index, (string) $value); | ||
} | ||
} | ||
} | ||
|
||
protected function getInteractionId(): int | ||
{ | ||
return $this->interactionDriver->getId(); | ||
} | ||
|
||
abstract protected function getPart(): int; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/PhpPact/Consumer/Driver/Interaction/Part/PartDriverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction\Part; | ||
|
||
interface PartDriverInterface | ||
{ | ||
public function withBody(?string $contentType = null, ?string $body = null): void; | ||
|
||
/** | ||
* @param array<string, string[]> $headers | ||
*/ | ||
public function withHeaders(array $headers): void; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/PhpPact/Consumer/Driver/Interaction/Part/RequestDriver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction\Part; | ||
|
||
class RequestDriver extends AbstractPartDriver implements RequestDriverInterface | ||
{ | ||
public function withQueryParameters(array $queryParams): void | ||
{ | ||
foreach ($queryParams as $key => $values) { | ||
foreach (array_values($values) as $index => $value) { | ||
$this->client->call('pactffi_with_query_parameter_v2', $this->getInteractionId(), (string) $key, (int) $index, (string) $value); | ||
} | ||
} | ||
} | ||
|
||
public function withRequest(string $method, string $path): void | ||
{ | ||
$this->client->call('pactffi_with_request', $this->getInteractionId(), $method, $path); | ||
} | ||
|
||
protected function getPart(): int | ||
{ | ||
return $this->client->get('InteractionPart_Request'); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/PhpPact/Consumer/Driver/Interaction/Part/RequestDriverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction\Part; | ||
|
||
interface RequestDriverInterface extends PartDriverInterface | ||
{ | ||
/** | ||
* @param array<string, string[]> $queryParams | ||
*/ | ||
public function withQueryParameters(array $queryParams): void; | ||
|
||
public function withRequest(string $method, string $path): void; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/PhpPact/Consumer/Driver/Interaction/Part/ResponseDriver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction\Part; | ||
|
||
class ResponseDriver extends AbstractPartDriver implements ResponseDriverInterface | ||
{ | ||
public function withResponse(int $status): void | ||
{ | ||
$this->client->call('pactffi_response_status', $this->getInteractionId(), $status); | ||
} | ||
|
||
protected function getPart(): int | ||
{ | ||
return $this->client->get('InteractionPart_Response'); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/PhpPact/Consumer/Driver/Interaction/Part/ResponseDriverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction\Part; | ||
|
||
interface ResponseDriverInterface extends PartDriverInterface | ||
{ | ||
public function withResponse(int $status): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters