Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
b45e9c0
Use Rust FFI: Consumer
tienvx Dec 23, 2022
849efd5
Merge branch 'master' into use-rust-ffi-consumer
tienvx Jan 11, 2023
e1d49cc
Remove method BuilderInterface::writePact
tienvx Jan 11, 2023
0d7fe0a
Remove CHANGELOG.md. Add '@internal' to classes are not supposed to b…
tienvx Jan 15, 2023
0812b31
Add missing return type to method Matcher::regex
tienvx Jan 15, 2023
cf5144b
Add more details to UPGRADE-9.0.md
tienvx Jan 15, 2023
d20f1f5
Revert multiple values support in header and query parameter
tienvx Jan 16, 2023
7d57b25
Merge branch 'master' into use-rust-ffi-consumer
Feb 14, 2023
bb256ef
Support multiple values in header and query parameter
tienvx Mar 1, 2023
d6a9d0d
Update pact ffi library
tienvx Mar 1, 2023
ca46297
Rename method getCode to getHeader
tienvx Mar 2, 2023
39718b9
Revert breaking change that require to call createMockServer manually
tienvx Mar 12, 2023
ddc46e5
Remove composer/semver
tienvx Mar 2, 2023
5dae03a
Make sure every value of header and query parameter is string
tienvx Mar 14, 2023
52e9a99
Move exception message to exception
tienvx Mar 14, 2023
bff0f9b
Extract method getSpecification() to check for supporting plugin
tienvx Mar 14, 2023
312c45c
Extract, change visibility, and move methods to abstract class to sup…
tienvx Mar 14, 2023
e7675e6
Use Rust FFI: Support multiple provider states with params for intera…
tienvx Mar 7, 2023
1e0b409
Fix provider state without params not added
tienvx Mar 16, 2023
47b0a81
Remove jsonSerialize methods
tienvx Jan 5, 2023
2754f47
Rename pact to driver
tienvx Mar 17, 2023
18b85b2
Move log level config to trait for reusing
tienvx Mar 23, 2023
5a4b15f
Allow mock server write pact file
tienvx Mar 23, 2023
07c63ac
feat: arm64 linux/macos + x86 windows
YOU54F Apr 28, 2023
fd24111
Merge remote-tracking branch 'origin/master' into arm64_ruby
YOU54F Apr 28, 2023
f37c8ee
feat: use pact-ruby-standalone 2.0.0 release
YOU54F Apr 28, 2023
d7060a2
ci: test arm64 linux
YOU54F Apr 28, 2023
60ae161
Merge branch 'fix/display_stderr_on_publish_error' into arm64_ruby
YOU54F Apr 28, 2023
6ad0384
ci(test): describeVersion test bork on aarch64 linux?!!
YOU54F Apr 29, 2023
9b4aa27
chore: cs-lint:
YOU54F Apr 29, 2023
ed38782
ci: ruby aarch64 linux needs libyaml-dev dep
YOU54F Apr 29, 2023
25335fd
Merge branch 'master' into arm64_ruby
YOU54F Apr 29, 2023
072cc93
Merge branch 'master' into use-rust-ffi-consumer
tienvx May 3, 2023
29b33ec
Revert removing semver
tienvx May 3, 2023
a0302bc
Extract services and helpers
tienvx May 4, 2023
7fbc58d
Make PR smaller
tienvx May 4, 2023
ff2120f
Extract drivers and factories
tienvx May 4, 2023
420f4c2
Extract set up method
tienvx May 5, 2023
7f472fe
Simplify default interaction registry factory
tienvx May 5, 2023
c87dd62
Move methods from AbstractDriver to InteractionDriver and rename
tienvx May 5, 2023
53cef3d
Group assertions together for better readability
tienvx May 5, 2023
d5a4b83
Remove condition to make code shorter
tienvx May 5, 2023
6cf8128
Update ffi library to 0.4.4
tienvx May 5, 2023
156f989
Remove not useful annotation
tienvx May 5, 2023
bd8b751
Rename ffi service and move it to FFI namespace
tienvx May 6, 2023
d41e1ac
Assign result to variable before asserting
tienvx May 8, 2023
cc7f14c
Change type hint from 'mixed' to 'string|array|null'
tienvx May 8, 2023
dfaa021
Add @throws annotation to setPactFileWriteMode() method declaration b…
tienvx May 8, 2023
693daad
Rename FFI Proxy to Client
tienvx May 8, 2023
d960221
Extract interaction part drivers
tienvx May 8, 2023
770e6e0
Extract interaction contents drivers
tienvx May 9, 2023
29f7b4c
Extract interaction part traits for reusing
tienvx May 9, 2023
768b772
Allow sub-class access properties
tienvx May 9, 2023
a96c56a
Move common code back to MockServer for reusing. Remove methods from …
tienvx May 9, 2023
264018a
Move code from registry to driver
tienvx May 9, 2023
3a3afda
Switch term 'Driver' <--> 'Registry'
tienvx May 10, 2023
02b7fc3
Merge branch 'master' into use-rust-ffi-consumer
tienvx May 11, 2023
1d6d39e
Inject driver factory into builder
tienvx May 12, 2023
f844be0
Revert namespace change
tienvx May 12, 2023
d5d14e8
Use Rust FFI: Message Consumer
tienvx Dec 28, 2022
6aad456
Use Rust FFI: Provider
tienvx Jan 2, 2023
e96453f
Use Rust FFI: Stub Server
tienvx Jan 3, 2023
6d19fa8
Use Rust FFI: Offload process
tienvx Jan 3, 2023
e401847
Use Rust FFI: Remove pact broker
tienvx Mar 13, 2023
e799d37
Use Rust FFI: Allow set content type
tienvx Mar 15, 2023
6f53e7a
Default port zero
tienvx Mar 2, 2023
cbe6de1
Make mock server host and port optional
tienvx Mar 13, 2023
b373a32
Add generators and matchers
tienvx May 7, 2023
cd49913
Move endpoint from config to parameter
tienvx Mar 6, 2023
05fca68
Allow random port for stub server
tienvx Mar 6, 2023
194ad08
Fix stub server hang on too low log level
tienvx Apr 4, 2023
08d88cd
Merge branch 'add-generators-and-matchers' into all
tienvx May 12, 2023
18e0a8d
Merge branch 'use-rust-ffi-default-port-zero' into all
tienvx May 12, 2023
07011e3
Merge branch 'use-rust-ffi-move-endpoint-config' into all
tienvx May 12, 2023
2706eff
Merge branch 'use-rust-ffi-stub-server-random-port' into all
tienvx May 12, 2023
64399fe
test: v2.0.1 (pact-2.0.1) - pact-ruby-standalone
YOU54F May 18, 2023
7d0bb98
Merge branch 'master' into arm64_ruby
YOU54F May 18, 2023
9dbbde1
Fix stub server always load pact files from pact broker
tienvx May 29, 2023
6b07881
Merge branch 'offload-process' into all
tienvx May 29, 2023
444a84f
chore: update pact-ruby-standalone to 2.0.2
YOU54F Jul 10, 2023
64a99f6
deps(ci): create dependabot config
YOU54F Jul 12, 2023
7ebfafd
docs: releasing instructions
YOU54F Jul 12, 2023
a853e39
chore: lint test
YOU54F Jul 14, 2023
1965a1a
feat: MockServerConfig improvements - allow setting of defaults
slt Jun 12, 2023
be5dd8d
feat: Speed up pact-php - allow floats in healthcheck sleep
slt Jun 12, 2023
07b12f4
chore: round float to int microseconds for usleep
YOU54F Jul 14, 2023
4705ded
docs: update supported platform docs
YOU54F Jul 14, 2023
43d2e2c
Merge pull request #322 from pact-foundation/slt-fast
YOU54F Jul 14, 2023
8c56e16
Merge pull request #309 from pact-foundation/arm64_ruby
YOU54F Jul 14, 2023
e58fb5a
Merge pull request #321 from pact-foundation/docs/releasing
YOU54F Jul 14, 2023
20af428
Merge pull request #320 from pact-foundation/deps/dependabot
YOU54F Jul 14, 2023
036244d
Merge branch 'all' of github.com:tienvx/pact-php into tienvx-all
YOU54F Jul 24, 2023
498c2a8
chore: support aarch64 in pact-stub-server
YOU54F Jul 24, 2023
90c1005
ci: support for arm64 linux
YOU54F Jul 24, 2023
b8eafd3
chore(docs): add developer docs
YOU54F Jul 24, 2023
d0bad6c
Merge remote-tracking branch 'origin/master' into tienvx-all
YOU54F Jul 24, 2023
02a0951
Merge branch 'tienvx-all' into ffi
YOU54F Jul 24, 2023
bcdc7cc
chore(docs): update migration doc to reflect 10.x
YOU54F Jul 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename pact to driver
  • Loading branch information
