php - GuzzlePHP mock response content -
i want mock response guzzle request:
$response = new response(200, ['x-foo' => 'bar']); //how set content of $response to--> "some mocked content" $client = mockery::mock('guzzlehttp\client'); $client->shouldreceive('get')->once()->andreturn($response);
i noticed need add third parameter interface:
guzzlehttp\stream\streaminterface
but there many implementations of it, , want return simple string. ideas?
edit: use this:
$response = new response(200, [], guzzlehttp\stream\stream::factory('bad xml here'));
but when check this:
$response->getbody()->getcontents()
i empty string. why this?
edit 2: happened me when used xdebug, when runs works great!
the previous answer guzzle 3. guzzle 5 uses following:
<?php $body = guzzlehttp\stream\stream::factory('some mocked content'); $response = new response(200, ['x-foo' => 'bar'], $body);
Comments
Post a Comment