Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
saltandvinegarcrisps committed Mar 9, 2022
1 parent 6173709 commit 6c1e7d0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Simple http client, zero dependencies
# Simple http client

Example

```php
$client = new Codin\HttpClient\HttpClient();
Expand Down
60 changes: 60 additions & 0 deletions spec/RequestBuilderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
namespace spec\Codin\HttpClient;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument\Token\TypeToken;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UriInterface;
use Psr\Http\Message\StreamInterface;
use function json_encode;

class RequestBuilderSpec extends ObjectBehavior
{
Expand All @@ -20,4 +24,60 @@ public function it_should_build_requests(

$this->build('get', '/', [])->shouldReturn($request);
}

public function it_should_build_requests_with_options(
ServerRequestFactoryInterface $serverRequestFactory,
StreamFactoryInterface $streamFactory,
ServerRequestInterface $request,
UriInterface $uri,
StreamInterface $stream
) {
$this->beConstructedWith($serverRequestFactory, $streamFactory);

$serverRequestFactory->createServerRequest('GET', '/')->shouldBeCalled()->willReturn($request);

$request->withHeader('foo', 'bar')->shouldBeCalled()->willReturn($request);

$request->getUri()->shouldBeCalled()->willReturn($uri);

$uri->withQuery(http_build_query(['foo' => 'bar']))->shouldBeCalled()->willReturn($uri);

$request->withUri($uri)->shouldBeCalled()->willReturn($request);

$request->withBody($stream)->shouldBeCalled()->willReturn($request);

$streamFactory->createStream('foo')->shouldBeCalled()->willReturn($stream);

$streamFactory->createStream(json_encode(['foo' => 'bar']))->shouldBeCalled()->willReturn($stream);

$streamFactory->createStream(http_build_query(['foo' => 'bar']))->shouldBeCalled()->willReturn($stream);

$request->withHeader('Content-Type', 'application/x-www-form-urlencoded')->shouldBeCalled()->willReturn($request);

$request->withBody($stream)->shouldBeCalled()->willReturn($request);

$streamFactory->createStream('')->shouldBeCalled()->willReturn($stream);

$request->withHeader('Content-Type', new TypeToken('string'))->shouldBeCalled()->willReturn($request);

$this->build('get', '/', [
'headers' => [
'foo' => 'bar',
],
'query' => [
'foo' => 'bar',
],
'stream' => $stream,
'body' => 'foo',
'json' => [
'foo' => 'bar',
],
'form' => [
'foo' => 'bar',
],
'multipart' => [
'foo' => 'bar',
],
])->shouldReturn($request);
}
}

0 comments on commit 6c1e7d0

Please sign in to comment.