Skip to content

Commit 03086a2

Browse files
authored
Merge pull request #183 from Headd2k/phpunit
adds phpunit as dev dependency
2 parents 0e6a80e + e7a93b8 commit 03086a2

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

composer.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
"require-dev": {
2121
"doctrine/instantiator": "^1.1",
2222
"guzzlehttp/psr7": "^1.4",
23+
"nyholm/psr7": "^1.2",
2324
"phpspec/phpspec": "^5.1 || ^6.0",
2425
"phpspec/prophecy": "^1.8",
26+
"phpunit/phpunit": "^7.5",
2527
"sebastian/comparator": "^3.0"
2628
},
2729
"suggest": {
@@ -42,8 +44,17 @@
4244
}
4345
},
4446
"scripts": {
45-
"test": "vendor/bin/phpspec run",
46-
"test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml"
47+
"test": [
48+
"vendor/bin/phpspec run",
49+
"vendor/bin/phpunit"
50+
],
51+
"test-ci": [
52+
"vendor/bin/phpspec run -c phpspec.ci.yml",
53+
"vendor/bin/phpunit"
54+
]
55+
},
56+
"config": {
57+
"sort-packages": true
4758
},
4859
"extra": {
4960
"branch-alias": {

tests/Plugin/AddPathPluginTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
use Http\Client\Common\Plugin;
66
use Http\Client\Common\Plugin\AddPathPlugin;
7-
use Http\Client\Common\PluginClient;
8-
use Http\Client\HttpClient;
7+
use Http\Client\Promise\HttpFulfilledPromise;
98
use Nyholm\Psr7\Request;
109
use Nyholm\Psr7\Response;
1110
use Nyholm\Psr7\Uri;
@@ -24,7 +23,7 @@ class AddPathPluginTest extends TestCase
2423
*/
2524
private $first;
2625

27-
protected function setUp()
26+
protected function setUp(): void
2827
{
2928
$this->first = function () {};
3029
$this->plugin = new AddPathPlugin(new Uri('/api'));
@@ -34,16 +33,18 @@ public function testRewriteSameUrl()
3433
{
3534
$verify = function (RequestInterface $request) {
3635
$this->assertEquals('https://example.com/api/foo', $request->getUri()->__toString());
36+
37+
return new HttpFulfilledPromise(new Response());
3738
};
3839

39-
$request = new Request('GET', 'https://example.com/foo', ['Content-Type'=>'text/html']);
40+
$request = new Request('GET', 'https://example.com/foo', ['Content-Type' => 'text/html']);
4041
$this->plugin->handleRequest($request, $verify, $this->first);
4142

4243
// Make a second call with the same $request object
4344
$this->plugin->handleRequest($request, $verify, $this->first);
4445

4546
// Make a new call with a new object but same URL
46-
$request = new Request('GET', 'https://example.com/foo', ['Content-Type'=>'text/plain']);
47+
$request = new Request('GET', 'https://example.com/foo', ['Content-Type' => 'text/plain']);
4748
$this->plugin->handleRequest($request, $verify, $this->first);
4849
}
4950

@@ -56,7 +57,11 @@ public function testRewriteCallingThePluginTwice()
5657
// Run the plugin again with the modified request
5758
$this->plugin->handleRequest($request, function (RequestInterface $request) {
5859
$this->assertEquals('https://example.com/api/foo', $request->getUri()->__toString());
60+
61+
return new HttpFulfilledPromise(new Response());
5962
}, $this->first);
63+
64+
return new HttpFulfilledPromise(new Response());
6065
}, $this->first);
6166
}
6267

@@ -65,18 +70,24 @@ public function testRewriteWithDifferentUrl()
6570
$request = new Request('GET', 'https://example.com/foo');
6671
$this->plugin->handleRequest($request, function (RequestInterface $request) {
6772
$this->assertEquals('https://example.com/api/foo', $request->getUri()->__toString());
73+
74+
return new HttpFulfilledPromise(new Response());
6875
}, $this->first);
6976

7077
$request = new Request('GET', 'https://example.com/bar');
7178
$this->plugin->handleRequest($request, function (RequestInterface $request) {
7279
$this->assertEquals('https://example.com/api/bar', $request->getUri()->__toString());
80+
81+
return new HttpFulfilledPromise(new Response());
7382
}, $this->first);
7483
}
7584

7685
public function testRewriteWhenPathIsIncluded()
7786
{
7887
$verify = function (RequestInterface $request) {
7988
$this->assertEquals('https://example.com/api/foo', $request->getUri()->__toString());
89+
90+
return new HttpFulfilledPromise(new Response());
8091
};
8192

8293
$request = new Request('GET', 'https://example.com/api/foo');

0 commit comments

Comments
 (0)