Skip to content

Commit 790c12e

Browse files
author
Márk Sági-Kazár
committed
Update dependencies, remove puli requirement, add unit tests
1 parent 1e36afb commit 790c12e

File tree

5 files changed

+101
-10
lines changed

5 files changed

+101
-10
lines changed

Diff for: CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Change Log
22

33

4+
## 0.3.0 - 2016-02-26
5+
6+
### Added
7+
8+
- Support for custom MessageFactory
9+
10+
### Changed
11+
12+
- Updated dependencies
13+
14+
415
## 0.2.0 - 2016-02-01
516

617
### Changed

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015 PHP HTTP Team <[email protected]>
1+
Copyright (c) 2015-2016 PHP HTTP Team <[email protected]>
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Diff for: composer.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"php": ">=5.4",
1515
"php-http/httplug": "^1.0",
1616
"php-http/client-common": "^1.0",
17-
"php-http/discovery": "^0.7"
17+
"php-http/discovery": "^0.8",
18+
"php-http/message-factory": "^1.0"
1819
},
1920
"require-dev": {
2021
"phpspec/phpspec": "^2.4",
@@ -34,9 +35,7 @@
3435
},
3536
"extra": {
3637
"branch-alias": {
37-
"dev-master": "0.1-dev"
38+
"dev-master": "0.4-dev"
3839
}
39-
},
40-
"prefer-stable": true,
41-
"minimum-stability": "beta"
40+
}
4241
}

Diff for: spec/ClientSpec.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace spec\Http\Mock;
4+
5+
use Http\Message\ResponseFactory;
6+
use Psr\Http\Message\RequestInterface;
7+
use Psr\Http\Message\ResponseInterface;
8+
use PhpSpec\ObjectBehavior;
9+
10+
class ClientSpec extends ObjectBehavior
11+
{
12+
function let(ResponseFactory $responseFactory)
13+
{
14+
$this->beConstructedWith($responseFactory);
15+
}
16+
17+
function it_is_initializable()
18+
{
19+
$this->shouldHaveType('Http\Mock\Client');
20+
}
21+
22+
function it_is_an_http_client()
23+
{
24+
$this->shouldImplement('Http\Client\HttpClient');
25+
}
26+
27+
function it_is_an_async_http_client()
28+
{
29+
$this->shouldImplement('Http\Client\HttpAsyncClient');
30+
}
31+
32+
function it_returns_a_response_for_a_request(RequestInterface $request, ResponseInterface $response)
33+
{
34+
$this->addResponse($response);
35+
36+
$this->sendRequest($request)->shouldReturn($response);
37+
}
38+
39+
function it_throws_an_exception_for_a_request(RequestInterface $request)
40+
{
41+
$this->addException(new \Exception());
42+
43+
$this->shouldThrow('Exception')->duringSendRequest($request);
44+
}
45+
46+
function it_creates_an_empty_response_when_none_is_added(
47+
RequestInterface $request,
48+
ResponseFactory $responseFactory,
49+
ResponseInterface $response
50+
) {
51+
$responseFactory->createResponse()->willReturn($response);
52+
53+
$this->sendRequest($request)->shouldReturn($response);
54+
}
55+
}

Diff for: src/Client.php

+30-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace Http\Mock;
44

55
use Http\Client\Common\HttpAsyncClientEmulator;
6+
use Http\Client\Exception;
67
use Http\Client\HttpAsyncClient;
78
use Http\Client\HttpClient;
89
use Http\Discovery\MessageFactoryDiscovery;
10+
use Http\Message\ResponseFactory;
911
use Psr\Http\Message\RequestInterface;
1012
use Psr\Http\Message\ResponseInterface;
1113

@@ -22,10 +24,34 @@ class Client implements HttpClient, HttpAsyncClient
2224
{
2325
use HttpAsyncClientEmulator;
2426

27+
/**
28+
* @var ResponseFactory
29+
*/
30+
private $responseFactory;
31+
32+
/**
33+
* @var RequestInterface[]
34+
*/
2535
private $requests = [];
36+
37+
/**
38+
* @var ResponseInterface[]
39+
*/
2640
private $responses = [];
41+
42+
/**
43+
* @var Exception[]
44+
*/
2745
private $exceptions = [];
2846

47+
/**
48+
* @param ResponseFactory|null $responseFactory
49+
*/
50+
public function __construct(ResponseFactory $responseFactory = null)
51+
{
52+
$this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find();
53+
}
54+
2955
/**
3056
* {@inheritdoc}
3157
*/
@@ -42,11 +68,11 @@ public function sendRequest(RequestInterface $request)
4268
}
4369

4470
// Return success response by default
45-
return MessageFactoryDiscovery::find()->createResponse();
71+
return $this->responseFactory->createResponse();
4672
}
4773

4874
/**
49-
* Add exception that will be thrown.
75+
* Adds an exception that will be thrown.
5076
*
5177
* @param \Exception $exception
5278
*/
@@ -56,7 +82,7 @@ public function addException(\Exception $exception)
5682
}
5783

5884
/**
59-
* Add response that will be returned.
85+
* Adds a response that will be returned.
6086
*
6187
* @param ResponseInterface $response
6288
*/
@@ -66,7 +92,7 @@ public function addResponse(ResponseInterface $response)
6692
}
6793

6894
/**
69-
* Get requests that were sent.
95+
* Returns requests that were sent.
7096
*
7197
* @return RequestInterface[]
7298
*/

0 commit comments

Comments
 (0)