-
Notifications
You must be signed in to change notification settings - Fork 92
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
16 changed files
with
362 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer; | ||
|
||
use PhpPact\Consumer\Model\Message; | ||
|
||
abstract class AbstractMessageBuilder implements BuilderInterface | ||
{ | ||
protected Message $message; | ||
|
||
public function __construct() | ||
{ | ||
$this->message = new Message(); | ||
} | ||
|
||
/** | ||
* @param string $name what is given to the request | ||
* @param array<string, string> $params for that request | ||
* @param bool $overwrite clear pass states completely and start this array | ||
*/ | ||
public function given(string $name, array $params = [], bool $overwrite = false): self | ||
{ | ||
$this->message->setProviderState($name, $params, $overwrite); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $description what is received when the request is made | ||
*/ | ||
public function expectsToReceive(string $description): self | ||
{ | ||
$this->message->setDescription($description); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param array<string, string> $metadata what is the additional metadata of the message | ||
*/ | ||
public function withMetadata(array $metadata): self | ||
{ | ||
$this->message->setMetadata($metadata); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Make the http request to the Mock Service to register the message. Content is required. | ||
* | ||
* @param mixed $contents required to be in the message | ||
*/ | ||
public function withContent(mixed $contents): self | ||
{ | ||
$this->message->setContents($contents); | ||
|
||
return $this; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction; | ||
|
||
use PhpPact\Consumer\Driver\Pact\PactDriverInterface; | ||
use PhpPact\Consumer\Model\Message; | ||
use PhpPact\Consumer\Registry\Interaction\MessageRegistryInterface; | ||
use PhpPact\FFI\ClientInterface; | ||
|
||
class MessageDriver implements MessageDriverInterface | ||
{ | ||
public function __construct( | ||
private ClientInterface $client, | ||
private PactDriverInterface $pactDriver, | ||
private MessageRegistryInterface $messageRegistry | ||
) { | ||
} | ||
|
||
public function reify(): string | ||
{ | ||
return $this->client->call('pactffi_message_reify', $this->messageRegistry->getId()); | ||
} | ||
|
||
public function writePactAndCleanUp(): bool | ||
{ | ||
$this->pactDriver->writePact(); | ||
$this->pactDriver->cleanUp(); | ||
|
||
return true; | ||
} | ||
|
||
public function registerMessage(Message $message): void | ||
{ | ||
$this->pactDriver->setUp(); | ||
$this->messageRegistry->registerMessage($message); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/PhpPact/Consumer/Driver/Interaction/MessageDriverInterface.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,14 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction; | ||
|
||
use PhpPact\Consumer\Model\Message; | ||
|
||
interface MessageDriverInterface | ||
{ | ||
public function registerMessage(Message $message): void; | ||
|
||
public function reify(): string; | ||
|
||
public function writePactAndCleanUp(): bool; | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Factory; | ||
|
||
use PhpPact\Consumer\Driver\Interaction\MessageDriver; | ||
use PhpPact\Consumer\Driver\Interaction\MessageDriverInterface; | ||
use PhpPact\Consumer\Driver\Pact\PactDriver; | ||
use PhpPact\Config\PactConfigInterface; | ||
use PhpPact\Consumer\Registry\Interaction\MessageRegistry; | ||
use PhpPact\Consumer\Registry\Pact\PactRegistry; | ||
use PhpPact\FFI\Client; | ||
|
||
class MessageDriverFactory | ||
{ | ||
public static function create(PactConfigInterface $config): MessageDriverInterface | ||
{ | ||
$client = new Client(); | ||
$pactRegistry = new PactRegistry($client); | ||
$pactDriver = new PactDriver($client, $config, $pactRegistry); | ||
$messageRegistry = new MessageRegistry($client, $pactRegistry); | ||
|
||
return new MessageDriver($client, $pactDriver, $messageRegistry); | ||
} | ||
} |
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
Oops, something went wrong.