diff --git a/README.md b/README.md index e67eacfd..39be9f71 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Table of contents * [Tips](#tips) * [Starting API Asynchronously](#starting-api-asynchronously) * [Set Up Provider State](#set-up-provider-state) - * + * [Examples](#additional-examples) ## Versions @@ -200,7 +200,7 @@ Create a single unit test function. This will test a single consumer of the serv ##### Start API -Get an instance of the API up and running. [Click here](#starting-your-api) for some tips. +Get an instance of the API up and running. [Click here](#starting-api-asynchronously) for some tips. If you need to set up the state of your API before making each request please see [Set Up Provider State](#set-up-provider-state). diff --git a/composer.json b/composer.json index 7779fb0e..530498d7 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ }, "require": { "php": "^7.0", + "ext-openssl": "*", "symfony/process": "^3.0", "symfony/filesystem": "^3.0", "guzzlehttp/guzzle": "^6.3", diff --git a/src/PhpPact/Broker/Service/BrokerHttpClient.php b/src/PhpPact/Broker/Service/BrokerHttpClient.php index 16a3ea88..c1afc1e1 100644 --- a/src/PhpPact/Broker/Service/BrokerHttpClient.php +++ b/src/PhpPact/Broker/Service/BrokerHttpClient.php @@ -66,7 +66,30 @@ public function tag(string $consumer, string $version, string $tag) */ public function getAllConsumerUrls(string $provider, string $version = 'latest'): array { - $uri = $this->baseUri->withPath("pacts/provider/{$provider}/latest"); + $uri = $this->baseUri->withPath("pacts/provider/{$provider}/{$version}"); + + $response = $this->httpClient->get($uri, [ + 'headers' => [ + 'Content-Type' => 'application/json' + ] + ]); + + $json = \json_decode($response->getBody()->getContents(), true); + + $urls = []; + foreach ($json['_links']['pacts'] as $pact) { + $urls[] = $pact['href']; + } + + return $urls; + } + + /** + * @inheritDoc + */ + public function getAllConsumerUrlsForTag(string $provider, string $tag): array + { + $uri = $this->baseUri->withPath("pacts/provider/{$provider}/latest/{$tag}"); $response = $this->httpClient->get($uri, [ 'headers' => [ diff --git a/src/PhpPact/Broker/Service/BrokerHttpClientInterface.php b/src/PhpPact/Broker/Service/BrokerHttpClientInterface.php index 6dc12b6d..783f70c9 100644 --- a/src/PhpPact/Broker/Service/BrokerHttpClientInterface.php +++ b/src/PhpPact/Broker/Service/BrokerHttpClientInterface.php @@ -47,4 +47,14 @@ public function tag(string $consumer, string $version, string $tag); * @return string[] */ public function getAllConsumerUrls(string $provider, string $version = 'latest'): array; + + /** + * Get all Pact URLs for a specific tag. + * + * @param string $provider + * @param string $tag + * + * @return array + */ + public function getAllConsumerUrlsForTag(string $provider, string $tag): array; } diff --git a/src/PhpPact/Standalone/Installer/Service/InstallerLinux.php b/src/PhpPact/Standalone/Installer/Service/InstallerLinux.php index 6a167338..f5cdf59a 100644 --- a/src/PhpPact/Standalone/Installer/Service/InstallerLinux.php +++ b/src/PhpPact/Standalone/Installer/Service/InstallerLinux.php @@ -24,7 +24,7 @@ public function install(string $destinationDir): Scripts $fs = new Filesystem(); if ($fs->exists($destinationDir . DIRECTORY_SEPARATOR . 'pact') === false) { - $version = '1.22.1'; + $version = '1.29.2'; $fileName = "pact-{$version}-linux-x86_64.tar.gz"; $tempFilePath = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; @@ -54,13 +54,18 @@ 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.22.1/{$fileName}"; + $uri = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.29.2/{$fileName}"; + $data = \file_get_contents($uri); + if ($data === false) { + throw new FileDownloadFailureException('Failed to download binary from Github for Ruby Standalone!'); + } + $result = \file_put_contents($tempFilePath, $data); if ($result === false) { - throw new FileDownloadFailureException('Failed to download file.'); + throw new FileDownloadFailureException('Failed to save binaries for Ruby Standalone!'); } return $this; diff --git a/src/PhpPact/Standalone/Installer/Service/InstallerMac.php b/src/PhpPact/Standalone/Installer/Service/InstallerMac.php index b1aee993..929379dc 100644 --- a/src/PhpPact/Standalone/Installer/Service/InstallerMac.php +++ b/src/PhpPact/Standalone/Installer/Service/InstallerMac.php @@ -24,7 +24,7 @@ public function install(string $destinationDir): Scripts $fs = new Filesystem(); if ($fs->exists($destinationDir . DIRECTORY_SEPARATOR . 'pact') === false) { - $version = '1.22.1'; + $version = '1.29.2'; $fileName = "pact-{$version}-osx.tar.gz"; $tempFilePath = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; @@ -54,13 +54,18 @@ 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.22.1/{$fileName}"; + $uri = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.29.2/{$fileName}"; + $data = \file_get_contents($uri); + if ($data === false) { + throw new FileDownloadFailureException('Failed to download binary from Github for Ruby Standalone!'); + } + $result = \file_put_contents($tempFilePath, $data); if ($result === false) { - throw new FileDownloadFailureException('Failed to download file.'); + throw new FileDownloadFailureException('Failed to save binaries for Ruby Standalone!'); } return $this; diff --git a/src/PhpPact/Standalone/Installer/Service/InstallerWindows.php b/src/PhpPact/Standalone/Installer/Service/InstallerWindows.php index ee6dca14..5f883e97 100644 --- a/src/PhpPact/Standalone/Installer/Service/InstallerWindows.php +++ b/src/PhpPact/Standalone/Installer/Service/InstallerWindows.php @@ -29,9 +29,9 @@ public function install(string $destinationDir): Scripts $fs = new Filesystem(); if ($fs->exists($destinationDir . DIRECTORY_SEPARATOR . 'pact') === false) { - $version = '1.22.1'; + $version = '1.29.2'; $fileName = "pact-{$version}-win32.zip"; - $tempFilePath = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; + $tempFilePath = __DIR__ . DIRECTORY_SEPARATOR . $fileName; $this ->download($fileName, $tempFilePath) @@ -41,7 +41,7 @@ public function install(string $destinationDir): Scripts $binDir = $destinationDir . DIRECTORY_SEPARATOR . 'pact' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR; $scripts = new Scripts( - $binDir . 'pact-mock-service.bat', + $binDir . 'pact-mock-service.bat', $binDir . 'pact-provider-verifier.bat' ); @@ -60,13 +60,18 @@ 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.22.1/{$fileName}"; + $uri = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.29.2/{$fileName}"; + $data = \file_get_contents($uri); + if ($data === false) { + throw new FileDownloadFailureException('Failed to download binary from Github for Ruby Standalone!'); + } + $result = \file_put_contents($tempFilePath, $data); if ($result === false) { - throw new FileDownloadFailureException('Failed to download file.'); + throw new FileDownloadFailureException('Failed to save binaries for Ruby Standalone!'); } return $this; diff --git a/src/PhpPact/Standalone/MockService/MockServerConfig.php b/src/PhpPact/Standalone/MockService/MockServerConfig.php index 82046d3f..9b5f93f5 100644 --- a/src/PhpPact/Standalone/MockService/MockServerConfig.php +++ b/src/PhpPact/Standalone/MockService/MockServerConfig.php @@ -104,6 +104,8 @@ public function getPort(): int */ public function setPort(int $port): MockServerConfigInterface { + $this->port = $port; + return $this; } diff --git a/src/PhpPact/Standalone/ProviderVerifier/Verifier.php b/src/PhpPact/Standalone/ProviderVerifier/Verifier.php index 88459cc3..1a43522b 100644 --- a/src/PhpPact/Standalone/ProviderVerifier/Verifier.php +++ b/src/PhpPact/Standalone/ProviderVerifier/Verifier.php @@ -138,6 +138,20 @@ public function verifyAll() $this->verifyAction($arguments); } + /** + * Verify all PACTs for a given tag. + * + * @param string $tag + */ + public function verifyAllForTag(string $tag) + { + $arguments = $this->getBrokerHttpClient()->getAllConsumerUrlsForTag($this->config->getProviderName(), $tag); + + $arguments = \array_merge($arguments, $this->getArguments()); + + $this->verifyAction($arguments); + } + /** * Wrapper to add a custom installer. *