Skip to content

Commit

Permalink
Merge pull request #55 from pact-foundation/bugfix/givenproviderorder
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrink91 authored Apr 18, 2018
2 parents c296dbe + 174f925 commit 60bb91b
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Table of contents
* [Make the Request](#make-the-request)
* [Make Assertions](#make-assertions)
* [Basic Provider Usage](#basic-provider-usage)
* [Create Unit Tests](#create-unit-tests)
* [Create Unit Tests](#create-unit-test)
* [Start API](#start-api)
* [Provider Verification](#provider-verification)
* [Verify From Pact Broker](#verify-from-pact-broker)
Expand Down Expand Up @@ -160,8 +160,8 @@ Now that we have the request and response, we need to build the interaction and
$config = new MockServerEnvConfig();
$builder = new InteractionBuilder($config);
$builder
->given('Get Hello')
->uponReceiving('A get request to /hello/{name}')
->given('a person exists')
->uponReceiving('a get request to /hello/{name}')
->with($request)
->willRespondWith($response); // This has to be last. This is what makes an API request to the Mock Server to set the interaction.
```
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
},
"scripts": {
"start-provider": "php -S localhost:58000 -t example/src/Provider/public/",
"test": [
"php-cs-fixer fix --config .php_cs",
"phpunit --debug"
]
"fix": "php-cs-fixer fix --config .php_cs",
"test": "phpunit --debug"
}
}
4 changes: 4 additions & 0 deletions example/tests/Consumer/Service/ConsumerServiceGoodbyeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Consumer\Service;

use PhpPact\Consumer\Exception\MissingEnvVariableException;
use PhpPact\Consumer\InteractionBuilder;
use PhpPact\Consumer\Model\ConsumerRequest;
use PhpPact\Consumer\Model\ProviderResponse;
Expand All @@ -10,6 +11,9 @@

class ConsumerServiceGoodbyeTest extends TestCase
{
/**
* @throws MissingEnvVariableException
*/
public function testGetGoodbyeString()
{
$request = new ConsumerRequest();
Expand Down
2 changes: 2 additions & 0 deletions example/tests/Consumer/Service/ConsumerServiceHelloTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ConsumerServiceHelloTest extends TestCase
{
/**
* Example PACT test.
*
* @throws \Exception
*/
public function testGetHelloString()
{
Expand Down
5 changes: 5 additions & 0 deletions example/tests/Provider/PactVerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Provider;

use GuzzleHttp\Psr7\Uri;
use PhpPact\Standalone\Installer\Exception\FileDownloadFailureException;
use PhpPact\Standalone\Installer\Exception\NoDownloaderFoundException;
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PhpPact\Standalone\ProviderVerifier\Verifier;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -37,6 +39,9 @@ protected function tearDown()

/**
* This test will run after the web server is started.
*
* @throws FileDownloadFailureException
* @throws NoDownloaderFoundException
*/
public function testPactVerifyConsumer()
{
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPact/Consumer/InteractionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(MockServerConfigInterface $config)
*/
public function given(string $description): InteractionBuilderInterface
{
$this->interaction->setDescription($description);
$this->interaction->setProviderState($description);

return $this;
}
Expand All @@ -51,7 +51,7 @@ public function given(string $description): InteractionBuilderInterface
*/
public function uponReceiving(string $providerState): InteractionBuilderInterface
{
$this->interaction->setProviderState($providerState);
$this->interaction->setDescription($providerState);

return $this;
}
Expand Down
5 changes: 5 additions & 0 deletions src/PhpPact/Consumer/Listener/PactTestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Psr7\Uri;
use PhpPact\Broker\Service\BrokerHttpClient;
use PhpPact\Consumer\Exception\MissingEnvVariableException;
use PhpPact\Http\GuzzleClient;
use PhpPact\Standalone\MockService\MockServer;
use PhpPact\Standalone\MockService\MockServerConfigInterface;
Expand Down Expand Up @@ -42,6 +43,8 @@ class PactTestListener implements TestListener
* PactTestListener constructor.
*
* @param string[] $testSuiteNames test suite names that need evaluated with the listener
*
* @throws MissingEnvVariableException
*/
public function __construct(array $testSuiteNames)
{
Expand All @@ -51,6 +54,8 @@ public function __construct(array $testSuiteNames)

/**
* @param TestSuite $suite
*
* @throws \Exception
*/
public function startTestSuite(TestSuite $suite)
{
Expand Down
8 changes: 6 additions & 2 deletions src/PhpPact/Consumer/Matcher/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ public function term($value, string $pattern): array
/**
* Alias for the term matcher.
*
* @param mixed $value example value
* @param string $pattern valid Ruby regex pattern
* @param $value
* @param string $pattern
*
* @throws \Exception
*
* @return array
*/
Expand All @@ -102,6 +104,8 @@ public function regex($value, string $pattern)
*
* @param string $value valid ISO8601 date, example: 2010-01-01
*
* @throws \Exception
*
* @return array
*/
public function dateISO8601(string $value): array
Expand Down
3 changes: 2 additions & 1 deletion src/PhpPact/Standalone/Installer/InstallManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public function setInstallers(array $installers): self
}

/**
* Install.
* @throws Exception\FileDownloadFailureException
* @throws NoDownloaderFoundException
*
* @return Scripts
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PhpPact\Standalone\Installer\Service;

use PhpPact\Standalone\Installer\Exception\FileDownloadFailureException;
use PhpPact\Standalone\Installer\Model\Scripts;

/**
Expand All @@ -21,6 +22,8 @@ public function isEligible(): bool;
*
* @param string $destinationDir folder path to put the binaries
*
* @throws FileDownloadFailureException
*
* @return Scripts
*/
public function install(string $destinationDir): Scripts;
Expand Down
7 changes: 4 additions & 3 deletions src/PhpPact/Standalone/Installer/Service/InstallerLinux.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class InstallerLinux implements InstallerInterface
{
const VERSION = '1.38.0';

/**
* @inheritDoc
*/
Expand All @@ -24,8 +26,7 @@ public function install(string $destinationDir): Scripts
$fs = new Filesystem();

if ($fs->exists($destinationDir . DIRECTORY_SEPARATOR . 'pact') === false) {
$version = '1.29.2';
$fileName = "pact-{$version}-linux-x86_64.tar.gz";
$fileName = 'pact-' . self::VERSION . '-linux-x86_64.tar.gz';
$tempFilePath = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;

$this
Expand Down Expand Up @@ -54,7 +55,7 @@ public function install(string $destinationDir): Scripts
*/
private function download(string $fileName, string $tempFilePath): self
{
$uri = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.29.2/{$fileName}";
$uri = 'https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v' . self::VERSION . "/{$fileName}";

$data = \file_get_contents($uri);

Expand Down
7 changes: 4 additions & 3 deletions src/PhpPact/Standalone/Installer/Service/InstallerMac.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class InstallerMac implements InstallerInterface
{
const VERSION = '1.38.0';

/**
* @inheritDoc
*/
Expand All @@ -24,8 +26,7 @@ public function install(string $destinationDir): Scripts
$fs = new Filesystem();

if ($fs->exists($destinationDir . DIRECTORY_SEPARATOR . 'pact') === false) {
$version = '1.29.2';
$fileName = "pact-{$version}-osx.tar.gz";
$fileName = 'pact-' . self::VERSION . '-osx.tar.gz';
$tempFilePath = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;

$this
Expand Down Expand Up @@ -54,7 +55,7 @@ public function install(string $destinationDir): Scripts
*/
private function download(string $fileName, string $tempFilePath): self
{
$uri = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.29.2/{$fileName}";
$uri = 'https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v' . self::VERSION . "/{$fileName}";

$data = \file_get_contents($uri);

Expand Down
7 changes: 4 additions & 3 deletions src/PhpPact/Standalone/Installer/Service/InstallerWindows.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class InstallerWindows implements InstallerInterface
{
const VERSION = '1.38.0';

/**
* @inheritDoc
*/
Expand All @@ -29,8 +31,7 @@ public function install(string $destinationDir): Scripts
$fs = new Filesystem();

if ($fs->exists($destinationDir . DIRECTORY_SEPARATOR . 'pact') === false) {
$version = '1.29.2';
$fileName = "pact-{$version}-win32.zip";
$fileName = 'pact-' . self::VERSION . '-win32.zip';
$tempFilePath = __DIR__ . DIRECTORY_SEPARATOR . $fileName;

$this
Expand Down Expand Up @@ -60,7 +61,7 @@ public function install(string $destinationDir): Scripts
*/
private function download(string $fileName, string $tempFilePath): self
{
$uri = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.29.2/{$fileName}";
$uri = 'https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v' . self::VERSION . "/{$fileName}";

$data = \file_get_contents($uri);

Expand Down
1 change: 1 addition & 0 deletions src/PhpPact/Standalone/MockService/MockServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct(MockServerConfigInterface $config)
* Start the Mock Server. Verify that it is running.
*
* @throws ProcessFailedException
* @throws Exception
*
* @return int process ID of the started Mock Server
*/
Expand Down
5 changes: 5 additions & 0 deletions src/PhpPact/Standalone/MockService/MockServerEnvConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
*/
class MockServerEnvConfig extends MockServerConfig
{
/**
* MockServerEnvConfig constructor.
*
* @throws MissingEnvVariableException
*/
public function __construct()
{
$this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PhpPact\Standalone\MockService\Service;

use PhpPact\Consumer\Model\Interaction;
use PhpPact\Exception\ConnectionException;

/**
* Interface MockServerHttpServiceInterface
Expand All @@ -12,6 +13,8 @@ interface MockServerHttpServiceInterface
/**
* Verify that the Ruby PhpPact Mock Server is running.
*
* @throws ConnectionException
*
* @return bool
*/
public function healthCheck(): bool;
Expand Down
21 changes: 19 additions & 2 deletions src/PhpPact/Standalone/ProviderVerifier/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use PhpPact\Broker\Service\BrokerHttpClient;
use PhpPact\Broker\Service\BrokerHttpClientInterface;
use PhpPact\Http\GuzzleClient;
use PhpPact\Standalone\Installer\Exception\FileDownloadFailureException;
use PhpPact\Standalone\Installer\Exception\NoDownloaderFoundException;
use PhpPact\Standalone\Installer\InstallManager;
use PhpPact\Standalone\Installer\Service\InstallerInterface;
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfigInterface;
Expand Down Expand Up @@ -90,7 +92,10 @@ public function getArguments(): array
* @param string $consumerName name of the consumer to be compared against
* @param null|string $tag optional tag of the consumer such as a branch name
*
* @return self
* @throws \PhpPact\Standalone\Installer\Exception\FileDownloadFailureException
* @throws \PhpPact\Standalone\Installer\Exception\NoDownloaderFoundException
*
* @return Verifier
*/
public function verify(string $consumerName, string $tag = null): self
{
Expand All @@ -115,7 +120,10 @@ public function verify(string $consumerName, string $tag = null): self
*
* @param array $files paths to pact json files
*
* @return self
* @throws FileDownloadFailureException
* @throws NoDownloaderFoundException
*
* @return Verifier
*/
public function verifyFiles(array $files): self
{
Expand All @@ -128,6 +136,9 @@ public function verifyFiles(array $files): self

/**
* Verify all Pacts from the Pact Broker are valid for the Provider.
*
* @throws FileDownloadFailureException
* @throws NoDownloaderFoundException
*/
public function verifyAll()
{
Expand All @@ -142,6 +153,9 @@ public function verifyAll()
* Verify all PACTs for a given tag.
*
* @param string $tag
*
* @throws FileDownloadFailureException
* @throws NoDownloaderFoundException
*/
public function verifyAllForTag(string $tag)
{
Expand Down Expand Up @@ -170,6 +184,9 @@ public function registerInstaller(InstallerInterface $installer): self
* Execute the Pact Verifier Service.
*
* @param array $arguments
*
* @throws \PhpPact\Standalone\Installer\Exception\FileDownloadFailureException
* @throws \PhpPact\Standalone\Installer\Exception\NoDownloaderFoundException
*/
private function verifyAction(array $arguments)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/PhpPact/Consumer/InteractionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class InteractionBuilderTest extends TestCase
/** @var MockServer */
private $mockServer;

/**
* @throws Exception\MissingEnvVariableException
* @throws \Exception
*/
protected function setUp()
{
$config = new MockServerEnvConfig();
Expand All @@ -33,6 +37,10 @@ protected function tearDown()
$this->mockServer->stop();
}

/**
* @throws Exception\MissingEnvVariableException
* @throws \Exception
*/
public function testSimpleGet()
{
$matcher = new Matcher();
Expand Down Expand Up @@ -62,6 +70,9 @@ public function testSimpleGet()
$this->assertTrue($result);
}

/**
* @throws Exception\MissingEnvVariableException
*/
public function testPostWithBody()
{
$request = new ConsumerRequest();
Expand Down Expand Up @@ -97,6 +108,9 @@ public function testPostWithBody()
$this->assertTrue($result);
}

/**
* @throws Exception\MissingEnvVariableException
*/
public function testBuildWithEachLikeMatcher()
{
$matcher = new Matcher();
Expand Down
Loading

0 comments on commit 60bb91b

Please sign in to comment.