Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
108 changes: 70 additions & 38 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,78 @@ name: main
on: [push, pull_request]

jobs:
run:

php-cs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
name: Checkout repository

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: phpstan, php-cs-fixer:3

- name: Install
uses: "ramsey/composer-install@v2"
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.COMPOSER_AUTH }}"}}'

- name: Run PHP CS Fixer
run: php-cs-fixer fix --diff --dry-run

- name: Run PHPStan
run: phpstan analyse src tests example

test:
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 3
needs:
- php-cs
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php-versions: ['8.0', '8.1', '8.2']
dependency-versions: ['lowest', 'highest']
name: PHP ${{ matrix.php-versions }} with ${{ matrix.dependency-versions }} versions of Composer dependencies
dependency-versions: ['lowest', 'locked']
include:
- operating-system: windows-latest
php-versions: '8.0'
dependency-versions: 'locked'
- operating-system: macos-latest
php-versions: '8.0'
dependency-versions: 'locked'
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} with ${{ matrix.dependency-versions }} versions of Composer dependencies
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: phpstan, phpcs, php-cs-fixer:3
coverage: pcov

- name: Checkout
uses: actions/checkout@v2

- name: Install
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependency-versions }}
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.COMPOSER_AUTH }}"}}'

- name: Run PHP CS Fixer
run: php-cs-fixer fix --diff --dry-run

- name: Run PHPStan
run: phpstan analyse src tests example

- name: Test & Generate Code Coverage
run: ./vendor/bin/phpunit
env:
PACT_LOGLEVEL: ${{ vars.PACT_LOGLEVEL }}

- name: Upload coverage results to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=clover.xml -v
if: matrix.php-versions == '8.0'
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
extensions: ffi
php-version: ${{ matrix.php-versions }}
coverage: pcov
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout
uses: actions/checkout@v3

- name: Install
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependency-versions }}
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.COMPOSER_AUTH }}"}}'

- name: Test & Generate Code Coverage
run: composer test
env:
PACT_LOGLEVEL: ${{ vars.PACT_LOGLEVEL }}

- name: Upload coverage results to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=clover.xml -v
if: matrix.php-versions == '8.2'
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"url": "https://github.com/tienvx/pact-php-plugin.git"
}
],
"scripts": {
"test": [
"php -r \"array_map('unlink', glob('./example/consumer/tests/Contract/pacts/*.json'));\"",
"phpunit"
]
},
"extra": {
"downloads": {
"pact-csv-plugin-metadata": {
Expand Down
16 changes: 7 additions & 9 deletions example/broker/pacts/csvConsumer-csvProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
},
"interactions": [
{
"description": "request for a report",
"description": "request for a report.csv",
"interactionMarkup": {
"markup": "# Data\n\n|Name|100|2000-01-01|\n",
"markupType": "COMMON_MARK"
},
"key": "ad7b43bc4dd005f5",
"key": "a565e88863669aab",
"pending": false,
"pluginConfiguration": {
"csv": {
Expand All @@ -23,7 +23,7 @@
],
"request": {
"headers": {
"Content-Type": [
"Accept": [
"text/csv"
]
},
Expand Down Expand Up @@ -72,24 +72,22 @@
"combine": "AND",
"matchers": [
{
"match": "timestamp",
"timestamp": "yyyy-MM-dd"
"format": "yyyy-MM-dd",
"match": "datetime"
}
]
}
}
},
"status": 200
},
"transport": "http",
"type": "Synchronous/HTTP"
}
],
"metadata": {
"pactRust": {
"ffi": "0.3.14",
"mockserver": "0.9.5",
"models": "1.0.0"
"ffi": "0.4.1",
"models": "1.0.4"
},
"pactSpecification": {
"version": "4.0"
Expand Down
13 changes: 8 additions & 5 deletions example/consumer/tests/Contract/CsvHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function testGetCsvFile()
$request
->setMethod('GET')
->setPath('/report.csv')
->addHeader('Accept', 'text/csv');
->addHeader('Accept', 'text/csv')
;

$response = new ProviderResponse();
$response
Expand All @@ -26,15 +27,16 @@ public function testGetCsvFile()
'csvHeaders' => false,
'column:1' => "matching(type,'Name')",
'column:2' => 'matching(number,100)',
'column:3' => "matching(datetime, 'yyyy-MM-dd','2000-01-01')"
'column:3' => "matching(datetime, 'yyyy-MM-dd','2000-01-01')",
])
->setContentType('text/csv');
->setContentType('text/csv')
;

$config = new MockServerConfig();
$config->setConsumer('csvConsumer');
$config->setProvider('csvProvider');
$config->setPactSpecificationVersion('4.0.0');
$config->setPactDir(__DIR__ . '/pacts');
$config->setPactDir(__DIR__.'/pacts');
if ($logLevel = \getenv('PACT_LOGLEVEL')) {
$config->setLogLevel($logLevel);
}
Expand All @@ -43,7 +45,8 @@ public function testGetCsvFile()
->given('report.csv file exist')
->uponReceiving('request for a report.csv')
->with($request)
->willRespondWith($response);
->willRespondWith($response)
;

$service = new CsvHttpClient($config->getBaseUri());
$columns = $service->getCsvFile();
Expand Down
5 changes: 3 additions & 2 deletions example/provider/public/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require __DIR__ . '/../../../vendor/autoload.php';
require __DIR__.'/../../../vendor/autoload.php';

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
Expand All @@ -12,7 +12,8 @@
$response->getBody()->write('Hello world!');

return $response
->withHeader('Content-Type', 'text/plain');
->withHeader('Content-Type', 'text/plain')
;
});

