Skip to content

Commit 126e8b3

Browse files
committed
Add reset logs verb and a test to check was called exact times
1 parent 281886d commit 126e8b3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/MockServerHelper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,15 @@ public function seeMockRequestWasNotCalled(string $expectationId): void
3636
$this->seeMockRequestWasCalled($expectationId, 0);
3737
}
3838

39+
public function resetMockServerLogs()
40+
{
41+
$request = new Request('PUT', '/mockserver/clear?type=log');
42+
$response = $this->mockserverClient->sendRequest($request);
43+
Assert::assertEquals(
44+
200,
45+
$response->getStatusCode(),
46+
$response->getBody()->getContents()
47+
);
48+
49+
}
3950
}

tests/Integration/SeeMockRequestWasCalledTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ protected function setUp(): void
1717
parent::setUp();
1818
$this->sot = new MockServerHelper();
1919
$this->client = new Client(['proxy' => 'http://mockserver:1080', 'verify' => false]);
20+
$this->sot->resetMockServerLogs();
2021
}
2122

2223
public function testExpectationWasCalled(): void
@@ -25,6 +26,13 @@ public function testExpectationWasCalled(): void
2526
$this->sot->seeMockRequestWasCalled('get-post-1');
2627
}
2728

29+
public function testExpectationWasCalledExact(): void
30+
{
31+
$this->client->request('GET', 'https://jsonplaceholder.typicode.com/posts/1');
32+
$this->client->request('GET', 'https://jsonplaceholder.typicode.com/posts/1');
33+
$this->sot->seeMockRequestWasCalled('get-post-1', 2);
34+
}
35+
2836
public function testExpectationNotWasCalledThrowException2(): void
2937
{
3038
$this->expectException(ExpectationFailedException::class);

0 commit comments

Comments
 (0)