Skip to content

adds phpunit as dev dependency #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
"require-dev": {
"doctrine/instantiator": "^1.1",
"guzzlehttp/psr7": "^1.4",
"nyholm/psr7": "^1.2",
"phpspec/phpspec": "^5.1 || ^6.0",
"phpspec/prophecy": "^1.8",
"phpunit/phpunit": "^7.5",
"sebastian/comparator": "^3.0"
},
"suggest": {
Expand All @@ -42,8 +44,17 @@
}
},
"scripts": {
"test": "vendor/bin/phpspec run",
"test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml"
"test": [
"vendor/bin/phpspec run",
"vendor/bin/phpunit"
],
"test-ci": [
"vendor/bin/phpspec run -c phpspec.ci.yml",
"vendor/bin/phpunit"
]
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
Expand Down
21 changes: 16 additions & 5 deletions tests/Plugin/AddPathPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use Http\Client\Common\Plugin;
use Http\Client\Common\Plugin\AddPathPlugin;
use Http\Client\Common\PluginClient;
use Http\Client\HttpClient;
use Http\Client\Promise\HttpFulfilledPromise;
use Nyholm\Psr7\Request;
use Nyholm\Psr7\Response;
use Nyholm\Psr7\Uri;
Expand All @@ -24,7 +23,7 @@ class AddPathPluginTest extends TestCase
*/
private $first;

protected function setUp()
protected function setUp(): void
{
$this->first = function () {};
$this->plugin = new AddPathPlugin(new Uri('/api'));
Expand All @@ -34,16 +33,18 @@ public function testRewriteSameUrl()
{
$verify = function (RequestInterface $request) {
$this->assertEquals('https://example.com/api/foo', $request->getUri()->__toString());

return new HttpFulfilledPromise(new Response());
};

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

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

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

Expand All @@ -56,7 +57,11 @@ public function testRewriteCallingThePluginTwice()
// Run the plugin again with the modified request
$this->plugin->handleRequest($request, function (RequestInterface $request) {
$this->assertEquals('https://example.com/api/foo', $request->getUri()->__toString());

return new HttpFulfilledPromise(new Response());
}, $this->first);

return new HttpFulfilledPromise(new Response());
}, $this->first);
}

Expand All @@ -65,18 +70,24 @@ public function testRewriteWithDifferentUrl()
$request = new Request('GET', 'https://example.com/foo');
$this->plugin->handleRequest($request, function (RequestInterface $request) {
$this->assertEquals('https://example.com/api/foo', $request->getUri()->__toString());

return new HttpFulfilledPromise(new Response());
}, $this->first);

$request = new Request('GET', 'https://example.com/bar');
$this->plugin->handleRequest($request, function (RequestInterface $request) {
$this->assertEquals('https://example.com/api/bar', $request->getUri()->__toString());

return new HttpFulfilledPromise(new Response());
}, $this->first);
}

public function testRewriteWhenPathIsIncluded()
{
$verify = function (RequestInterface $request) {
$this->assertEquals('https://example.com/api/foo', $request->getUri()->__toString());

return new HttpFulfilledPromise(new Response());
};

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