-
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
20 changed files
with
450 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="../../../vendor/autoload.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="PhpPact Example Tests"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="PACT_LOGLEVEL" value="DEBUG"/> | ||
</php> | ||
</phpunit> |
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,28 @@ | ||
<?php | ||
|
||
namespace CsvConsumer\Service; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Psr7\Uri; | ||
|
||
class HttpClientService | ||
{ | ||
private Client $httpClient; | ||
|
||
private string $baseUri; | ||
|
||
public function __construct(string $baseUri) | ||
{ | ||
$this->httpClient = new Client(); | ||
$this->baseUri = $baseUri; | ||
} | ||
|
||
public function getReport(): array | ||
{ | ||
$response = $this->httpClient->get(new Uri("{$this->baseUri}/report.csv"), [ | ||
'headers' => ['Accept' => 'text/csv'] | ||
]); | ||
|
||
return str_getcsv($response->getBody()); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
example/csv/consumer/tests/Service/HttpClientServiceTest.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,63 @@ | ||
<?php | ||
|
||
namespace CsvConsumer\Tests\Service; | ||
|
||
use CsvConsumer\Service\HttpClientService; | ||
use PhpPact\Consumer\InteractionBuilder; | ||
use PhpPact\Consumer\Model\Body\Text; | ||
use PhpPact\Consumer\Model\ConsumerRequest; | ||
use PhpPact\Consumer\Model\ProviderResponse; | ||
use PhpPact\Plugins\Csv\Factory\CsvInteractionDriverFactory; | ||
use PhpPact\Standalone\MockService\MockServerConfig; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HttpClientServiceTest extends TestCase | ||
{ | ||
public function testGetCsvFile(): void | ||
{ | ||
$request = new ConsumerRequest(); | ||
$request | ||
->setMethod('GET') | ||
->setPath('/report.csv') | ||
->addHeader('Accept', 'text/csv') | ||
; | ||
|
||
$response = new ProviderResponse(); | ||
$response | ||
->setStatus(200) | ||
->setBody(new Text( | ||
json_encode([ | ||
'csvHeaders' => false, | ||
'column:1' => "matching(type,'Name')", | ||
'column:2' => 'matching(number,100)', | ||
'column:3' => "matching(datetime, 'yyyy-MM-dd','2000-01-01')", | ||
]), | ||
'text/csv' | ||
)) | ||
; | ||
|
||
$config = new MockServerConfig(); | ||
$config | ||
->setConsumer('csvConsumer') | ||
->setProvider('csvProvider') | ||
->setPactSpecificationVersion('4.0.0') | ||
->setPactDir(__DIR__.'/../../../pacts'); | ||
if ($logLevel = \getenv('PACT_LOGLEVEL')) { | ||
$config->setLogLevel($logLevel); | ||
} | ||
$builder = new InteractionBuilder($config, new CsvInteractionDriverFactory()); | ||
$builder | ||
->given('report.csv file exist') | ||
->uponReceiving('request for a report.csv') | ||
->with($request) | ||
->willRespondWith($response) | ||
; | ||
|
||
$service = new HttpClientService($config->getBaseUri()); | ||
$columns = $service->getReport(); | ||
|
||
$this->assertTrue($builder->verify()); | ||
$this->assertCount(3, $columns); | ||
$this->assertSame(['Name', '100', '2000-01-01'], $columns); | ||
} | ||
} |
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,108 @@ | ||
{ | ||
"consumer": { | ||
"name": "csvConsumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "request for a report.csv", | ||
"interactionMarkup": { | ||
"markup": "# Data\n\n|Name|100|2000-01-01|\n", | ||
"markupType": "COMMON_MARK" | ||
}, | ||
"pending": false, | ||
"pluginConfiguration": { | ||
"csv": { | ||
"csvHeaders": false | ||
} | ||
}, | ||
"providerStates": [ | ||
{ | ||
"name": "report.csv file exist" | ||
} | ||
], | ||
"request": { | ||
"headers": { | ||
"Accept": [ | ||
"text/csv" | ||
] | ||
}, | ||
"method": "GET", | ||
"path": "/report.csv" | ||
}, | ||
"response": { | ||
"body": { | ||
"content": "Name,100,2000-01-01\n", | ||
"contentType": "text/csv;charset=utf-8", | ||
"contentTypeHint": "DEFAULT", | ||
"encoded": false | ||
}, | ||
"generators": { | ||
"body": { | ||
"column:3": { | ||
"format": "yyyy-MM-dd", | ||
"type": "DateTime" | ||
} | ||
} | ||
}, | ||
"headers": { | ||
"content-type": [ | ||
"text/csv" | ||
] | ||
}, | ||
"matchingRules": { | ||
"body": { | ||
"column:1": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
}, | ||
"column:2": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "number" | ||
} | ||
] | ||
}, | ||
"column:3": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"format": "yyyy-MM-dd", | ||
"match": "datetime" | ||
} | ||
] | ||
} | ||
}, | ||
"status": {} | ||
}, | ||
"status": 200 | ||
}, | ||
"transport": "http", | ||
"type": "Synchronous/HTTP" | ||
} | ||
], | ||
"metadata": { | ||
"pactRust": { | ||
"ffi": "0.4.11", | ||
"mockserver": "1.2.4", | ||
"models": "1.1.12" | ||
}, | ||
"pactSpecification": { | ||
"version": "4.0" | ||
}, | ||
"plugins": [ | ||
{ | ||
"configuration": {}, | ||
"name": "csv", | ||
"version": "0.0.3" | ||
} | ||
] | ||
}, | ||
"provider": { | ||
"name": "csvProvider" | ||
} | ||
} |
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="../../../vendor/autoload.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="PhpPact Example Tests"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="PACT_LOGLEVEL" value="DEBUG"/> | ||
</php> | ||
</phpunit> |
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,15 @@ | ||
<?php | ||
|
||
require __DIR__.'/../../../../vendor/autoload.php'; | ||
|
||
use Psr\Http\Message\ResponseInterface as Response; | ||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
use Slim\Factory\AppFactory; | ||
|
||
$app = AppFactory::create(); | ||
|
||
$app->post('/pact-change-state', function (Request $request, Response $response) { | ||
return $response; | ||
}); | ||
|
||
$app->run(); |
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,11 @@ | ||
"Mack Greenholt Jr.",943,2003-02-05 | ||
"Luigi Ruecker",654,1980-09-11 | ||
"Mr. Unique Zieme",79,2020-04-30 | ||
"Leif Price",367,2013-04-07 | ||
"Destiny Rodriguez",995,1983-03-20 | ||
"Lavinia Carroll",344,2010-08-01 | ||
"Reta Schoen",113,2001-01-26 | ||
"Mrs. Carolina Swift",494,1982-01-20 | ||
"Gene Crona PhD",852,1992-11-16 | ||
"Dr. Santino Koepp",79,1984-05-05 | ||
"Luigi Sanford",969,1995-07-02 |
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,53 @@ | ||
<?php | ||
|
||
namespace CsvProvider\Tests; | ||
|
||
use GuzzleHttp\Psr7\Uri; | ||
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig; | ||
use PhpPact\Standalone\ProviderVerifier\Verifier; | ||
use PhpPactTest\Helper\ProviderProcess; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PactVerifyTest extends TestCase | ||
{ | ||
private ProviderProcess $process; | ||
|
||
/** | ||
* Run the PHP build-in web server. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->process = new ProviderProcess(__DIR__ . '/../public/'); | ||
$this->process->start(); | ||
} | ||
|
||
/** | ||
* Stop the web server process once complete. | ||
*/ | ||
protected function tearDown(): void | ||
{ | ||
$this->process->stop(); | ||
} | ||
|
||
public function testPactVerifyConsumer(): void | ||
{ | ||
$config = new VerifierConfig(); | ||
$config->getProviderInfo() | ||
->setName('csvProvider') | ||
->setHost('localhost') | ||
->setPort(7202); | ||
$config->getProviderState() | ||
->setStateChangeUrl(new Uri('http://localhost:7202/pact-change-state')) | ||
; | ||
if ($logLevel = \getenv('PACT_LOGLEVEL')) { | ||
$config->setLogLevel($logLevel); | ||
} | ||
|
||
$verifier = new Verifier($config); | ||
$verifier->addFile(__DIR__ . '/../../pacts/csvConsumer-csvProvider.json'); | ||
|
||
$verifyResult = $verifier->verify(); | ||
|
||
$this->assertTrue($verifyResult); | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
.../Driver/Pact/AbstractPluginPactDriver.php → .../Driver/Pact/AbstractPluginPactDriver.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
4 changes: 2 additions & 2 deletions
4
...n/InteractionContentNotAddedException.php → ...Exception/PluginBodyNotAddedException.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
2 changes: 1 addition & 1 deletion
2
...nNotSupportedBySpecificationException.php → ...nNotSupportedBySpecificationException.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace PhpPact\SyncMessage\Exception; | ||
namespace PhpPact\Plugin\Exception; | ||
|
||
use Exception; | ||
|
||
|
Oops, something went wrong.