tienvx committed Mar 17, 2023
commit 2754f47504d65502b51fd7a16e83f5e17eaedf84
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameters:
excludePaths:
- src/PhpPact/Consumer/Model/AbstractPact.php
- src/PhpPact/Consumer/Model/Pact.php
- src/PhpPact/Consumer/Driver/AbstractDriver.php
- src/PhpPact/Consumer/Driver/InteractionDriver.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
<?php

namespace PhpPact\Consumer\Model;
namespace PhpPact\Consumer\Driver;

use FFI;
use PhpPact\Standalone\Installer\Model\Scripts;
use PhpPact\Standalone\PactConfigInterface;
use PhpPact\Consumer\Exception\PactFileNotWroteException;
use PhpPact\Consumer\Exception\InteractionBodyNotAddedException;
use PhpPact\Consumer\Model\ProviderState;

/**
* Class AbstractPact.
*/
abstract class AbstractPact
abstract class AbstractDriver implements DriverInterface
{
protected FFI $ffi;
protected int $id;
protected int $pactId;
protected int $interactionId;

public function __construct(protected PactConfigInterface $config)
{
$this->ffi = FFI::cdef(\file_get_contents(Scripts::getHeader()), Scripts::getLibrary());
$this
->createFfi()
->initWithLogLevel()
->newPact()
->withSpecification();
}

private function createFfi(): self
private function newPact(): self
{
$this->ffi = FFI::cdef(\file_get_contents(Scripts::getHeader()), Scripts::getLibrary());
$this->pactId = $this->ffi->pactffi_new_pact($this->config->getConsumer(), $this->config->getProvider());

return $this;
}

private function newPact(): self
protected function newInteraction(string $description): self
{
$this->interactionId = $this->ffi->pactffi_new_interaction($this->pactId, $description);

return $this;
}

private function withSpecification(): self
{
$this->id = $this->ffi->pactffi_new_pact($this->config->getConsumer(), $this->config->getProvider());
$this->ffi->pactffi_with_specification($this->pactId, $this->getSpecification());

return $this;
}
Expand All @@ -58,27 +65,15 @@ protected function getSpecification(): int
return $specification;
}

