diff --git a/README.md b/README.md index ace66aed..16b7bf7f 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ All of the following code will be used exclusively for the Consumer. This library contains a wrapper for the [Ruby Standalone Mock Service](https://github.com/pact-foundation/pact-mock_service). -The easiest way to configure this is to use a [PHPUnit Listener](https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.test-listeners). A default listener is included in this project, see [PactTestListener.php](/src/PhpPact/Consumer/Listener/PactTestListener.php). This utilizes environmental variables for configurations. These env variables can either be added to the system or to the phpunit.xml configuration file. Here is an example [phpunit.xml](/example/phpunit.consumer.xml) file configured to use the default. Keep in mind that both the test suite and the arguments array must be the same value. +The easiest way to configure this is to use a [PHPUnit Extension](https://phpunit.readthedocs.io/en/7.1/configuration.html#registering-testrunner-extensionsl). A default extension is included in this project, see [PactExtension.php](src/PhpPact/Consumer/Hook/PactExtension.php). This utilizes environmental variables for configurations. These env variables can either be added to the system or to the phpunit.xml configuration file. Here is an example [phpunit.xml](example/phpunit.consumer.xml) file configured to use the default. Keep in mind that both the test suite and the arguments array must be the same value. Alternatively, you can start and stop as in whatever means you would like by following this example: @@ -103,7 +103,7 @@ Alternatively, you can start and stop as in whatever means you would like by fol Create a standard PHPUnit test case class and function. -[Click here](/example/tests/Consumer/Service/ConsumerServiceHelloTest.php) to see the full sample file. +[Click here](example/tests/Consumer/Service/ConsumerServiceHelloTest.php) to see the full sample file. ### Create Mock Request @@ -124,28 +124,24 @@ You can also create a body just like you will see in the provider example. This will define what the response from the provider should look like. ```php -$matcher = new Matcher(); - $response = new ProviderResponse(); $response ->setStatus(200) ->addHeader('Content-Type', 'application/json') ->setBody([ - 'message' => $matcher->regex('Hello, Bob', '(Hello, )[A-Za-z]') + 'message' => Match::regex('Hello, Bob', '(Hello, )[A-Za-z]') ]); ``` In this example, we are using matchers. This allows us to add flexible rules when matching the expectation with the actual value. In the example, you will see regex is used to validate that the response is valid. ```php -$matcher = new Matcher(); - $response = new ProviderResponse(); $response ->setStatus(200) ->addHeader('Content-Type', 'application/json') ->setBody([ - 'list' => $matcher->eachLike([ + 'list' => Match::eachLike([ 'firstName' => 'Bob', 'age' => 22 ]) @@ -154,23 +150,23 @@ $response Matcher | Explanation | Parameters | Example ---|---|---|--- -term | Match a value against a regex pattern. | Value, Regex Pattern | $matcher->term('Hello, Bob', '(Hello, )[A-Za-z]') -regex | Alias to term matcher. | Value, Regex Pattern | $matcher->regex('Hello, Bob', '(Hello, )[A-Za-z]') -dateISO8601 | Regex match a date using the ISO8601 format. | Value (Defaults to 2010-01-01) | $matcher->dateISO8601('2010-01-01') -timeISO8601 | Regex match a time using the ISO8601 format. | Value (Defaults to T22:44:30.652Z) | $matcher->timeISO8601('T22:44:30.652Z') -dateTimeISO8601 | Regex match a datetime using the ISO8601 format. | Value (Defaults to 2015-08-06T16:53:10+01:00) | $matcher->dateTimeISO8601('2015-08-06T16:53:10+01:00') -dateTimeWithMillisISO8601 | Regex match a datetime with millis using the ISO8601 format. | Value (Defaults to 2015-08-06T16:53:10.123+01:00) | $matcher->dateTimeWithMillisISO8601('2015-08-06T16:53:10.123+01:00') -timestampRFC3339 | Regex match a timestamp using the RFC3339 format. | Value (Defaults to Mon, 31 Oct 2016 15:21:41 -0400) | $matcher->timestampRFC3339('Mon, 31 Oct 2016 15:21:41 -0400') -like | Match a value against its data type. | Value | $matcher->like(12) -somethingLike | Alias to like matcher. | Value | $matcher->somethingLike(12) -eachLike | Match on an object like the example. | Value, Min (Defaults to 1) | $matcher->eachLike(12) -boolean | Match against boolean true. | none | $matcher->boolean() -integer | Match a value against integer. | Value (Defaults to 13) | $matcher->integer() -decimal | Match a value against float. | Value (Defaults to 13.01) | $matcher->decimal() -hexadecimal | Regex to match a hexadecimal number. Example: 3F | Value (Defaults to 3F) | $matcher->hexadecimal('FF') -uuid | Regex to match a uuid. | Value (Defaults to ce118b6e-d8e1-11e7-9296-cec278b6b50a) | $matcher->uuid('ce118b6e-d8e1-11e7-9296-cec278b6b50a') -ipv4Address | Regex to match a ipv4 address. | Value (Defaults to 127.0.0.13) | $matcher->ipv4Address('127.0.0.1') -ipv6Address | Regex to match a ipv6 address. | Value (Defaults to ::ffff:192.0.2.128) | $matcher->ipv6Address('::ffff:192.0.2.1') +term | Match a value against a regex pattern. | Value, Regex Pattern | Match::term('Hello, Bob', '(Hello, )[A-Za-z]') +regex | Alias to term matcher. | Value, Regex Pattern | Match::regex('Hello, Bob', '(Hello, )[A-Za-z]') +dateISO8601 | Regex match a date using the ISO8601 format. | Value (Defaults to 2010-01-01) | Match::dateISO8601('2010-01-01') +timeISO8601 | Regex match a time using the ISO8601 format. | Value (Defaults to T22:44:30.652Z) | Match::timeISO8601('T22:44:30.652Z') +dateTimeISO8601 | Regex match a datetime using the ISO8601 format. | Value (Defaults to 2015-08-06T16:53:10+01:00) | Match::dateTimeISO8601('2015-08-06T16:53:10+01:00') +dateTimeWithMillisISO8601 | Regex match a datetime with millis using the ISO8601 format. | Value (Defaults to 2015-08-06T16:53:10.123+01:00) | Match::dateTimeWithMillisISO8601('2015-08-06T16:53:10.123+01:00') +timestampRFC3339 | Regex match a timestamp using the RFC3339 format. | Value (Defaults to Mon, 31 Oct 2016 15:21:41 -0400) | Match::timestampRFC3339('Mon, 31 Oct 2016 15:21:41 -0400') +like | Match a value against its data type. | Value | Match::like(12) +somethingLike | Alias to like matcher. | Value | Match::somethingLike(12) +eachLike | Match on an object like the example. | Value, Min (Defaults to 1) | Match::eachLike(12) +boolean | Match against boolean true. | none | Match::boolean() +integer | Match a value against integer. | Value (Defaults to 13) | Match::integer() +decimal | Match a value against float. | Value (Defaults to 13.01) | Match::decimal() +hexadecimal | Regex to match a hexadecimal number. Example: 3F | Value (Defaults to 3F) | Match::hexadecimal('FF') +uuid | Regex to match a uuid. | Value (Defaults to ce118b6e-d8e1-11e7-9296-cec278b6b50a) | Match::uuid('ce118b6e-d8e1-11e7-9296-cec278b6b50a') +ipv4Address | Regex to match a ipv4 address. | Value (Defaults to 127.0.0.13) | Match::ipv4Address('127.0.0.1') +ipv6Address | Regex to match a ipv6 address. | Value (Defaults to ::ffff:192.0.2.128) | Match::ipv6Address('::ffff:192.0.2.1') ### Build the Interaction diff --git a/example/phpunit.consumer.xml b/example/phpunit.consumer.xml index 6e88b251..893df3cb 100644 --- a/example/phpunit.consumer.xml +++ b/example/phpunit.consumer.xml @@ -5,17 +5,9 @@ ./tests/Consumer - - - - - - PhpPact Example Tests - - - - - + + + diff --git a/src/PhpPact/Consumer/Hook/PactExtension.php b/src/PhpPact/Consumer/Hook/PactExtension.php new file mode 100644 index 00000000..c758d2d7 --- /dev/null +++ b/src/PhpPact/Consumer/Hook/PactExtension.php @@ -0,0 +1,120 @@ +mockServerConfig = new MockServerEnvConfig(); + } + + public function executeBeforeFirstTest(): void + { + $this->server = new MockServer($this->mockServerConfig); + $this->server->start(); + } + + public function executeAfterTestFailure(string $test, string $message, float $time): void + { + $this->failed = true; + } + + public function executeAfterLastTest(): void + { + try { + $httpService = new MockServerHttpService(new GuzzleClient(), $this->mockServerConfig); + $httpService->verifyInteractions(); + + $pact = $httpService->getPactJson(); + } catch (ServerException $exception) { + print $exception->getResponse()->getBody()->getContents(); + exit(1); + } catch (Throwable $throwable) { + print $throwable->getMessage(); + exit(1); + } finally { + $this->server->stop(); + } + + $this->uploadPact($pact); + } + + protected function uploadPact(string $pact): void + { + if ($this->failed === true) { + print 'A unit test has failed. Skipping PACT file upload.'; + return; + } + + if (!($pactBrokerUri = getenv('PACT_BROKER_URI'))) { + print 'PACT_BROKER_URI environment variable was not set. Skipping PACT file upload.'; + return; + } + + if (!($consumerVersion = getenv('PACT_CONSUMER_VERSION'))) { + print 'PACT_CONSUMER_VERSION environment variable was not set. Skipping PACT file upload.'; + return; + } + + if (!($tag = getenv('PACT_CONSUMER_TAG'))) { + print 'PACT_CONSUMER_TAG environment variable was not set. Skipping PACT file upload.'; + return; + } + + $clientConfig = []; + if (($user = getenv('PACT_BROKER_HTTP_AUTH_USER')) && + ($pass = getenv('PACT_BROKER_HTTP_AUTH_PASS')) + ) { + $clientConfig = [ + 'auth' => [$user, $pass], + ]; + } + + if (($sslVerify = getenv('PACT_BROKER_SSL_VERIFY'))) { + $clientConfig['verify'] = $sslVerify !== 'no'; + } + + $headers = []; + if ($bearerToken = getenv('PACT_BROKER_BEARER_TOKEN')) { + $headers['Authorization'] = 'Bearer ' . $bearerToken; + } + + $client = new GuzzleClient($clientConfig); + + $brokerHttpService = new BrokerHttpClient($client, new Uri($pactBrokerUri), $headers); + $brokerHttpService->tag($this->mockServerConfig->getConsumer(), $consumerVersion, $tag); + $brokerHttpService->publishJson($pact, $consumerVersion); + + print 'Pact file has been uploaded to the Broker successfully.'; + } +} diff --git a/src/PhpPact/Consumer/InteractionBuilder.php b/src/PhpPact/Consumer/InteractionBuilder.php index 93ec41d6..14bb3cac 100644 --- a/src/PhpPact/Consumer/InteractionBuilder.php +++ b/src/PhpPact/Consumer/InteractionBuilder.php @@ -36,6 +36,7 @@ public function __construct(MockServerConfigInterface $config) } /** + * @deprecated use register instead * @param string $providerState what is given to the request * * @return InteractionBuilder @@ -48,6 +49,7 @@ public function given(string $providerState): self } /** + * @deprecated use register instead * @param string $description what is received when the request is made * * @return InteractionBuilder @@ -60,6 +62,7 @@ public function uponReceiving(string $description): self } /** + * @deprecated use register instead * @param ConsumerRequest $request mock of request sent * * @return InteractionBuilder @@ -72,6 +75,7 @@ public function with(ConsumerRequest $request): self } /** + * @deprecated use register instead * Make the http request to the Mock Service to register the interaction. * * @param ProviderResponse $response mock of response received @@ -85,6 +89,15 @@ public function willRespondWith(ProviderResponse $response): bool return $this->mockServerHttpService->registerInteraction($this->interaction); } + /** + * Make the http request to the Mock Service to register the interaction. + * @return bool returns true on success + */ + public function register(Interaction $interaction): bool + { + return $this->mockServerHttpService->registerInteraction($interaction); + } + /** * {@inheritdoc} */ diff --git a/src/PhpPact/Consumer/Listener/PactTestListener.php b/src/PhpPact/Consumer/Listener/PactTestListener.php index 5e393992..7f336c12 100644 --- a/src/PhpPact/Consumer/Listener/PactTestListener.php +++ b/src/PhpPact/Consumer/Listener/PactTestListener.php @@ -2,6 +2,7 @@ namespace PhpPact\Consumer\Listener; +use GuzzleHttp\Exception\ServerException; use GuzzleHttp\Psr7\Uri; use PhpPact\Broker\Service\BrokerHttpClient; use PhpPact\Http\GuzzleClient; @@ -15,8 +16,10 @@ use PHPUnit\Framework\TestListener; use PHPUnit\Framework\TestListenerDefaultImplementation; use PHPUnit\Framework\TestSuite; +use Throwable; /** + * @deprecated use PhpPact\Consumer\Hook\PactExtension instead, PHPunit deprecated the use of listeners * PACT listener that can be used with environment variables and easily attached to PHPUnit configuration. * Class PactTestListener */ @@ -89,6 +92,12 @@ public function endTestSuite(TestSuite $suite): void $httpService->verifyInteractions(); $json = $httpService->getPactJson(); + } catch (ServerException $exception) { + print $exception->getResponse()->getBody()->getContents(); + exit(1); + } catch (Throwable $throwable) { + print $throwable->getMessage(); + exit(1); } finally { $this->server->stop(); } diff --git a/src/PhpPact/Consumer/Matcher/Match.php b/src/PhpPact/Consumer/Matcher/Match.php new file mode 100644 index 00000000..c7bde57e --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Match.php @@ -0,0 +1,273 @@ + $value, + 'json_class' => 'Pact::SomethingLike', + ]; + } + + /** + * Expect an array of similar data as the value passed in. + * + * @param mixed $value example of what the expected data would be + * @param int $min minimum number of objects to verify against + * + * @return array + */ + public static function eachLike($value, int $min = 1): array + { + $result = [ + 'contents' => $value, + 'json_class' => 'Pact::ArrayLike', + ]; + + $result['min'] = $min; + + return $result; + } + + /** + * Validate that a value will match a regex pattern. + * + * @param mixed $value example of what the expected data would be + * @param string $pattern valid Ruby regex pattern + * + * @throws \Exception + * + * @return array + */ + public static function term($value, string $pattern): array + { + $result = \preg_match("/$pattern/", $value); + + if ($result === false || $result === 0) { + $errorCode = \preg_last_error(); + + throw new \Exception("The pattern {$pattern} is not valid for value {$value}. Failed with error code {$errorCode}."); + } + + return [ + 'data' => [ + 'generate' => $value, + 'matcher' => [ + 'json_class' => 'Regexp', + 'o' => 0, + 's' => $pattern, + ], + ], + 'json_class' => 'Pact::Term', + ]; + } + + /** + * Alias for the term matcher. + * + * @param $value + * @param string $pattern + * + * @throws \Exception + * + * @return array + */ + public static function regex($value, string $pattern) + { + return self::term($value, $pattern); + } + + /** + * ISO8601 date format wrapper for the term matcher. + * + * @param string $value valid ISO8601 date, example: 2010-01-01 + * + * @throws \Exception + * + * @return array + */ + public static function dateISO8601(string $value = '2013-02-01'): array + { + return self::term($value, self::ISO8601_DATE_FORMAT); + } + + /** + * ISO8601 Time Matcher, matches a pattern of the format "'T'HH:mm:ss". + * + * @param string $value + * + * @throws \Exception + * + * @return array + */ + public static function timeISO8601(string $value = 'T22:44:30.652Z'): array + { + return self::term($value, self::ISO8601_TIME_FORMAT); + } + + /** + * ISO8601 DateTime matcher. + * + * @param string $value + * + * @throws \Exception + * + * @return array + */ + public static function dateTimeISO8601(string $value = '2015-08-06T16:53:10+01:00'): array + { + return self::term($value, self::ISO8601_DATETIME_FORMAT); + } + + /** + * ISO8601 DateTime matcher with required millisecond precision. + * + * @param string $value + * + * @throws \Exception + * + * @return array + */ + public static function dateTimeWithMillisISO8601(string $value = '2015-08-06T16:53:10.123+01:00'): array + { + return self::term($value, self::ISO8601_DATETIME_WITH_MILLIS_FORMAT); + } + + /** + * RFC3339 Timestamp matcher, a subset of ISO8609. + * + * @param string $value + * + * @throws \Exception + * + * @return array + */ + public static function timestampRFC3339(string $value = 'Mon, 31 Oct 2016 15:21:41 -0400'): array + { + return self::term($value, self::RFC3339_TIMESTAMP_FORMAT); + } + + /** + * @throws \Exception + * + * @return array + */ + public static function boolean(): array + { + return self::like(true); + } + + /** + * @param int $int + * + * @throws \Exception + * + * @return array + */ + public static function integer(int $int = 13): array + { + return self::like($int); + } + + /** + * @param float $float + * + * @throws \Exception + * + * @return array + */ + public static function decimal(float $float = 13.01): array + { + return self::like($float); + } + + /** + * @param string $hex + * + * @throws \Exception + * + * @return array + */ + public static function hexadecimal(string $hex = '3F'): array + { + return self::term($hex, self::HEX_FORMAT); + } + + /** + * @param string $uuid + * + * @throws \Exception + * + * @return array + */ + public static function uuid(string $uuid = 'ce118b6e-d8e1-11e7-9296-cec278b6b50a'): array + { + return self::term($uuid, self::UUID_V4_FORMAT); + } + + /** + * @param string $ip + * + * @throws \Exception + * + * @return array + */ + public static function ipv4Address(string $ip = '127.0.0.13'): array + { + return self::term($ip, self::IPV4_FORMAT); + } + + /** + * @param string $ip + * + * @throws \Exception + * + * @return array + */ + public static function ipv6Address(string $ip = '::ffff:192.0.2.128'): array + { + return self::term($ip, self::IPV6_FORMAT); + } +} diff --git a/src/PhpPact/Consumer/Matcher/Matcher.php b/src/PhpPact/Consumer/Matcher/Matcher.php index 7b8f3e93..c273ba02 100644 --- a/src/PhpPact/Consumer/Matcher/Matcher.php +++ b/src/PhpPact/Consumer/Matcher/Matcher.php @@ -3,21 +3,10 @@ namespace PhpPact\Consumer\Matcher; /** - * Matcher implementation. Builds the Ruby Mock Server specification json for interaction publishing. - * Class Matcher. + * @deprecated use Match instead */ class Matcher { - const ISO8601_DATE_FORMAT = '^([\\+-]?\\d{4}(?!\\d{2}\\b))((-?)((0[1-9]|1[0-2])(\\3([12]\\d|0[1-9]|3[01]))?|W([0-4]\\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\\d|[12]\\d{2}|3([0-5]\\d|6[1-6])))?)$'; - const ISO8601_DATETIME_FORMAT = '^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d([+-][0-2]\\d:[0-5]\\d|Z)$'; - const ISO8601_DATETIME_WITH_MILLIS_FORMAT = '^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d{3}([+-][0-2]\\d:[0-5]\\d|Z)$'; - const ISO8601_TIME_FORMAT = '^(T\\d\\d:\\d\\d(:\\d\\d)?(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?)?$'; - const RFC3339_TIMESTAMP_FORMAT = '^(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\\s\\d{2}\\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}\\s(\\+|-)\\d{4}$'; - const UUID_V4_FORMAT = '^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$'; - const IPV4_FORMAT = '^(\\d{1,3}\\.)+\\d{1,3}$'; - const IPV6_FORMAT = '^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$'; - const HEX_FORMAT = '^[0-9a-fA-F]+$'; - /** * Alias for the `like()` function. * @@ -29,7 +18,7 @@ class Matcher */ public function somethingLike($value): array { - return $this->like($value); + return Match::like($value); } /** @@ -41,14 +30,7 @@ public function somethingLike($value): array */ public function like($value): array { - if ($value === null) { - throw new \Exception('Value must not be null.'); - } - - return [ - 'contents' => $value, - 'json_class' => 'Pact::SomethingLike', - ]; + return Match::like($value); } /** @@ -61,14 +43,7 @@ public function like($value): array */ public function eachLike($value, int $min = 1): array { - $result = [ - 'contents' => $value, - 'json_class' => 'Pact::ArrayLike', - ]; - - $result['min'] = $min; - - return $result; + return Match::eachLike($value, $min); } /** @@ -83,25 +58,7 @@ public function eachLike($value, int $min = 1): array */ public function term($value, string $pattern): array { - $result = \preg_match("/$pattern/", $value); - - if ($result === false || $result === 0) { - $errorCode = \preg_last_error(); - - throw new \Exception("The pattern {$pattern} is not valid for value {$value}. Failed with error code {$errorCode}."); - } - - return [ - 'data' => [ - 'generate' => $value, - 'matcher' => [ - 'json_class' => 'Regexp', - 'o' => 0, - 's' => $pattern, - ], - ], - 'json_class' => 'Pact::Term', - ]; + return Match::term($value, $pattern); } /** @@ -116,7 +73,7 @@ public function term($value, string $pattern): array */ public function regex($value, string $pattern) { - return $this->term($value, $pattern); + return Match::term($value, $pattern); } /** @@ -130,7 +87,7 @@ public function regex($value, string $pattern) */ public function dateISO8601(string $value = '2013-02-01'): array { - return $this->term($value, self::ISO8601_DATE_FORMAT); + return Match::term($value, Match::ISO8601_DATE_FORMAT); } /** @@ -144,7 +101,7 @@ public function dateISO8601(string $value = '2013-02-01'): array */ public function timeISO8601(string $value = 'T22:44:30.652Z'): array { - return $this->term($value, self::ISO8601_TIME_FORMAT); + return Match::term($value, Match::ISO8601_TIME_FORMAT); } /** @@ -158,7 +115,7 @@ public function timeISO8601(string $value = 'T22:44:30.652Z'): array */ public function dateTimeISO8601(string $value = '2015-08-06T16:53:10+01:00'): array { - return $this->term($value, self::ISO8601_DATETIME_FORMAT); + return Match::term($value, Match::ISO8601_DATETIME_FORMAT); } /** @@ -172,7 +129,7 @@ public function dateTimeISO8601(string $value = '2015-08-06T16:53:10+01:00'): ar */ public function dateTimeWithMillisISO8601(string $value = '2015-08-06T16:53:10.123+01:00'): array { - return $this->term($value, self::ISO8601_DATETIME_WITH_MILLIS_FORMAT); + return Match::term($value, Match::ISO8601_DATETIME_WITH_MILLIS_FORMAT); } /** @@ -186,7 +143,7 @@ public function dateTimeWithMillisISO8601(string $value = '2015-08-06T16:53:10.1 */ public function timestampRFC3339(string $value = 'Mon, 31 Oct 2016 15:21:41 -0400'): array { - return $this->term($value, self::RFC3339_TIMESTAMP_FORMAT); + return Match::term($value, Match::RFC3339_TIMESTAMP_FORMAT); } /** @@ -196,7 +153,7 @@ public function timestampRFC3339(string $value = 'Mon, 31 Oct 2016 15:21:41 -040 */ public function boolean(): array { - return $this->like(true); + return Match::like(true); } /** @@ -208,7 +165,7 @@ public function boolean(): array */ public function integer(int $int = 13): array { - return $this->like($int); + return Match::like($int); } /** @@ -220,7 +177,7 @@ public function integer(int $int = 13): array */ public function decimal(float $float = 13.01): array { - return $this->like($float); + return Match::like($float); } /** @@ -232,7 +189,7 @@ public function decimal(float $float = 13.01): array */ public function hexadecimal(string $hex = '3F'): array { - return $this->term($hex, self::HEX_FORMAT); + return Match::term($hex, Match::HEX_FORMAT); } /** @@ -244,7 +201,7 @@ public function hexadecimal(string $hex = '3F'): array */ public function uuid(string $uuid = 'ce118b6e-d8e1-11e7-9296-cec278b6b50a'): array { - return $this->term($uuid, self::UUID_V4_FORMAT); + return Match::term($uuid, Match::UUID_V4_FORMAT); } /** @@ -256,7 +213,7 @@ public function uuid(string $uuid = 'ce118b6e-d8e1-11e7-9296-cec278b6b50a'): arr */ public function ipv4Address(string $ip = '127.0.0.13'): array { - return $this->term($ip, self::IPV4_FORMAT); + return Match::term($ip, Match::IPV4_FORMAT); } /** @@ -268,6 +225,6 @@ public function ipv4Address(string $ip = '127.0.0.13'): array */ public function ipv6Address(string $ip = '::ffff:192.0.2.128'): array { - return $this->term($ip, self::IPV6_FORMAT); + return Match::term($ip, Match::IPV6_FORMAT); } } diff --git a/src/PhpPact/Consumer/Model/ConsumerRequest.php b/src/PhpPact/Consumer/Model/ConsumerRequest.php index 1270f027..05323861 100644 --- a/src/PhpPact/Consumer/Model/ConsumerRequest.php +++ b/src/PhpPact/Consumer/Model/ConsumerRequest.php @@ -33,6 +33,16 @@ class ConsumerRequest implements \JsonSerializable */ private $query; + /** + * @param string|null $method should not be nullable + * @param string|null $path + */ + public function __construct(string $method = null, string $path = null) + { + $this->method = $method; + $this->path = $path; + } + /** * @return string */ diff --git a/src/PhpPact/Consumer/Model/Interaction.php b/src/PhpPact/Consumer/Model/Interaction.php index 438e1057..5e31fa95 100644 --- a/src/PhpPact/Consumer/Model/Interaction.php +++ b/src/PhpPact/Consumer/Model/Interaction.php @@ -28,6 +28,24 @@ class Interaction implements \JsonSerializable */ private $response; + /** + * @param string|null $description should not be nullable + * @param ConsumerRequest|null $request should not be nullable + * @param ProviderResponse|null $response should not be nullable + * @param string|null $providerState + */ + public function __construct( + string $description = null, + ConsumerRequest $request = null, + ProviderResponse $response = null, + string $providerState = null + ) { + $this->description = $description; + $this->request = $request; + $this->response = $response; + $this->providerState = $providerState; + } + /** * @return string */ diff --git a/src/PhpPact/Consumer/Model/ProviderResponse.php b/src/PhpPact/Consumer/Model/ProviderResponse.php index f53222a3..1d251f8e 100644 --- a/src/PhpPact/Consumer/Model/ProviderResponse.php +++ b/src/PhpPact/Consumer/Model/ProviderResponse.php @@ -23,6 +23,14 @@ class ProviderResponse implements \JsonSerializable */ private $body; + /** + * @param int|null $status should not be nullable + */ + public function __construct(int $status = null) + { + $this->status = $status; + } + /** * @return int */