Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Rust FFI #10: Remove pact broker #302

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 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
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
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
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- uses: ramsey/composer-install@v2
with:
Expand All @@ -48,6 +49,7 @@ jobs:
operating-system: [ ubuntu-latest, macos-latest, windows-latest ]
php: [ '8.0', '8.1', '8.2' ]
dependencies: [ 'lowest', 'locked' ]
timeout-minutes: 5

name: PHP ${{ matrix.php }} on ${{ matrix.operating-system }} with ${{ matrix.dependencies }} dependencies

Expand All @@ -58,8 +60,9 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
extensions: openssl, sockets, curl, zip
extensions: sockets, curl, zip, ffi
php-version: ${{ matrix.php }}
coverage: none

- name: Composer install
uses: ramsey/composer-install@v2
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
->name('*.php');

$config = new PhpCsFixer\Config();
$config->setRules(['@PSR12' => true,
$config->setRules([
'@PSR12' => true,
'strict_param' => false,
'array_syntax' => ['syntax' => 'short'],
])
Expand Down
249 changes: 112 additions & 137 deletions README.md

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions UPGRADE-9.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
UPGRADE FROM 8.x to 9.0
=======================

* Environment Variables
* These environment variables can be removed:
* PACT_CORS
* PACT_MOCK_SERVER_HEALTH_CHECK_TIMEOUT
* PACT_MOCK_SERVER_HEALTH_CHECK_RETRY_SEC

* Verifier
* Different pacts sources can be configured via `addXxx` methods

Example Usage:
```php
$config = new VerifierConfig();
$config
->setPort(8000)
->setProviderName('someProvider')
->setProviderVersion('1.0.0');

$url = new Url();
$url
->setUrl(new Uri('http://localhost'))
->setProviderName('someProvider')
->setUsername('user')
->setPassword('pass')
->setToken('token');

$selectors = (new ConsumerVersionSelectors())
->addSelector('{"tag":"foo","latest":true}')
->addSelector('{"tag":"bar","latest":true}');

$broker = new Broker();
$broker
->setUrl(new Uri('http://localhost'))
->setProviderName('someProvider')
->setUsername('user')
->setPassword('pass')
->setToken('token')
->setConsumerVersionSelectors($selectors);

$verifier = new Verifier($config);
$verifier
->addFile('C:\SomePath\consumer-provider.json');
->addDirectory('C:\OtherPath');
->addUrl($url);
->addBroker($broker);

$verifyResult = $verifier->verify();

$this->assertTrue($verifyResult);
```

* Consumer
* Pact file write mode has been changed from 'overwrite' to 'merge'. Make sure old pact files are removed before running tests.

```shell
rm /path/to/pacts/*.json
```

* Pact files now can ONLY be uploaded to Pact Broker by downloading and running Pact CLI manually.

```shell
pact-broker publish /path/to/pacts/*.json --consumer-app-version 1.0.0 --branch main --broker-base-url https://test.pactflow.io --broker-token SomeToken
```
65 changes: 37 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,20 @@
],
"require": {
"php": "^8.0",
"ext-openssl": "*",
"ext-json": "*",
"composer/semver": "^1.4.0|^3.2.0",
"amphp/amp": "^2.5.1",
"amphp/byte-stream": "^1.8",
"amphp/dns": "^1.2.3",
"amphp/hpack": "^3.1.0",
"amphp/http-server": "^2.1",
"amphp/log": "^1.1",
"amphp/process": "^1.1.1",
"amphp/serialization": "^1.0",
"amphp/socket": "^1.1.3",
"amphp/sync": "^1.4.0",
"amphp/cache": "^1.4.0",
"amphp/windows-registry": "v0.3.3",
"symfony/process": "^4.4|^5.4|^6.0",
"guzzlehttp/guzzle": "^6.5.8|^7.4.5",
"phpunit/phpunit": ">=8.5.23 <10",
"tienvx/composer-downloads-plugin": "^1.1.0"
"tienvx/composer-downloads-plugin": "^1.2.0"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"mockery/mockery": "^1.4.2",
"slim/slim": "^4.6",
"slim/psr7": "^1.2.0",
"friendsofphp/php-cs-fixer": "^3.0",
"php-amqplib/php-amqplib": "^3.0",
"phpstan/phpstan": "^1.9"
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": ">=8.5.23 <10"
},
"autoload": {
"psr-4": {
Expand All @@ -66,27 +53,49 @@
"MessageProvider\\": [
"example/src/MessageProvider",
"example/tests/MessageProvider"
],
"Provider\\": [
"example/src/Provider"
]
}
},
"scripts": {
"start-provider": "php -S localhost:58000 -t example/src/Provider/public/",
"static-code-analysis": "phpstan analyse src/ --level=7",
"lint": "php-cs-fixer fix --config .php-cs-fixer.php --dry-run",
"fix": "php-cs-fixer fix --config .php-cs-fixer.php",
"test": "phpunit --debug -c example/phpunit.all.xml"
"static-code-analysis": "phpstan",
"lint": "php-cs-fixer fix --dry-run",
"fix": "php-cs-fixer fix",
"test": [
"php -r \"array_map('unlink', glob('./example/output/*.json'));\"",
"phpunit --debug -c example/phpunit.all.xml"
]
},
"extra": {
"downloads": {
"pact-ruby-standalone": {
"version": "1.91.0",
"pact-ffi-headers": {
"version": "0.4.4",
"url": "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v{$version}/pact.h",
"path": "bin/pact-ffi-headers/pact.h"
},
"pact-ffi-lib": {
"version": "0.4.4",
"variables": {
"{$prefix}": "PHP_OS_FAMILY === 'Windows' ? 'pact_ffi' : 'libpact_ffi'",
"{$os}": "PHP_OS === 'Darwin' ? 'osx' : strtolower(PHP_OS_FAMILY)",
"{$architecture}": "in_array(php_uname('m'), ['arm64', 'aarch64']) ? (PHP_OS === 'Darwin' ? 'aarch64-apple-darwin' : 'aarch64') : 'x86_64'",
"{$extension}": "PHP_OS_FAMILY === 'Windows' ? 'dll' : (PHP_OS === 'Darwin' ? 'dylib' : 'so')"
},
"url": "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v{$version}/{$prefix}-{$os}-{$architecture}.{$extension}.gz",
"path": "bin/pact-ffi-lib/pact.{$extension}"
},
"pact-stub-server": {
"version": "0.5.3",
"variables": {
"{$os}": "PHP_OS_FAMILY === 'Windows' ? 'win32' : (PHP_OS === 'Darwin' ? 'osx' : 'linux')",
"{$architecture}": "PHP_OS === 'Linux' ? '-x86_64' : ''",
"{$extension}": "PHP_OS_FAMILY === 'Windows' ? 'zip' : 'tar.gz'"
"{$os}": "PHP_OS === 'Darwin' ? 'osx' : strtolower(PHP_OS_FAMILY)",
"{$extension}": "PHP_OS_FAMILY === 'Windows' ? '.exe' : ''"
},
"url": "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v{$version}/pact-{$version}-{$os}{$architecture}.{$extension}",
"path": "bin/pact-ruby-standalone"
"url": "https://github.com/pact-foundation/pact-stub-server/releases/download/v{$version}/pact-stub-server-{$os}-x86_64{$extension}.gz",
"path": "bin/pact-stub-server/pact-stub-server{$extension}",
"executable": true
}
}
},
Expand Down
4 changes: 0 additions & 4 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ All examples could be run within tests.
## Consumer Tests for Message Processing

vendor/bin/phpunit -c example/phpunit.message.consumer.xml

## Provider Verification Tests for Message Processing

vendor/bin/phpunit -c example/phpunit.message.provider.xml

## All tests together

Expand Down
2 changes: 1 addition & 1 deletion example/pacts/someconsumer-someprovider.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"matchingRules": {
"$.body.message": {
"match": "regex",
"regex": "(Hello, )[A-Za-z]"
"regex": "(Hello, )[A-Za-z]+"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion example/pacts/test_consumer-test_provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
"version": "3.0.0"
}
}
}
18 changes: 0 additions & 18 deletions example/phpunit.all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,12 @@
<testsuite name="PhpPact Message Consumer Example Tests">
<directory>./tests/MessageConsumer</directory>
</testsuite>
<testsuite name="PhpPact Message Provider Example Tests">
<directory>./tests/MessageProvider</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="PhpPact\Consumer\Listener\PactTestListener">
<arguments>
<array>
<element key="0">
<string>PhpPact Consumer Example Tests</string>
</element>
</array>
</arguments>
</listener>
</listeners>
<php>
<env name="PACT_MOCK_SERVER_HOST" value="localhost"/>
<env name="PACT_MOCK_SERVER_PORT" value="7200"/>
<env name="PACT_CONSUMER_NAME" value="someConsumer"/>
<env name="PACT_CONSUMER_VERSION" value="1.0.0"/>
<env name="PACT_CONSUMER_TAG" value="master"/>
<env name="PACT_PROVIDER_NAME" value="someProvider"/>
<env name="PACT_OUTPUT_DIR" value=".\example\output\\"/>
<env name="PACT_CORS" value="true"/>
<env name="PACT_MOCK_SERVER_HEALTH_CHECK_RETRY_SEC" value="2"/>
</php>
</phpunit>
15 changes: 0 additions & 15 deletions example/phpunit.consumer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,11 @@
<directory>./tests/Consumer</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="PhpPact\Consumer\Listener\PactTestListener">
<arguments>
<array>
<element key="0">
<string>PhpPact Example Tests</string>
</element>
</array>
</arguments>
</listener>
</listeners>
<php>
<env name="PACT_MOCK_SERVER_HOST" value="localhost"/>
<env name="PACT_MOCK_SERVER_PORT" value="7200"/>
<env name="PACT_CONSUMER_NAME" value="someConsumer"/>
<env name="PACT_CONSUMER_VERSION" value="1.0.0"/>
<env name="PACT_CONSUMER_TAG" value="master"/>
<env name="PACT_PROVIDER_NAME" value="someProvider"/>
<env name="PACT_OUTPUT_DIR" value=".\example\output"/>
<env name="PACT_MOCK_SERVER_HEALTH_CHECK_TIMEOUT" value="10"/>
<!-- <env name="PACT_BROKER_URI" value="http://localhost"/> -->
</php>
</phpunit>
15 changes: 0 additions & 15 deletions example/phpunit.core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,11 @@
<directory>../tests</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="PhpPact\Consumer\Listener\PactTestListener">
<arguments>
<array>
<element key="0">
<string>PhpPact Consumer Example Tests</string>
</element>
</array>
</arguments>
</listener>
</listeners>
<php>
<env name="PACT_MOCK_SERVER_HOST" value="localhost"/>
<env name="PACT_MOCK_SERVER_PORT" value="7200"/>
<env name="PACT_CONSUMER_NAME" value="someConsumer"/>
<env name="PACT_CONSUMER_VERSION" value="1.0.0"/>
<env name="PACT_CONSUMER_TAG" value="master"/>
<env name="PACT_PROVIDER_NAME" value="someProvider"/>
<env name="PACT_OUTPUT_DIR" value=".\example\output\\"/>
<env name="PACT_CORS" value="true"/>
<env name="PACT_MOCK_SERVER_HEALTH_CHECK_RETRY_SEC" value="2"/>
</php>
</phpunit>
8 changes: 0 additions & 8 deletions example/phpunit.message.provider.xml

This file was deleted.

16 changes: 0 additions & 16 deletions example/src/Consumer/publish_json_example.php

This file was deleted.

4 changes: 2 additions & 2 deletions example/src/MessageConsumer/ExampleMessageConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

class ExampleMessageConsumer
{
public function ProcessText($message)
public function ProcessText(string $message): object
{
$obj = \json_decode($message);
print ' [x] Processed ' . \print_r($obj->contents->text, true) . "\n";

return $obj;
}

public function ProcessSong($message)
public function ProcessSong(string $message): object
{
$obj = \json_decode($message);
print ' [x] Processed ' . \print_r($obj->contents->song, true) . "\n";
Expand Down
Loading