private function withSpecification(): self
{
$this->ffi->pactffi_with_specification($this->id, $this->getSpecification());

return $this;
}

protected function newInteraction(?string $description): int
{
return $this->ffi->pactffi_new_interaction($this->id, $description);
}

protected function cleanUp(): void
{
$this->ffi->pactffi_free_pact_handle($this->id);
$this->ffi->pactffi_free_pact_handle($this->pactId);
}

protected function writePact(): void
{
$error = $this->ffi->pactffi_pact_handle_write_file(
$this->id,
$this->pactId,
$this->config->getPactDir(),
$this->config->getPactFileWriteMode() === PactConfigInterface::MODE_OVERWRITE
);
Expand All @@ -87,14 +82,42 @@ protected function writePact(): void
}
}

protected function withBody(int $interaction, int $part, ?string $contentType = null, ?string $body = null): void
protected function withBody(int $part, ?string $contentType = null, ?string $body = null): void
{
if (is_null($body)) {
return;
}
$success = $this->ffi->pactffi_with_body($interaction, $part, $contentType, $body);
$success = $this->ffi->pactffi_with_body($this->interactionId, $part, $contentType, $body);
if (!$success) {
throw new InteractionBodyNotAddedException();
}
}

private function initWithLogLevel(): self
{
$logLevel = $this->config->getLogLevel();
if ($logLevel) {
$this->ffi->pactffi_init_with_log_level($logLevel);
}

return $this;
}

/**
* @var array<ProviderState> $providerStates
*/
protected function setProviderStates(array $providerStates): void
{
foreach ($providerStates as $providerState) {
$this->ffi->pactffi_given($this->interactionId, $providerState->getName());
foreach ($providerState->getParams() as $key => $value) {
$this->ffi->pactffi_given_with_param($this->interactionId, $providerState->getName(), $key, $value);
}
}
}

protected function setDescription(string $description): void
{
$this->ffi->pactffi_upon_receiving($this->interactionId, $description);
}
}
7 changes: 7 additions & 0 deletions src/PhpPact/Consumer/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace PhpPact\Consumer\Driver;

interface DriverInterface
{
}
50 changes: 50 additions & 0 deletions src/PhpPact/Consumer/Driver/HasMockServerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace PhpPact\Consumer\Driver;

use FFI;
use PhpPact\Consumer\Exception\MockServerNotStartedException;
use PhpPact\Standalone\MockService\MockServerConfigInterface;

trait HasMockServerTrait
{
protected function createMockServer(): void
{
$port = $this->ffi->pactffi_create_mock_server_for_transport(
$this->pactId,
$this->getMockServerConfig()->getHost(),
$this->getMockServerConfig()->getPort(),
$this->getMockServerTransport(),
null
);

if ($port < 0) {
throw new MockServerNotStartedException($port);
}
$this->getMockServerConfig()->setPort($port);
}

protected function mockServerMatched(): bool
{
$matched = $this->ffi->pactffi_mock_server_matched($this->getMockServerConfig()->getPort());

try {
if ($matched) {
$this->writePact();
}
} finally {
$this->cleanUp();
}

return $matched;
}

protected function cleanUpMockServer(): void
{
$this->ffi->pactffi_cleanup_mock_server($this->getMockServerConfig()->getPort());
}

abstract protected function getMockServerTransport(): string;

abstract protected function getMockServerConfig(): MockServerConfigInterface;
}
103 changes: 103 additions & 0 deletions src/PhpPact/Consumer/Driver/InteractionDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace PhpPact\Consumer\Driver;