$app->post('/change-state', function (Request $request, Response $response) {
Expand Down
18 changes: 13 additions & 5 deletions example/provider/tests/Contract/PactVerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
class PactVerifyTest extends TestCase
{
private Process $process;
private int $port;

protected function setUp(): void
{
$this->process = new Process(['php', '-S', 'localhost:8000', '-t', __DIR__.'/../../public/']);
$this->process = new Process(['php', '-S', 'localhost:0', '-t', __DIR__.'/../../public/']);

$this->process->start();
$this->process->waitUntil(fn () => is_resource(fsockopen('localhost', 8000)));
$this->process->waitUntil(function (string $type, string $output): bool {
$result = preg_match('/Development Server \(http:\/\/localhost:(\d+)\) started/', $output, $matches);
if ($result === 1) {
$this->port = (int)$matches[1];
}

return $result;
});
}

protected function tearDown(): void
Expand All @@ -33,15 +41,15 @@ public function testPactVerifyConsumer()
->setProviderVersion('1.0.0')
->setProviderBranch('main')
->setHost('localhost')
->setPort(8000)
->setStateChangeUrl(new Uri('http://localhost:8000/change-state'))
->setPort($this->port)
->setStateChangeUrl(new Uri("http://localhost:{$this->port}/change-state"))
->setStateChangeTeardown(true)
->setStateChangeAsBody(true)
->setPublishResults(false)
;

$verifier = new Verifier($config);
$verifier->addDirectory(__DIR__ . '/../../../broker/pacts');
$verifier->addDirectory(__DIR__.'/../../../broker/pacts');

$this->assertTrue($verifier->verify());
}
Expand Down
4 changes: 2 additions & 2 deletions src/CsvInteractionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(MockServerConfigInterface $config)

private function setPluginDir(): void
{
$pluginDir = __DIR__ . '/../bin/pact-plugins';
\putenv("PACT_PLUGIN_DIR=$pluginDir");
$pluginDir = __DIR__.'/../bin/pact-plugins';
\putenv("PACT_PLUGIN_DIR={$pluginDir}");
}
}
11 changes: 3 additions & 8 deletions tests/CsvInteractionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

namespace Tienvx\PactPhpCsv\Tests;

use PhpPact\Consumer\InteractionBuilder;
use PhpPact\Consumer\Matcher\Matcher;
use PhpPact\Consumer\Model\ConsumerRequest;
use PhpPact\Consumer\Model\ProviderResponse;
use PhpPact\Standalone\Exception\MissingEnvVariableException;
use PhpPact\Standalone\MockService\MockServerConfig;
use PhpPact\Standalone\MockService\MockServerConfigInterface;
use PhpPact\Standalone\MockService\MockServerEnvConfig;
use PHPUnit\Framework\TestCase;
use Tienvx\PactPhpCsv\CsvInteractionBuilder;
use Tienvx\PactPhpPlugin\Exception\PluginNotSupportedBySpecificationException;
Expand All @@ -24,7 +18,8 @@ protected function setUp(): void
$this->config
->setConsumer('consumer')
->setProvider('provider')
->setLogLevel('debug');
->setLogLevel('debug')
;
}

public function testPluginNotSupportedBySpecification(): void
Expand All @@ -40,6 +35,6 @@ public function testPluginSupportedBySpecification(): void
$this->config->setPactSpecificationVersion('4.0.0');
\putenv('PACT_PLUGIN_DIR=/home');
new CsvInteractionBuilder($this->config);
$this->assertSame(realpath(__DIR__ . '/../bin/pact-plugins'), realpath(\getenv('PACT_PLUGIN_DIR')));
$this->assertSame(realpath(__DIR__.'/../bin/pact-plugins'), realpath(\getenv('PACT_PLUGIN_DIR')));
}
}