diff --git a/README.md b/README.md index 5af094e..1b56d67 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ For those running Behat within Docker, integrating a Wiremock container is strai } ``` -- **Given wiremock stubs from**: This step loads stubs from a specified file or directory and sends them to Wiremock. +- **Given wiremock stubs from {file}**: This step loads stubs from a specified file or directory and sends them to Wiremock. **Example**: ```gherkin @@ -75,27 +75,35 @@ For those running Behat within Docker, integrating a Wiremock container is strai And wiremock stubs from "dir2" ``` -- **Given wiremock stubs from and should be called exactly times**: This step loads stubs from a specified file or directory and sends them to Wiremock also gives you ability to verify that the stub is called exactly the specified number of times. +- **Given wiremock stubs from {file} should be called {count} times**: This step loads stubs from a specified file or directory, sends them to WireMock and also allows you to verify that the stub is called the specified number of times. **Example**: ```gherkin - Given wiremock stubs from "{filename}" and should be called exactly {count} times - And wiremock stubs from "dir2" + Given wiremock stubs from "dir/awesome-stub.json" should be called 2 times + And wiremock stubs from "dir2" should be called 2 times ``` -- **Given wiremock stubs from and should be called minimum times**: This step loads stubs from a specified file or directory and sends them to Wiremock also gives you ability to verify that the stub is called at least the specified number of times. +- **Given wiremock stubs from {file} should be called once**: This step loads stubs from a specified file or directory, sends them to WireMock and also allows you to verify that the stub is called once. **Example**: ```gherkin - Given wiremock stubs from "{filename}" and should be called minimum {count} times - And wiremock stubs from "dir2" + Given wiremock stubs from "dir/awesome-stub.json" should be called once + And wiremock stubs from "dir2" should be called once ``` -- **Given wiremock stubs from and should be called at most times**: This step loads stubs from a specified file or directory and sends them to Wiremock also gives you ability to verify that the stub is not called more than the specified number of times. + +- **Given wiremock stubs from {file} should be called at least {count} times**: This step loads stubs from a specified file or directory, sends them to WireMock and also allows you to verify that the stub is called at least the specified number of times. **Example**: ```gherkin - Given wiremock stubs from "{filename}" and should be called at most {count} times - And wiremock stubs from "dir2" + Given wiremock stubs from "dir/awesome-stub.json" should be called at least 2 times + And wiremock stubs from "dir2" should be called at least 2 times + ``` +- **Given wiremock stubs from {file} should be called at most {count} times**: This step loads stubs from a specified file or directory, sends them to WireMock and also allows you to verify that the stub is not called more than the specified number of times. + + **Example**: + ```gherkin + Given wiremock stubs from "dir/awesome-stub.json" and should be called at most 2 times + And wiremock stubs from "dir2" and should be called at most 2 times ``` ### Managing Wiremock State diff --git a/src/WiremockContext.php b/src/WiremockContext.php index b3353a6..179bbee 100644 --- a/src/WiremockContext.php +++ b/src/WiremockContext.php @@ -77,8 +77,8 @@ public function addWiremockStubFromFileStep(string $path): void /** * @throws WiremockContextException */ - #[Given('/^wiremock stubs from "([^"]+)" and should be called exactly (?P\d+) times$/')] - public function addWiremockStubFromFileShouldBeCalledExactlyStep(string $path, int $expectedCallCount): void + #[Given('/^wiremock stubs from "([^"]+)" should be called (?P\d+) times$/')] + public function addWiremockStubFromFileShouldBeCalledStep(string $path, int $expectedCallCount): void { $this->addWiremockStubFromFile($path, $expectedCallCount, self::STUB_MATCH_COUNT_STRATEGY_EXACT); } @@ -86,8 +86,17 @@ public function addWiremockStubFromFileShouldBeCalledExactlyStep(string $path, i /** * @throws WiremockContextException */ - #[Given('/^wiremock stubs from "([^"]+)" and should be called minimal (?P\d+) times$/')] - public function addWiremockStubFromFileShouldBeCalledMinimalStep(string $path, int $expectedCallCount): void + #[Given('/^wiremock stubs from "([^"]+)" should be called once')] + public function addWiremockStubFromFileShouldBeCalledOnceStep(string $path): void + { + $this->addWiremockStubFromFile($path, 1, self::STUB_MATCH_COUNT_STRATEGY_EXACT); + } + + /** + * @throws WiremockContextException + */ + #[Given('/^wiremock stubs from "([^"]+)" should be called at least (?P\d+) times$/')] + public function addWiremockStubFromFileShouldBeCalledAtLeastStep(string $path, int $expectedCallCount): void { $this->addWiremockStubFromFile($path, $expectedCallCount, self::STUB_MATCH_COUNT_STRATEGY_MIN); } @@ -95,7 +104,7 @@ public function addWiremockStubFromFileShouldBeCalledMinimalStep(string $path, i /** * @throws WiremockContextException */ - #[Given('/^wiremock stubs from "([^"]+)" and should be called at most (?P\d+) times$/')] + #[Given('/^wiremock stubs from "([^"]+)" should be called at most (?P\d+) times$/')] public function addWiremockStubFromFileShouldBeCalledAtMostStep(string $path, int $expectedCallCount): void { $this->addWiremockStubFromFile($path, $expectedCallCount, self::STUB_MATCH_COUNT_STRATEGY_MAX); @@ -381,7 +390,7 @@ private function checkRequestedStubsCallCounts(array $requestedStubsCallCounts): case self::STUB_MATCH_COUNT_STRATEGY_EXACT: if ($actualCount !== $expectedCount) { $errors[] = sprintf( - 'Stub with URL "%s" was expected to be called exactly %d time(s), but was called %d time(s)', + 'Stub with URL "%s" was expected to be called %d time(s), but was called %d time(s)', $url, $expectedCount, $actualCount @@ -401,7 +410,7 @@ private function checkRequestedStubsCallCounts(array $requestedStubsCallCounts): case self::STUB_MATCH_COUNT_STRATEGY_MIN: if ($actualCount < $expectedCount) { $errors[] = sprintf( - 'Stub with URL "%s" was expected to be called minimum %d time(s), but was called %d time(s)', + 'Stub with URL "%s" was expected to be called at least %d time(s), but was called %d time(s)', $url, $expectedCount, $actualCount diff --git a/tests/WiremockContextTest.php b/tests/WiremockContextTest.php index 466f671..52610ca 100644 --- a/tests/WiremockContextTest.php +++ b/tests/WiremockContextTest.php @@ -203,7 +203,7 @@ function ($method, $url) use ($addStubResponse, $matchedStubsResponse) { $stubBody = '{"request": {"method": "GET", "url": "/test"}, "response": {"status": 200, "body": "Success"}}'; $this->wiremockContext->addStub($stubBody, 1, 'exact'); $this->expectException(WiremockContextException::class); - $this->expectExceptionMessage('Stub with URL "/test" was expected to be called exactly 1 time(s), but was called 2 time(s)'); + $this->expectExceptionMessage('Stub with URL "/test" was expected to be called 1 time(s), but was called 2 time(s)'); $this->wiremockContext->allStubsMatchedStep(); } @@ -336,7 +336,7 @@ function ($method, $url) use ($addStubResponse, $matchedStubsResponse) { $stubBody = '{"request": {"method": "GET", "url": "/test"}, "response": {"status": 200, "body": "Success"}}'; $this->wiremockContext->addStub($stubBody, 3, 'min'); $this->expectException(WiremockContextException::class); - $this->expectExceptionMessage('Stub with URL "/test" was expected to be called minimum 3 time(s), but was called 2 time(s)'); + $this->expectExceptionMessage('Stub with URL "/test" was expected to be called at least 3 time(s), but was called 2 time(s)'); $this->wiremockContext->allStubsMatchedStep(); }