-
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
13 changed files
with
267 additions
and
111 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,64 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction; | ||
|
||
use FFI; | ||
|
||
class MessageDriver extends AbstractDriver implements MessageDriverInterface | ||
{ | ||
public function newInteraction(string $description): void | ||
{ | ||
$this->id = $this->ffi->call('pactffi_new_message_interaction', $this->pactDriver->getId(), $description); | ||
} | ||
|
||
public function withContents(?string $contentType = null, ?string $body = null): void | ||
{ | ||
if (is_null($body)) { | ||
return; | ||
} | ||
$length = \strlen($body); | ||
$size = $length + 1; | ||
$cData = FFI::new("uint8_t[{$size}]"); | ||
FFI::memcpy($cData, $body, $length); | ||
$this->ffi->call('pactffi_message_with_contents', $this->id, $contentType, $cData, $size); | ||
} | ||
|
||
public function expectsToReceive(string $description): void | ||
{ | ||
$this->ffi->call('pactffi_message_expects_to_receive', $this->id, $description); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function given(array $providerStates): void | ||
{ | ||
foreach ($providerStates as $providerState) { | ||
$this->ffi->call('pactffi_message_given', $this->id, $providerState->getName()); | ||
foreach ($providerState->getParams() as $key => $value) { | ||
$this->ffi->call('pactffi_message_given_with_param', $this->id, $providerState->getName(), (string) $key, (string) $value); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function withMetadata(array $metadata): void | ||
{ | ||
foreach ($metadata as $key => $value) { | ||
$this->ffi->call('pactffi_message_with_metadata', $this->id, (string) $key, (string) $value); | ||
} | ||
} | ||
|
||
public function reify(): string | ||
{ | ||
return $this->ffi->call('pactffi_message_reify', $this->id); | ||
} | ||
|
||
public function writePactAndCleanUp(): void | ||
{ | ||
$this->pactDriver->writePact(); | ||
$this->pactDriver->cleanUp(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Driver\Interaction; | ||
|
||
use PhpPact\Consumer\Model\ProviderState; | ||
|
||
interface MessageDriverInterface extends DriverInterface | ||
{ | ||
public function withContents(?string $contentType = null, ?string $body = null): void; | ||
|
||
public function expectsToReceive(string $description): void; | ||
|
||
/** | ||
* @param ProviderState[] $providerStates | ||
*/ | ||
public function given(array $providerStates): void; | ||
|
||
/** | ||
* @param array<string, string> $metadata | ||
*/ | ||
public function withMetadata(array $metadata): void; | ||
|
||
public function reify(): string; | ||
|
||
public function writePactAndCleanUp(): 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Factory; | ||
|
||
use PhpPact\Consumer\Driver\Interaction\MessageDriver; | ||
use PhpPact\Consumer\Driver\Pact\PactDriver; | ||
use PhpPact\Config\PactConfigInterface; | ||
use PhpPact\Consumer\Service\FFI; | ||
use PhpPact\Consumer\Service\MessageRegistryInterface; | ||
use PhpPact\Consumer\Service\MessageRegistry; | ||
|
||
class MessageRegistryFactory | ||
{ | ||
public static function create(PactConfigInterface $config): MessageRegistryInterface | ||
{ | ||
$ffi = new FFI(); | ||
$pactDriver = new PactDriver($ffi, $config); | ||
$messageDriver = new MessageDriver($ffi, $pactDriver); | ||
|
||
return new MessageRegistry($messageDriver); | ||
} | ||
} |
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
Oops, something went wrong.