Skip to content

Commit ce1471b

Browse files
committed
FEATURE: Added testcase for mixed cassettes
(with and without legacy entries)
1 parent ad35687 commit ce1471b

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

tests/Unit/CassetteTest.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public function testHasResponseFound(): void
7070
public function testPlaybackOfIdenticalRequestsFromLegacyCassette(): void
7171
{
7272
$request1 = new Request('GET', 'https://example.com');
73-
$response1 = new Response(200, [], 'response1');
73+
$response1 = new Response('200', [], 'response1');
7474

7575
$request2 = new Request('GET', 'https://example.com');
76-
$response2 = new Response(200, [], 'response2');
76+
$response2 = new Response('200', [], 'response2');
7777

7878
// These are legacy recordings with no index keys.
7979
$recordings = [
@@ -94,17 +94,48 @@ public function testPlaybackOfIdenticalRequestsFromLegacyCassette(): void
9494
}
9595

9696
/**
97-
* Ensure that if a second identical request is played back from an cassette
97+
* Ensure also mixed cassettes are working properly, if a legacy cassette has a first entry without index (should be
98+
* 0) and a second entry for the same request with incremented index (should be 1).
99+
*/
100+
public function testPlaybackOfIdenticalRequestsFromLegacyCassetteWithIndexedRecords(): void
101+
{
102+
$request1 = new Request('GET', 'https://example.com');
103+
$response1 = new Response('200', [], 'response1');
104+
105+
$request2 = new Request('GET', 'https://example.com');
106+
$response2 = new Response('200', [], 'response2');
107+
108+
// These are legacy recordings with no index keys.
109+
$recordings = [
110+
[
111+
'request' => $request1->toArray(),
112+
'response' => $response1->toArray(),
113+
],
114+
[
115+
'request' => $request2->toArray(),
116+
'response' => $response2->toArray(),
117+
'index' => 1,
118+
],
119+
];
120+
121+
$cassette = $this->createCassetteWithRecordings($recordings);
122+
123+
$this->assertEquals($response1->toArray(), $cassette->playback($request1, 0)->toArray());
124+
$this->assertEquals($response2->toArray(), $cassette->playback($request2, 1)->toArray());
125+
}
126+
127+
/**
128+
* Ensure that if a second identical request is played back from a cassette
98129
* with indexed recordings, the response corresponding to the recording
99130
* index will be returned.
100131
*/
101132
public function testPlaybackOfIdenticalRequests(): void
102133
{
103134
$request1 = new Request('GET', 'https://example.com');
104-
$response1 = new Response(200, [], 'response1');
135+
$response1 = new Response('200', [], 'response1');
105136

106137
$request2 = new Request('GET', 'https://example.com');
107-
$response2 = new Response(200, [], 'response2');
138+
$response2 = new Response('200', [], 'response2');
108139

109140
// These are recordings with index keys which support playback of
110141
// multiple identical requests.

0 commit comments

Comments
 (0)