Skip to content

Commit 47948ad

Browse files
Yevhen Hrytsaimcustiel
authored andcommitted
Added method to fetch executed requests (#27)
1 parent 6afeb39 commit 47948ad

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Module/Phiremock.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ public function seeRemoteServiceReceived($times, RequestBuilder $builder)
9595
);
9696
}
9797
}
98+
99+
/**
100+
* @param RequestBuilder $builder
101+
*
102+
* @return array
103+
*/
104+
public function grabRequestsMadeToRemoteService(RequestBuilder $builder)
105+
{
106+
return $this->phiremock->listExecutions($builder);
107+
}
98108
}

tests/tests/acceptance/BasicTestCest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,32 @@ public function shouldCreateAnExpectationWithBinaryResponseTest(AcceptanceTester
9292
$responseBody = file_get_contents('http://localhost:18080/show-me-the-video');
9393
$I->assertEquals($responseContents, $responseBody);
9494
}
95+
96+
public function testGrabRequestsMadeToRemoteService(AcceptanceTester $I)
97+
{
98+
$requestBuilder = A::postRequest()->andUrl(Is::equalTo('/some/url'));
99+
$I->expectARequestToRemoteServiceWithAResponse(
100+
Phiremock::on($requestBuilder)->then(Respond::withStatusCode(200))
101+
);
102+
103+
$options = array(
104+
'http' => array(
105+
'header' => 'Content-Type: application/x-www-form-urlencoded',
106+
'method' => 'POST',
107+
'content' => http_build_query(['a' => 'b'])
108+
)
109+
);
110+
file_get_contents('http://localhost:18080/some/url', false, stream_context_create($options));
111+
112+
$requests = $I->grabRequestsMadeToRemoteService($requestBuilder);
113+
$I->assertCount(1, $requests);
114+
115+
$first = reset($requests);
116+
$I->assertEquals('POST', $first->method);
117+
$I->assertEquals('a=b', $first->body);
118+
$I->assertArraySubset([
119+
'Host' => ['localhost:18080'],
120+
'Content-Type' => ['application/x-www-form-urlencoded']
121+
], (array) $first->headers);
122+
}
95123
}

0 commit comments

Comments
 (0)