use PhpPact\Consumer\Model\Interaction;
use PhpPact\Standalone\MockService\MockServerConfigInterface;

class InteractionDriver extends AbstractDriver implements InteractionDriverInterface
{
use HasMockServerTrait;

public function __construct(MockServerConfigInterface $config)
{
parent::__construct($config);
}

protected function getMockServerTransport(): string
{
return $this->config->isSecure() ? 'https' : 'http';
}

protected function getMockServerConfig(): MockServerConfigInterface
{
return $this->config;
}

public function verifyInteractions(): bool
{
return $this->mockServerMatched();
}

protected function cleanUp(): void
{
$this->cleanUpMockServer();
parent::cleanUp();
}

public function registerInteraction(Interaction $interaction): bool
{
$this
->newInteraction($interaction->getDescription())
->given($interaction)
->uponReceiving($interaction)
->with($interaction)
->willRespondWith($interaction)
->createMockServer();

return true;
}

private function given(Interaction $interaction): self
{
$this->setProviderStates($interaction->getProviderStates());

return $this;
}

private function uponReceiving(Interaction $interaction): self
{
$this->setDescription($interaction->getDescription());

return $this;
}

private function with(Interaction $interaction): self
{
$request = $interaction->getRequest();
$this->ffi->pactffi_with_request($this->interactionId, $request->getMethod(), $request->getPath());
$this->withHeaders($this->ffi->InteractionPart_Request, $request->getHeaders());
$this->withQuery($request->getQuery());
$this->withBody($this->ffi->InteractionPart_Request, null, $request->getBody());

return $this;
}

private function willRespondWith(Interaction $interaction): self
{
$response = $interaction->getResponse();
$this->ffi->pactffi_response_status($this->interactionId, $response->getStatus());
$this->withHeaders($this->ffi->InteractionPart_Response, $response->getHeaders());
$this->withBody($this->ffi->InteractionPart_Response, null, $response->getBody());

return $this;
}

private function withHeaders(int $part, array $headers): void
{
foreach ($headers as $header => $values) {
foreach (array_values($values) as $index => $value) {
$this->ffi->pactffi_with_header_v2($this->interactionId, $part, (string) $header, (int) $index, (string) $value);
}
}
}

private function withQuery(array $query): void
{
foreach ($query as $key => $values) {
foreach (array_values($values) as $index => $value) {
$this->ffi->pactffi_with_query_parameter_v2($this->interactionId, (string) $key, (int) $index, (string) $value);
}
}
}
}
12 changes: 12 additions & 0 deletions src/PhpPact/Consumer/Driver/InteractionDriverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace PhpPact\Consumer\Driver;

use PhpPact\Consumer\Model\Interaction;

interface InteractionDriverInterface extends DriverInterface
{
public function verifyInteractions(): bool;

public function registerInteraction(Interaction $interaction): bool;
}
13 changes: 7 additions & 6 deletions src/PhpPact/Consumer/InteractionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PhpPact\Consumer;

use PhpPact\Consumer\Driver\InteractionDriver;
use PhpPact\Consumer\Driver\InteractionDriverInterface;
use PhpPact\Consumer\Model\ConsumerRequest;
use PhpPact\Consumer\Model\Interaction;
use PhpPact\Consumer\Model\Pact;
use PhpPact\Consumer\Model\ProviderResponse;
use PhpPact\Standalone\MockService\MockServerConfigInterface;

Expand All @@ -17,8 +18,8 @@ class InteractionBuilder implements BuilderInterface
/** @var Interaction */
protected Interaction $interaction;

/** @var Pact */
protected Pact $pact;
/** @var InteractionDriverInterface */
protected InteractionDriverInterface $driver;

/**
* InteractionBuilder constructor.
Expand All @@ -28,7 +29,7 @@ class InteractionBuilder implements BuilderInterface
public function __construct(MockServerConfigInterface $config)
{
$this->interaction = new Interaction();
$this->pact = new Pact($config);
$this->driver = new InteractionDriver($config);
}

/**
Expand Down Expand Up @@ -78,14 +79,14 @@ public function willRespondWith(ProviderResponse $response): bool
{
$this->interaction->setResponse($response);

return $this->pact->registerInteraction($this->interaction);
return $this->driver->registerInteraction($this->interaction);
}

/**
* {@inheritdoc}
*/
public function verify(): bool
{
return $this->pact->verifyInteractions();
return $this->driver->verifyInteractions();
}
}
Loading