Skip to content

Commit 0b13c95

Browse files
committed
Add a test to verify seeMockRequestWasCalled happy path
1 parent 6c9cfb3 commit 0b13c95

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
bootstrap="vendor/autoload.php"
55
cacheResultFile="var/phpunit/test-results"
66
executionOrder="depends,defects"
7-
forceCoversAnnotation="true"
7+
forceCoversAnnotation="false"
88
beStrictAboutCoversAnnotation="true"
99
beStrictAboutOutputDuringTests="true"
1010
beStrictAboutTodoAnnotatedTests="true"

tests/Integration/SeeMockRequestWasCalledTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,35 @@
33
namespace Integration;
44

55
use DEVizzent\CodeceptionMockServerHelper\MockServerHelper;
6+
use GuzzleHttp\Client;
7+
use PHPUnit\Framework\ExpectationFailedException;
68
use PHPUnit\Framework\TestCase;
79

810
class SeeMockRequestWasCalledTest extends TestCase
911
{
1012
private MockServerHelper $sot;
13+
private Client $client;
1114

1215
protected function setUp(): void
1316
{
1417
parent::setUp();
1518
$this->sot = new MockServerHelper();
19+
$this->client = new Client(['proxy' => 'http://mockserver:1080', 'verify' => false]);
1620
}
1721

18-
public function testExpectationNotWasCalledThrowException(): void
22+
public function testExpectationWasCalledNotThrowException(): void
1923
{
20-
$this->sot->seeMockRequestWasCalled('some-expectation');
24+
$this->client->request('GET', 'https://jsonplaceholder.typicode.com/posts/1', []);
25+
$this->sot->seeMockRequestWasCalled('get-post-1');
26+
}
27+
28+
public function testExpectationNotWasCalledThrowException2(): void
29+
{
30+
$this->expectException(ExpectationFailedException::class);
31+
$this->expectExceptionMessage(
32+
'No expectation found with id not-existing-expectation' . PHP_EOL
33+
. 'Failed asserting that 400 matches expected 202.'
34+
);
35+
$this->sot->seeMockRequestWasCalled('not-existing-expectation');
2136
}
2237
}

0 commit comments

Comments
 (0)