diff --git a/.travis.yml b/.travis.yml index 84eac28..10d366e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,8 @@ jobs: env: DEPENDENCIES="dunglas/symfony-lock:^3" - php: 7.2 env: DEPENDENCIES="dunglas/symfony-lock:^4" + - php: 7.2 + env: TEST_COMMAND="./vendor/bin/phpunit" DEPENDENCIES="phpunit/phpunit:^7.5 nyholm/psr7:^1.0" # Latest dev release - php: 7.3 diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..d353b7c --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,14 @@ + + + + + + + ./tests + + + diff --git a/tests/PluginClientTest.php b/tests/PluginClientTest.php new file mode 100644 index 0000000..eb55685 --- /dev/null +++ b/tests/PluginClientTest.php @@ -0,0 +1,79 @@ +assertInstanceOf($returnType, $result); + } + + public function clientAndMethodProvider() + { + $syncClient = new class() implements ClientInterface { + public function sendRequest(RequestInterface $request): ResponseInterface + { + return new Response(); + } + }; + + $asyncClient = new class() implements HttpAsyncClient { + public function sendAsyncRequest(RequestInterface $request) + { + return new HttpFulfilledPromise(new Response()); + } + }; + + $headerAppendPlugin = new HeaderAppendPlugin(['Content-Type' => 'text/html']); + $redirectPlugin = new RedirectPlugin(); + $restartOncePlugin = new class() implements Plugin { + private $firstRun = true; + + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise + { + if ($this->firstRun) { + $this->firstRun = false; + + return $first($request); + } + $this->firstRun = true; + + return $next($request); + } + }; + + $plugins = [$headerAppendPlugin, $restartOncePlugin, $redirectPlugin]; + + $pluginClient = new PluginClient($syncClient, $plugins); + yield [$pluginClient, 'sendRequest', ResponseInterface::class]; + yield [$pluginClient, 'sendAsyncRequest', Promise::class]; + + // Async + $pluginClient = new PluginClient($asyncClient, $plugins); + yield [$pluginClient, 'sendRequest', ResponseInterface::class]; + yield [$pluginClient, 'sendAsyncRequest', Promise::class]; + } +}