diff --git a/composer.json b/composer.json index 2eb548d..fb19fc3 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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": { diff --git a/tests/Plugin/AddPathPluginTest.php b/tests/Plugin/AddPathPluginTest.php index 3980fa4..55081a8 100644 --- a/tests/Plugin/AddPathPluginTest.php +++ b/tests/Plugin/AddPathPluginTest.php @@ -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; @@ -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')); @@ -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); } @@ -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); } @@ -65,11 +70,15 @@ 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); } @@ -77,6 +86,8 @@ 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');