Skip to content

Commit

Permalink
feat: Use Rust FFI
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Dec 3, 2021
1 parent be7c9a6 commit 1117526
Show file tree
Hide file tree
Showing 92 changed files with 2,569 additions and 4,603 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.3', '7.4', '8.0' ]
php: [ '7.4', '8.0' ]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
fail-fast: true
matrix:
operating-system: [ ubuntu-latest, macos-latest, windows-latest ]
php: [ '7.3', '7.4', '8.0' ]
php: [ '7.4', '8.0' ]
dependencies: [ 'lowest', 'locked' ]

name: PHP ${{ matrix.php }} on ${{ matrix.operating-system }} with ${{ matrix.dependencies }} dependencies
Expand All @@ -52,6 +52,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ffi

- name: Copy the inis
if: runner.os == 'Windows'
Expand Down
281 changes: 160 additions & 121 deletions README.md

Large diffs are not rendered by default.

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

* Removed `InteractionBuilder::finalize`, use `InteractionBuilder::verify` instead
* Removed `BuilderInterface::writePact`, use `BuilderInterface::verify` instead
* Removed `PactConfigInterface`, use `MockServerConfigInterface` instead
* [BC BREAK] Updated `MockServerConfigInterface`, removed methods related to http mock server
* Removed environment variables:
- PACT_LOG
- PACT_MOCK_SERVER_HOST
- PACT_MOCK_SERVER_PORT
- PACT_CORS
- PACT_MOCK_SERVER_HEALTH_CHECK_TIMEOUT
- PACT_MOCK_SERVER_HEALTH_CHECK_RETRY_SEC
- PACT_BROKER_SSL_VERIFY
- PACT_PROVIDER_NAME
* [BC BREAK] Removed `MockServerConfig::getBaseUri()`, use `InteractionBuilder::getBaseUri()` instead
* [BC BREAK] Need to call `MockServerConfigInterface::setProvider` in each test case
* [BC BREAK] Added `InteractionBuilder::newInteraction`, required to be called before each interaction.
* [BC BREAK] Removed `MockServer`, use `InteractionBuilder::createMockServer` instead
* Allowed multiple interactions per mock server

Example:
```php
$builder = new InteractionBuilder($config);
$builder
->newInteraction()
->given('a person exists')
->uponReceiving('a get request to /hello/{name}')
->with($request)
->willRespondWith($response);
$builder
->newInteraction()
->given('a person exists')
->uponReceiving('a get request to /goodbye/{name}')
->with($request)
->willRespondWith($response);
$builder->createMockServer();
```

* Allowed multiple providers per consumer's test suite

In a test case:
```php
$config = new MockServerEnvConfig();
$config->setProvider('someProvider');
$builder = new InteractionBuilder($config);
```

In another test case:
```php
$config = new MockServerEnvConfig();
$config->setProvider('otherProvider');
$builder = new InteractionBuilder($config);
```

* Removed `VerifierProcess`
* Removed `MessageVerifier`, use `Verifier` instead
* [BC BREAK] Move some methods from `VerifierConfigInterface` to:
- UrlInterface
- BrokerInterface
* [BC BREAK] Updated `Verifier`

Example:
```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();
$verifier->newHandle($config);
$verifier->addFile('C:\SomePath\consumer-provider.json');
$verifier->addDirectory('C:\OtherPath');
$verifier->addUrl($url);
$verifier->addBroker($broker);

$this->assertTrue($verifier->verify());
```

* Removed `ProcessRunnerFactory`
* Removed `PactMessage`
* Removed `PactMessageConfig`, use `MockServerEnvConfig` or `MockServerConfig` instead
* Removed `MockServerHttpService`
* Removed `MockServerHttpServiceInterface`
* Removed `HealthCheckFailedException`
* Removed `BrokerHttpClient`
* Removed `BrokerHttpClientInterface`
* Added `MockServerNotStartedException`
* Removed `ContractDownloader`
* Removed `Model\Interaction`
* Removed `Model\Message`
* [BC BREAK] Updated `StubServerConfigInterface`, see [pact-stub-server](https://github.com/pact-foundation/pact-stub-server)
25 changes: 10 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,28 @@
}
],
"require": {
"php": "^7.3 |^8.0",
"php": "^7.4 |^8.0",
"ext-ffi": "*",
"ext-openssl": "*",
"ext-json": "*",
"composer/semver": "^1.4.0|^3.2.0",
"ext-zip": "*",
"ext-zlib": "*",
"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": "v1.4.0",
"amphp/windows-registry": "v0.3.3",
"guzzlehttp/guzzle": "^7.2.0",
"phpunit/phpunit": ">=8.2.3"
"phpunit/phpunit": ">=8.2.3",
"symfony/filesystem": "^5.3"
},
"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": "^0.12.90"
"phpstan/phpstan": "^0.12.90",
"symfony/process": "^4.2 | ^5.0.9"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -72,8 +67,8 @@
"post-update-cmd": [
"\\PhpPact\\Standalone\\Installer\\InstallManager::uninstall"
],
"start-provider": "php -S localhost:58000 -t example/src/Provider/public/",
"static-code-analysis": "phpstan analyse src/ --level=5",
"start-provider": "php -S localhost:58000 -t example/src/Provider/public/ example/src/Provider/public/proxy.php",
"static-code-analysis": "phpstan analyse src/ --level=5 -c phpstan.neon",
"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"
Expand Down
11 changes: 0 additions & 11 deletions example/pacts/README.md

This file was deleted.

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"
}
}
}
8 changes: 0 additions & 8 deletions example/phpunit.all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<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">
Expand All @@ -29,14 +26,9 @@
</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>
4 changes: 0 additions & 4 deletions example/phpunit.consumer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
</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>
5 changes: 0 additions & 5 deletions example/phpunit.core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@
</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.

9 changes: 3 additions & 6 deletions example/src/Consumer/Service/HttpClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
*/
class HttpClientService
{
/** @var Client */
private $httpClient;

/** @var string */
private $baseUri;
private Client $httpClient;
private string $baseUri;

public function __construct(string $baseUri)
{
Expand All @@ -38,7 +35,7 @@ public function getHelloString(string $name): string
$body = $response->getBody();
$object = \json_decode($body);

return $object->message;
return $object->message->data->generate;
}

/**
Expand Down
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

0 comments on commit 1117526

Please sign in to comment.