From 84e7017543863a3e3d7b4c6f3f2ddc97f43222d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Wed, 26 Dec 2018 17:22:05 +0300 Subject: [PATCH 1/3] #41: Support PSR-18 --- composer.json | 19 +- phpunit.xml.dist | 39 +++- src/Client.php | 65 ++++--- src/MultiRunner.php | 10 +- src/PromiseCore.php | 20 +- src/ResponseBuilder.php | 2 +- tests/BaseUnitTestCase.php | 68 ------- tests/CurlPromiseTest.php | 74 -------- .../HttpAsyncClientDiactorosTest.php | 26 +++ .../HttpAsyncClientGuzzleTest.php | 10 +- tests/Functional/HttpAsyncClientTestCase.php | 63 +++++++ .../HttpClientDiactorosTest.php | 28 +-- .../{ => Functional}/HttpClientGuzzleTest.php | 2 +- tests/{ => Functional}/HttpClientTestCase.php | 116 ++++++------ tests/HttpAsyncClientDiactorosTest.php | 24 --- tests/HttpAsyncClientTestCase.php | 65 ------- tests/PromiseCoreTest.php | 166 ----------------- tests/{ => Unit}/ClientTest.php | 39 ++-- tests/Unit/CurlPromiseTest.php | 86 +++++++++ tests/Unit/PromiseCoreTest.php | 176 ++++++++++++++++++ 20 files changed, 543 insertions(+), 555 deletions(-) delete mode 100644 tests/BaseUnitTestCase.php delete mode 100644 tests/CurlPromiseTest.php create mode 100644 tests/Functional/HttpAsyncClientDiactorosTest.php rename tests/{ => Functional}/HttpAsyncClientGuzzleTest.php (63%) create mode 100644 tests/Functional/HttpAsyncClientTestCase.php rename tests/{ => Functional}/HttpClientDiactorosTest.php (52%) rename tests/{ => Functional}/HttpClientGuzzleTest.php (94%) rename tests/{ => Functional}/HttpClientTestCase.php (69%) delete mode 100644 tests/HttpAsyncClientDiactorosTest.php delete mode 100644 tests/HttpAsyncClientTestCase.php delete mode 100644 tests/PromiseCoreTest.php rename tests/{ => Unit}/ClientTest.php (77%) create mode 100644 tests/Unit/CurlPromiseTest.php create mode 100644 tests/Unit/PromiseCoreTest.php diff --git a/composer.json b/composer.json index 8c9b395..5b0a0e2 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,12 @@ { "name": "php-http/curl-client", - "description": "cURL client for PHP-HTTP", + "description": "PSR-18 cURL client", "license": "MIT", - "keywords": ["http", "curl"], + "keywords": [ + "curl", + "http", + "psr-18" + ], "homepage": "http://php-http.org", "authors": [ { @@ -12,23 +16,20 @@ ], "prefer-stable": true, "minimum-stability": "dev", - "config": { - "bin-dir": "vendor/bin" - }, "require": { "php": "^7.1", "ext-curl": "*", - "php-http/httplug": "^2.0", - "php-http/message-factory": "^1.0.2", - "php-http/message": "^1.2", "php-http/discovery": "^1.0", + "php-http/httplug": "^2.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", "symfony/options-resolver": "^3.4 || ^4.0" }, "require-dev": { "guzzlehttp/psr7": "^1.0", "php-http/client-integration-tests": "dev-master", "phpunit/phpunit": "^7.5", - "zendframework/zend-diactoros": "^1.0" + "zendframework/zend-diactoros": "^2.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c6643dc..3f3b615 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,41 @@ - + + + + + + + - - tests/ + + + tests + + tests/Functional/HttpAsyncClientGuzzleTest.php + tests/Functional/HttpClientGuzzleTest.php + + + + tests/Unit + + + tests/Functional + + tests/Functional/HttpAsyncClientGuzzleTest.php + tests/Functional/HttpClientGuzzleTest.php + + - - - + - src/ + src + diff --git a/src/Client.php b/src/Client.php index 2e8705d..5b19bd1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,5 +1,7 @@ messageFactory = $messageFactory ?: MessageFactoryDiscovery::find(); - $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); + $this->responseFactory = $responseFactory; // FIXME ?: MessageFactoryDiscovery::find(); + $this->streamFactory = $streamFactory; // FIXME ?: StreamFactoryDiscovery::find(); $resolver = new OptionsResolver(); - $resolver->setDefaults([ - CURLOPT_HEADER => false, - CURLOPT_RETURNTRANSFER => false, - CURLOPT_FOLLOWLOCATION => false, - ]); + $resolver->setDefaults( + [ + CURLOPT_HEADER => false, + CURLOPT_RETURNTRANSFER => false, + CURLOPT_FOLLOWLOCATION => false, + ] + ); $resolver->setAllowedValues(CURLOPT_HEADER, [false]); // our parsing will fail if this is set to true $resolver->setAllowedValues(CURLOPT_RETURNTRANSFER, [false]); // our parsing will fail if this is set to true @@ -105,7 +113,7 @@ public function __destruct() } /** - * Sends a PSR-7 request. + * Sends a PSR-7 request and returns a PSR-7 response. * * @param RequestInterface $request * @@ -363,17 +371,14 @@ private function createHeaders(RequestInterface $request, array $options): array * Create new ResponseBuilder instance. * * @return ResponseBuilder - * - * @throws \RuntimeException If creating the stream from $body fails */ private function createResponseBuilder(): ResponseBuilder { - try { - $body = $this->streamFactory->createStream(fopen('php://temp', 'w+b')); - } catch (\InvalidArgumentException $e) { - throw new \RuntimeException('Can not create "php://temp" stream.'); - } - $response = $this->messageFactory->createResponse(200, null, [], $body); + $body = $this->streamFactory->createStreamFromFile('php://temp', 'w+b'); + + $response = $this->responseFactory + ->createResponse(200) + ->withBody($body); return new ResponseBuilder($response); } diff --git a/src/MultiRunner.php b/src/MultiRunner.php index 4c60587..7a2c50c 100644 --- a/src/MultiRunner.php +++ b/src/MultiRunner.php @@ -19,7 +19,7 @@ class MultiRunner * * @var resource|null */ - private $multiHandle = null; + private $multiHandle; /** * Awaiting cores. @@ -43,7 +43,7 @@ public function __destruct() * * @param PromiseCore $core */ - public function add(PromiseCore $core) + public function add(PromiseCore $core): void { foreach ($this->cores as $existed) { if ($existed === $core) { @@ -64,7 +64,7 @@ public function add(PromiseCore $core) * * @param PromiseCore $core */ - public function remove(PromiseCore $core) + public function remove(PromiseCore $core): void { foreach ($this->cores as $index => $existed) { if ($existed === $core) { @@ -81,7 +81,7 @@ public function remove(PromiseCore $core) * * @param PromiseCore|null $targetCore */ - public function wait(PromiseCore $targetCore = null) + public function wait(PromiseCore $targetCore = null): void { do { $status = curl_multi_exec($this->multiHandle, $active); @@ -118,7 +118,7 @@ public function wait(PromiseCore $targetCore = null) * * @return PromiseCore|null */ - private function findCoreByHandle($handle) + private function findCoreByHandle($handle): ?PromiseCore { foreach ($this->cores as $core) { if ($core->getHandle() === $handle) { diff --git a/src/PromiseCore.php b/src/PromiseCore.php index 72a733e..2b0256d 100644 --- a/src/PromiseCore.php +++ b/src/PromiseCore.php @@ -109,7 +109,7 @@ public function __construct( * * @param callable $callback */ - public function addOnFulfilled(callable $callback) + public function addOnFulfilled(callable $callback): void { if ($this->getState() === Promise::PENDING) { $this->onFulfilled[] = $callback; @@ -126,7 +126,7 @@ public function addOnFulfilled(callable $callback) * * @param callable $callback */ - public function addOnRejected(callable $callback) + public function addOnRejected(callable $callback): void { if ($this->getState() === Promise::PENDING) { $this->onRejected[] = $callback; @@ -150,7 +150,7 @@ public function getHandle() * * @return string */ - public function getState() + public function getState(): string { return $this->state; } @@ -160,7 +160,7 @@ public function getState() * * @return RequestInterface */ - public function getRequest() + public function getRequest(): RequestInterface { return $this->request; } @@ -168,9 +168,9 @@ public function getRequest() /** * Return the value of the promise (fulfilled). * - * @return ResponseInterface Response Object only when the Promise is fulfilled + * @return ResponseInterface Response object only when the Promise is fulfilled */ - public function getResponse() + public function getResponse(): ResponseInterface { return $this->responseBuilder->getResponse(); } @@ -181,11 +181,11 @@ public function getResponse() * If the exception is an instance of Http\Client\Exception\HttpException it will contain * the response object with the status code and the http reason. * - * @return Exception Exception Object only when the Promise is rejected + * @return \Throwable Exception Object only when the Promise is rejected * * @throws \LogicException When the promise is not rejected */ - public function getException() + public function getException(): \Throwable { if (null === $this->exception) { throw new \LogicException('Promise is not rejected'); @@ -197,7 +197,7 @@ public function getException() /** * Fulfill promise. */ - public function fulfill() + public function fulfill(): void { $this->state = Promise::FULFILLED; $response = $this->responseBuilder->getResponse(); @@ -225,7 +225,7 @@ public function fulfill() * * @param Exception $exception Reject reason */ - public function reject(Exception $exception) + public function reject(Exception $exception): void { $this->exception = $exception; $this->state = Promise::REJECTED; diff --git a/src/ResponseBuilder.php b/src/ResponseBuilder.php index 8d98819..c7250e7 100644 --- a/src/ResponseBuilder.php +++ b/src/ResponseBuilder.php @@ -17,7 +17,7 @@ class ResponseBuilder extends OriginalResponseBuilder * * @param ResponseInterface $response */ - public function setResponse(ResponseInterface $response) + public function setResponse(ResponseInterface $response): void { $this->response = $response; } diff --git a/tests/BaseUnitTestCase.php b/tests/BaseUnitTestCase.php deleted file mode 100644 index 1557431..0000000 --- a/tests/BaseUnitTestCase.php +++ /dev/null @@ -1,68 +0,0 @@ -handle)) { - curl_close($this->handle); - } - } - - /** - * Create new request. - * - * @param string $method - * @param mixed $uri - * - * @return RequestInterface - */ - protected function createRequest($method, $uri) - { - return MessageFactoryDiscovery::find()->createRequest($method, $uri); - } - - /** - * Create new response. - * - * @return ResponseInterface - */ - protected function createResponse() - { - return MessageFactoryDiscovery::find()->createResponse(); - } - - /** - * Create PromiseCore mock. - * - * @return PromiseCore|\PHPUnit_Framework_MockObject_MockObject - */ - protected function createPromiseCore() - { - return $this->getMockBuilder(PromiseCore::class)->disableOriginalConstructor()->getMock(); - } -} diff --git a/tests/CurlPromiseTest.php b/tests/CurlPromiseTest.php deleted file mode 100644 index 5c4ddf8..0000000 --- a/tests/CurlPromiseTest.php +++ /dev/null @@ -1,74 +0,0 @@ -createPromiseCore(); - $runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor() - ->setMethods(['wait'])->getMock(); - /** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */ - $promise = new CurlPromise($core, $runner); - - $onFulfill = function () { - }; - $core->expects(static::once())->method('addOnFulfilled')->with($onFulfill); - $onReject = function () { - }; - $core->expects(static::once())->method('addOnRejected')->with($onReject); - $value = $promise->then($onFulfill, $onReject); - static::assertInstanceOf(Promise::class, $value); - - $core->expects(static::once())->method('getState')->willReturn('STATE'); - static::assertEquals('STATE', $promise->getState()); - } - - public function testCoreCallWaitFulfilled() - { - $core = $this->createPromiseCore(); - $runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor() - ->setMethods(['wait'])->getMock(); - /** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */ - $promise = new CurlPromise($core, $runner); - - $runner->expects(static::once())->method('wait')->with($core); - $core->expects(static::once())->method('getState')->willReturn(Promise::FULFILLED); - $core->expects(static::once())->method('getResponse')->willReturn('RESPONSE'); - static::assertEquals('RESPONSE', $promise->wait()); - } - - public function testCoreCallWaitRejected() - { - $core = $this->createPromiseCore(); - $runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()->getMock(); - /** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */ - $promise = new CurlPromise($core, $runner); - - $runner->expects(static::once())->method('wait')->with($core); - $core->expects(static::once())->method('getState')->willReturn(Promise::REJECTED); - $core->expects(static::once())->method('getException')->willReturn(new TransferException()); - - try { - $promise->wait(); - } catch (TransferException $exception) { - static::assertTrue(true); - } - } -} diff --git a/tests/Functional/HttpAsyncClientDiactorosTest.php b/tests/Functional/HttpAsyncClientDiactorosTest.php new file mode 100644 index 0000000..273ea0f --- /dev/null +++ b/tests/Functional/HttpAsyncClientDiactorosTest.php @@ -0,0 +1,26 @@ +createTempFile(); $fd = fopen($filename, 'ab'); @@ -99,16 +55,53 @@ public function testSendLargeFile() } /** - * Create temp file. + * TODO Summary. * - * @return string Filename + * @param string $method HTTP method. + * @param string $uri Request URI. + * @param array $headers HTTP headers. + * @param string $body Request body. + * + * @dataProvider requestProvider */ - protected function createTempFile() + public function testSendRequest($method, $uri, array $headers, $body): void { - $filename = tempnam(sys_get_temp_dir(), 'tests'); - $this->tmpFiles[] = $filename; + if ($body !== null && in_array($method, ['GET', 'HEAD', 'TRACE'], true)) { + self::markTestSkipped('cURL can not send body using '.$method); + } + parent::testSendRequest( + $method, + $uri, + $headers, + $body + ); + } - return $filename; + /** + * TODO Summary. + * + * @param array $uriAndOutcome TODO ??? + * @param string $protocolVersion HTTP version. + * @param array $headers HTTP headers. + * @param string $body Request body. + * + * @dataProvider requestWithOutcomeProvider + */ + public function testSendRequestWithOutcome( + $uriAndOutcome, + $protocolVersion, + array $headers, + $body + ): void { + if ($body !== null) { + self::markTestSkipped('cURL can not send body using GET'); + } + parent::testSendRequestWithOutcome( + $uriAndOutcome, + $protocolVersion, + $headers, + $body + ); } /** @@ -118,7 +111,20 @@ protected function createTempFile() * * @return StreamInterface */ - abstract protected function createFileStream($filename); + abstract protected function createFileStream($filename): StreamInterface; + + /** + * Create temporary file. + * + * @return string Filename + */ + protected function createTempFile(): string + { + $filename = tempnam(sys_get_temp_dir(), 'tests'); + $this->tmpFiles[] = $filename; + + return $filename; + } /** * Tears down the fixture. diff --git a/tests/HttpAsyncClientDiactorosTest.php b/tests/HttpAsyncClientDiactorosTest.php deleted file mode 100644 index e94cbb0..0000000 --- a/tests/HttpAsyncClientDiactorosTest.php +++ /dev/null @@ -1,24 +0,0 @@ -expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, NULL given'); - - new PromiseCore( - $this->createRequest('GET', '/'), - null, - new ResponseBuilder($this->createResponse()) - ); - } - - /** - * Testing if handle is not a cURL resource. - */ - public function testHandleIsNotACurlResource() - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, stream resource given'); - - new PromiseCore( - $this->createRequest('GET', '/'), - fopen('php://memory', 'r+b'), - new ResponseBuilder($this->createResponse()) - ); - } - - /** - * Test on fulfill actions. - */ - public function testOnFulfill() - { - $request = $this->createRequest('GET', '/'); - $this->handle = curl_init(); - - $core = new PromiseCore( - $request, - $this->handle, - new ResponseBuilder($this->createResponse()) - ); - static::assertSame($request, $core->getRequest()); - static::assertSame($this->handle, $core->getHandle()); - - $core->addOnFulfilled( - function (ResponseInterface $response) { - return $response->withAddedHeader('X-Test', 'foo'); - } - ); - - $core->fulfill(); - static::assertEquals(Promise::FULFILLED, $core->getState()); - static::assertInstanceOf(ResponseInterface::class, $core->getResponse()); - static::assertEquals('foo', $core->getResponse()->getHeaderLine('X-Test')); - - $core->addOnFulfilled( - function (ResponseInterface $response) { - return $response->withAddedHeader('X-Test', 'bar'); - } - ); - static::assertEquals('foo, bar', $core->getResponse()->getHeaderLine('X-Test')); - } - - /** - * Test on reject actions. - */ - public function testOnReject() - { - $request = $this->createRequest('GET', '/'); - $this->handle = curl_init(); - - $core = new PromiseCore( - $request, - $this->handle, - new ResponseBuilder($this->createResponse()) - ); - $core->addOnRejected( - function (RequestException $exception) { - throw new RequestException('Foo', $exception->getRequest(), $exception); - } - ); - - $exception = new RequestException('Error', $request); - $core->reject($exception); - static::assertEquals(Promise::REJECTED, $core->getState()); - static::assertInstanceOf(Exception::class, $core->getException()); - static::assertEquals('Foo', $core->getException()->getMessage()); - - $core->addOnRejected( - function (RequestException $exception) { - return new RequestException('Bar', $exception->getRequest(), $exception); - } - ); - static::assertEquals('Bar', $core->getException()->getMessage()); - } - - /** - * «onReject» callback can throw exception. - * - * @see https://github.com/php-http/curl-client/issues/26 - */ - public function testIssue26() - { - $request = $this->createRequest('GET', '/'); - $this->handle = curl_init(); - - $core = new PromiseCore( - $request, - $this->handle, - new ResponseBuilder($this->createResponse()) - ); - $core->addOnRejected( - function (RequestException $exception) { - throw new RequestException('Foo', $exception->getRequest(), $exception); - } - ); - $core->addOnRejected( - function (RequestException $exception) { - return new RequestException('Bar', $exception->getRequest(), $exception); - } - ); - - $exception = new RequestException('Error', $request); - $core->reject($exception); - static::assertEquals(Promise::REJECTED, $core->getState()); - static::assertInstanceOf(Exception::class, $core->getException()); - static::assertEquals('Bar', $core->getException()->getMessage()); - } - - /** - * @expectedException \LogicException - */ - public function testNotRejected() - { - $request = $this->createRequest('GET', '/'); - $this->handle = curl_init(); - $core = new PromiseCore( - $request, - $this->handle, - new ResponseBuilder($this->createResponse()) - ); - $core->getException(); - } -} diff --git a/tests/ClientTest.php b/tests/Unit/ClientTest.php similarity index 77% rename from tests/ClientTest.php rename to tests/Unit/ClientTest.php index 85ae402..0cc07d3 100644 --- a/tests/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Http\Client\Curl\Tests; +namespace Http\Client\Curl\Tests\Unit; use Http\Client\Curl\Client; -use Http\Message\MessageFactory; -use Http\Message\StreamFactory; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Zend\Diactoros\Request; @@ -23,7 +23,7 @@ class ClientTest extends TestCase * * @link https://github.com/php-http/curl-client/issues/18 */ - public function testExpectHeader() + public function testExpectHeader(): void { $client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock(); @@ -42,9 +42,9 @@ public function testExpectHeader() * * @link https://github.com/php-http/curl-client/issues/18 */ - public function testWithNullPostFields() + public function testWithNullPostFields(): void { - $client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock(); + $client = $this->createMock(Client::class); $createHeaders = new \ReflectionMethod(Client::class, 'createHeaders'); $createHeaders->setAccessible(true); @@ -52,12 +52,12 @@ public function testWithNullPostFields() $request = new Request(); $request = $request->withHeader('content-length', '0'); - $headers = $createHeaders->invoke($client, $request, [CURLOPT_POSTFIELDS => null]); + $headers = $createHeaders->invoke($client, $request, [CURLOPT_POSTFIELDS => '']); - static::assertContains('content-length: 0', $headers); + self::assertContains('content-length: 0', $headers); } - public function testRewindStream() + public function testRewindStream(): void { $client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock(); @@ -72,7 +72,7 @@ public function testRewindStream() static::assertEquals('abcdef', $options[CURLOPT_POSTFIELDS]); } - public function testRewindLargeStream() + public function testRewindLargeStream(): void { $client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock(); @@ -93,25 +93,18 @@ public function testRewindLargeStream() static::assertTrue(false !== strstr($options[CURLOPT_READFUNCTION](null, null, $length), 'abcdef'), 'Steam was not rewinded'); } - public function testInvalidCurlOptions() + /** + * Tests throwing InvalidArgumentException when invalid cURL options passed to constructor. + */ + public function testInvalidCurlOptions(): void { $this->expectException(InvalidOptionsException::class); new Client( - $this->createMock(MessageFactory::class), - $this->createMock(StreamFactory::class), + $this->createMock(ResponseFactoryInterface::class), + $this->createMock(StreamFactoryInterface::class), [ CURLOPT_HEADER => true, // this won't work with our client ] ); } - - /** - * Discovery should be used if no factory given. - */ - public function testFactoryDiscovery() - { - $client = new Client(); - - static::assertInstanceOf(Client::class, $client); - } } diff --git a/tests/Unit/CurlPromiseTest.php b/tests/Unit/CurlPromiseTest.php new file mode 100644 index 0000000..2cf42d8 --- /dev/null +++ b/tests/Unit/CurlPromiseTest.php @@ -0,0 +1,86 @@ +createMock(PromiseCore::class); + $runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor() + ->setMethods(['wait'])->getMock(); + /** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */ + $promise = new CurlPromise($core, $runner); + + $runner->expects(self::once())->method('wait')->with($core); + $core->expects(self::once())->method('getState')->willReturn(Promise::FULFILLED); + + $response = $this->createMock(ResponseInterface::class); + $core->expects(self::once())->method('getResponse')->willReturn($response); + self::assertSame($response, $promise->wait()); + } + + /** + * TODO Summary + */ + public function testCoreCallWaitRejected(): void + { + $core = $this->createMock(PromiseCore::class); + $runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()->getMock(); + /** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */ + $promise = new CurlPromise($core, $runner); + + $runner->expects(self::once())->method('wait')->with($core); + $core->expects(self::once())->method('getState')->willReturn(Promise::REJECTED); + $core->expects(self::once())->method('getException')->willReturn(new TransferException()); + + try { + $promise->wait(); + } catch (TransferException $exception) { + self::assertTrue(true); + } + } + + /** + * Test that promise call core methods. + */ + public function testCoreCalls(): void + { + $core = $this->createMock(PromiseCore::class); + $runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor() + ->setMethods(['wait'])->getMock(); + /** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */ + $promise = new CurlPromise($core, $runner); + + $onFulfill = function () { + }; + $core->expects(self::once())->method('addOnFulfilled')->with($onFulfill); + + $onReject = function () { + }; + $core->expects(self::once())->method('addOnRejected')->with($onReject); + + $promise->then($onFulfill, $onReject); + + $core->expects(self::once())->method('getState')->willReturn('STATE'); + self::assertEquals('STATE', $promise->getState()); + } +} diff --git a/tests/Unit/PromiseCoreTest.php b/tests/Unit/PromiseCoreTest.php new file mode 100644 index 0000000..489f834 --- /dev/null +++ b/tests/Unit/PromiseCoreTest.php @@ -0,0 +1,176 @@ +createMock(RequestInterface::class); + $responseBuilder = $this->createMock(ResponseBuilder::class); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, stream resource given'); + + new PromiseCore($request, fopen('php://memory', 'r+b'), $responseBuilder); + } + + /** + * Testing if handle is not a resource. + */ + public function testHandleIsNotAResource(): void + { + $request = $this->createMock(RequestInterface::class); + $responseBuilder = $this->createMock(ResponseBuilder::class); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, NULL given'); + + new PromiseCore($request, null, $responseBuilder); + } + + /** + * «onReject» callback can throw exception. + * + * @see https://github.com/php-http/curl-client/issues/26 + */ + public function testIssue26(): void + { + $request = $this->createMock(RequestInterface::class); + $responseBuilder = $this->createMock(ResponseBuilder::class); + + $this->handle = curl_init(); + + $core = new PromiseCore($request, $this->handle, $responseBuilder); + $core->addOnRejected( + function (RequestException $exception) { + throw new RequestException('Foo', $exception->getRequest(), $exception); + } + ); + $core->addOnRejected( + function (RequestException $exception) { + return new RequestException('Bar', $exception->getRequest(), $exception); + } + ); + + $exception = new RequestException('Error', $request); + $core->reject($exception); + self::assertEquals(Promise::REJECTED, $core->getState()); + self::assertEquals('Bar', $core->getException()->getMessage()); + } + + /** + * @expectedException \LogicException + */ + public function testNotRejected(): void + { + $request = $this->createMock(RequestInterface::class); + $responseBuilder = $this->createMock(ResponseBuilder::class); + + $this->handle = curl_init(); + + $core = new PromiseCore($request, $this->handle, $responseBuilder); + $core->getException(); + } + + /** + * Test on fulfill actions. + */ + public function testOnFulfill(): void + { + $request = $this->createMock(RequestInterface::class); + + $stream = $this->createMock(StreamInterface::class); + $response1 = $this->createConfiguredMock(ResponseInterface::class, ['getBody' => $stream]); + $responseBuilder = $this->createConfiguredMock(ResponseBuilder::class, ['getResponse' => $response1]); + $response2 = $this->createConfiguredMock(ResponseInterface::class, ['getBody' => $stream]); + + $this->handle = curl_init(); + + $core = new PromiseCore($request, $this->handle, $responseBuilder); + + self::assertSame($request, $core->getRequest()); + self::assertSame($this->handle, $core->getHandle()); + + $core->addOnFulfilled( + function (ResponseInterface $response) use ($response1, $response2) { + self::assertSame($response1, $response); + + return $response2; + } + ); + + $core->fulfill(); + self::assertEquals(Promise::FULFILLED, $core->getState()); + } + + /** + * Test on reject actions. + */ + public function testOnReject(): void + { + $request = $this->createMock(RequestInterface::class); + $responseBuilder = $this->createMock(ResponseBuilder::class); + + $this->handle = curl_init(); + + $core = new PromiseCore($request, $this->handle, $responseBuilder); + $core->addOnRejected( + function (RequestException $exception) { + throw new RequestException('Foo', $exception->getRequest(), $exception); + } + ); + + $exception = new RequestException('Error', $request); + $core->reject($exception); + self::assertEquals(Promise::REJECTED, $core->getState()); + self::assertEquals('Foo', $core->getException()->getMessage()); + + $core->addOnRejected( + function (RequestException $exception) { + return new RequestException('Bar', $exception->getRequest(), $exception); + } + ); + self::assertEquals('Bar', $core->getException()->getMessage()); + } + + /** + * Tears down the fixture. + */ + protected function tearDown() + { + if (is_resource($this->handle)) { + curl_close($this->handle); + } + + parent::tearDown(); + } +} From fa4feeac1267a01c22752a3461fe1652f2dee01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2?= Date: Wed, 26 Dec 2018 17:31:00 +0300 Subject: [PATCH 2/3] Restore php-http/message dependency --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 5b0a0e2..eba01d8 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "ext-curl": "*", "php-http/discovery": "^1.0", "php-http/httplug": "^2.0", + "php-http/message": "^1.2", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", "symfony/options-resolver": "^3.4 || ^4.0" From dd1384284b20f6a2cb78f5031370bc310066de1e Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 24 Jan 2019 11:06:45 +0100 Subject: [PATCH 3/3] cleanup for PSR-17 --- CHANGELOG.md | 3 +- composer.json | 4 +- src/Client.php | 98 ++++++------------- .../HttpAsyncClientDiactorosTest.php | 6 +- .../Functional/HttpAsyncClientGuzzleTest.php | 6 +- tests/Functional/HttpAsyncClientTestCase.php | 40 +++----- tests/Functional/HttpClientDiactorosTest.php | 14 +-- tests/Functional/HttpClientGuzzleTest.php | 14 +-- tests/Functional/HttpClientTestCase.php | 54 ++++------ tests/Unit/ClientTest.php | 2 - tests/Unit/CurlPromiseTest.php | 11 --- tests/Unit/PromiseCoreTest.php | 15 +-- 12 files changed, 77 insertions(+), 190 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 112bfc3..a2faf1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Change Log -## Unreleased +## 2.0.0 - Unreleased +- Client expects PSR-17 ResponseFactoryInterface and StreamFactoryInterface rather than Httplug factories. - Allow cURL options to overwrite our default spec-compliant default configuration ## 1.7.1 - 2018-03-36 diff --git a/composer.json b/composer.json index eba01d8..6b528f1 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "php-http/curl-client", - "description": "PSR-18 cURL client", + "description": "PSR-18 and HTTPlug Async client with cURL", "license": "MIT", "keywords": [ "curl", @@ -19,7 +19,7 @@ "require": { "php": "^7.1", "ext-curl": "*", - "php-http/discovery": "^1.0", + "php-http/discovery": "^1.6", "php-http/httplug": "^2.0", "php-http/message": "^1.2", "psr/http-client": "^1.0", diff --git a/src/Client.php b/src/Client.php index 5b19bd1..7dc4262 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,9 +7,7 @@ use Http\Client\Exception; use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; -use Http\Discovery\MessageFactoryDiscovery; -use Http\Discovery\StreamFactoryDiscovery; -use Http\Promise\Promise; +use Http\Discovery\Psr17FactoryDiscovery; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; @@ -17,7 +15,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; /** - * PSR-7 compatible cURL based HTTP client. + * PSR-18 and HTTPlug Async client based on lib-curl. * * @license http://opensource.org/licenses/MIT MIT * @author Михаил Красильников @@ -34,7 +32,7 @@ class Client implements HttpClient, HttpAsyncClient * * @var array */ - private $options; + private $curlOptions; /** * PSR-17 response factory. @@ -65,25 +63,19 @@ class Client implements HttpClient, HttpAsyncClient private $multiRunner; /** - * Construct client. - * * @param ResponseFactoryInterface|null $responseFactory PSR-17 HTTP response factory. * @param StreamFactoryInterface|null $streamFactory PSR-17 HTTP stream factory. * @param array $options cURL options {@link http://php.net/curl_setopt} * * @throws \Http\Discovery\Exception\NotFoundException If factory discovery failed - * - * @since x.x $messageFactory changed to PSR-17 ResponseFactoryInterface $responseFactory. - * @since x.x $streamFactory type changed to PSR-17 StreamFactoryInterface. - * @since 1.0 */ public function __construct( ResponseFactoryInterface $responseFactory = null, StreamFactoryInterface $streamFactory = null, array $options = [] ) { - $this->responseFactory = $responseFactory; // FIXME ?: MessageFactoryDiscovery::find(); - $this->streamFactory = $streamFactory; // FIXME ?: StreamFactoryDiscovery::find(); + $this->responseFactory = $responseFactory ?: Psr17FactoryDiscovery::findResponseFactory(); + $this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory(); $resolver = new OptionsResolver(); $resolver->setDefaults( [ @@ -99,7 +91,7 @@ public function __construct( // Make sure that we accept everything that is in the options. $resolver->setDefined(array_keys($options)); - $this->options = $resolver->resolve($options); + $this->curlOptions = $resolver->resolve($options); } /** @@ -113,11 +105,7 @@ public function __destruct() } /** - * Sends a PSR-7 request and returns a PSR-7 response. - * - * @param RequestInterface $request - * - * @return ResponseInterface + * {@inheritdoc} * * @throws \Http\Client\Exception\NetworkException In case of network problems * @throws \Http\Client\Exception\RequestException On invalid request @@ -164,11 +152,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface } /** - * Sends a PSR-7 request in an asynchronous way. - * - * @param RequestInterface $request - * - * @return Promise + * {@inheritdoc} * * @throws \Http\Client\Exception\RequestException On invalid request * @throws \InvalidArgumentException For invalid header names or values @@ -198,36 +182,31 @@ public function sendAsyncRequest(RequestInterface $request) /** * Update cURL options for this request and hook in the response builder. * - * @param RequestInterface $request - * @param ResponseBuilder $responseBuilder - * * @throws \Http\Client\Exception\RequestException On invalid request * @throws \InvalidArgumentException For invalid header names or values * @throws \RuntimeException If can not read body - * - * @return array */ - private function prepareRequestOptions(RequestInterface $request, ResponseBuilder $responseBuilder) + private function prepareRequestOptions(RequestInterface $request, ResponseBuilder $responseBuilder): array { - $options = $this->options; + $curlOptions = $this->curlOptions; try { - $options[CURLOPT_HTTP_VERSION] + $curlOptions[CURLOPT_HTTP_VERSION] = $this->getProtocolVersion($request->getProtocolVersion()); } catch (\UnexpectedValueException $e) { throw new Exception\RequestException($e->getMessage(), $request); } - $options[CURLOPT_URL] = (string) $request->getUri(); + $curlOptions[CURLOPT_URL] = (string) $request->getUri(); - $options = $this->addRequestBodyOptions($request, $options); + $curlOptions = $this->addRequestBodyOptions($request, $curlOptions); - $options[CURLOPT_HTTPHEADER] = $this->createHeaders($request, $options); + $curlOptions[CURLOPT_HTTPHEADER] = $this->createHeaders($request, $curlOptions); if ($request->getUri()->getUserInfo()) { - $options[CURLOPT_USERPWD] = $request->getUri()->getUserInfo(); + $curlOptions[CURLOPT_USERPWD] = $request->getUri()->getUserInfo(); } - $options[CURLOPT_HEADERFUNCTION] = function ($ch, $data) use ($responseBuilder) { + $curlOptions[CURLOPT_HEADERFUNCTION] = function ($ch, $data) use ($responseBuilder) { $str = trim($data); if ('' !== $str) { if (strpos(strtolower($str), 'http/') === 0) { @@ -240,21 +219,17 @@ private function prepareRequestOptions(RequestInterface $request, ResponseBuilde return strlen($data); }; - $options[CURLOPT_WRITEFUNCTION] = function ($ch, $data) use ($responseBuilder) { + $curlOptions[CURLOPT_WRITEFUNCTION] = function ($ch, $data) use ($responseBuilder) { return $responseBuilder->getResponse()->getBody()->write($data); }; - return $options; + return $curlOptions; } /** * Return cURL constant for specified HTTP version. * - * @param string $requestVersion - * * @throws \UnexpectedValueException If unsupported version requested - * - * @return int */ private function getProtocolVersion(string $requestVersion): int { @@ -275,13 +250,8 @@ private function getProtocolVersion(string $requestVersion): int /** * Add request body related cURL options. - * - * @param RequestInterface $request - * @param array $options - * - * @return array */ - private function addRequestBodyOptions(RequestInterface $request, array $options): array + private function addRequestBodyOptions(RequestInterface $request, array $curlOptions): array { /* * Some HTTP methods cannot have payload: @@ -302,40 +272,37 @@ private function addRequestBodyOptions(RequestInterface $request, array $options // Message has non empty body. if (null === $bodySize || $bodySize > 1024 * 1024) { // Avoid full loading large or unknown size body into memory - $options[CURLOPT_UPLOAD] = true; + $curlOptions[CURLOPT_UPLOAD] = true; if (null !== $bodySize) { - $options[CURLOPT_INFILESIZE] = $bodySize; + $curlOptions[CURLOPT_INFILESIZE] = $bodySize; } - $options[CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) { + $curlOptions[CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) { return $body->read($length); }; } else { // Small body can be loaded into memory - $options[CURLOPT_POSTFIELDS] = (string) $body; + $curlOptions[CURLOPT_POSTFIELDS] = (string) $body; } } } if ($request->getMethod() === 'HEAD') { // This will set HTTP method to "HEAD". - $options[CURLOPT_NOBODY] = true; + $curlOptions[CURLOPT_NOBODY] = true; } elseif ($request->getMethod() !== 'GET') { // GET is a default method. Other methods should be specified explicitly. - $options[CURLOPT_CUSTOMREQUEST] = $request->getMethod(); + $curlOptions[CURLOPT_CUSTOMREQUEST] = $request->getMethod(); } - return $options; + return $curlOptions; } /** * Create headers array for CURLOPT_HTTPHEADER. * - * @param RequestInterface $request - * @param array $options cURL options - * * @return string[] */ - private function createHeaders(RequestInterface $request, array $options): array + private function createHeaders(RequestInterface $request, array $curlOptions): array { $curlHeaders = []; $headers = $request->getHeaders(); @@ -346,10 +313,10 @@ private function createHeaders(RequestInterface $request, array $options): array continue; } if ('content-length' === $header) { - if (array_key_exists(CURLOPT_POSTFIELDS, $options)) { + if (array_key_exists(CURLOPT_POSTFIELDS, $curlOptions)) { // Small body content length can be calculated here. - $values = [strlen($options[CURLOPT_POSTFIELDS])]; - } elseif (!array_key_exists(CURLOPT_READFUNCTION, $options)) { + $values = [strlen($curlOptions[CURLOPT_POSTFIELDS])]; + } elseif (!array_key_exists(CURLOPT_READFUNCTION, $curlOptions)) { // Else if there is no body, forcing "Content-length" to 0 $values = [0]; } @@ -367,11 +334,6 @@ private function createHeaders(RequestInterface $request, array $options): array return $curlHeaders; } - /** - * Create new ResponseBuilder instance. - * - * @return ResponseBuilder - */ private function createResponseBuilder(): ResponseBuilder { $body = $this->streamFactory->createStreamFromFile('php://temp', 'w+b'); diff --git a/tests/Functional/HttpAsyncClientDiactorosTest.php b/tests/Functional/HttpAsyncClientDiactorosTest.php index 273ea0f..2ef7b6c 100644 --- a/tests/Functional/HttpAsyncClientDiactorosTest.php +++ b/tests/Functional/HttpAsyncClientDiactorosTest.php @@ -10,14 +10,12 @@ use Zend\Diactoros\StreamFactory; /** - * Testing asynchronous requests with Zend Diactoros factories. + * @covers \Http\Client\Curl\Client */ class HttpAsyncClientDiactorosTest extends HttpAsyncClientTestCase { /** - * Create asynchronous HTTP client for tests. - * - * @return HttpAsyncClient + * {@inheritdoc} */ protected function createHttpAsyncClient(): HttpAsyncClient { diff --git a/tests/Functional/HttpAsyncClientGuzzleTest.php b/tests/Functional/HttpAsyncClientGuzzleTest.php index 1b72d83..f1d2808 100644 --- a/tests/Functional/HttpAsyncClientGuzzleTest.php +++ b/tests/Functional/HttpAsyncClientGuzzleTest.php @@ -10,14 +10,12 @@ use Http\Message\StreamFactory\GuzzleStreamFactory; /** - * Tests for Http\Client\Curl\Client. + * @covers \Http\Client\Curl\Client */ class HttpAsyncClientGuzzleTest extends HttpAsyncClientTestCase { /** - * Create asynchronious HTTP client for tests. - * - * @return HttpAsyncClient + * {@inheritdoc} */ protected function createHttpAsyncClient(): HttpAsyncClient { diff --git a/tests/Functional/HttpAsyncClientTestCase.php b/tests/Functional/HttpAsyncClientTestCase.php index b940dc6..ded8f72 100644 --- a/tests/Functional/HttpAsyncClientTestCase.php +++ b/tests/Functional/HttpAsyncClientTestCase.php @@ -12,52 +12,42 @@ abstract class HttpAsyncClientTestCase extends HttpAsyncClientTest { /** - * TODO Summary. - * - * @param string $method HTTP method. - * @param string $uri Request URI. - * @param array $headers HTTP headers. - * @param string $body Request body. + * {@inheritdoc} * * @dataProvider requestProvider */ - public function testAsyncSendRequest($method, $uri, array $headers, $body): void + public function testAsyncSendRequest($httpMethod, $uri, array $httpHeaders, $requestBody): void { - if ($body !== null && in_array($method, ['GET', 'HEAD', 'TRACE'], true)) { - self::markTestSkipped('cURL can not send body using '.$method); + if ($requestBody !== null && in_array($httpMethod, ['GET', 'HEAD', 'TRACE'], true)) { + self::markTestSkipped('cURL can not send body using '.$httpMethod); } parent::testAsyncSendRequest( - $method, + $httpMethod, $uri, - $headers, - $body + $httpHeaders, + $requestBody ); } /** - * TODO Summary. - * - * @param array $uriAndOutcome TODO ??? - * @param string $protocolVersion HTTP version. - * @param array $headers HTTP headers. - * @param string $body Request body. + * {@inheritdoc} * * @dataProvider requestWithOutcomeProvider */ public function testSendAsyncRequestWithOutcome( $uriAndOutcome, - $protocolVersion, - array $headers, - $body + $httpVersion, + array $httpHeaders, + $requestBody ): void { - if ( $body !== null) { + if ( $requestBody !== null) { self::markTestSkipped('cURL can not send body using GET'); } parent::testSendAsyncRequestWithOutcome( $uriAndOutcome, - $protocolVersion, - $headers, - $body + $httpVersion, + $httpHeaders, + $requestBody ); } } diff --git a/tests/Functional/HttpClientDiactorosTest.php b/tests/Functional/HttpClientDiactorosTest.php index 5117f4b..854bcdc 100644 --- a/tests/Functional/HttpClientDiactorosTest.php +++ b/tests/Functional/HttpClientDiactorosTest.php @@ -16,23 +16,11 @@ */ class HttpClientDiactorosTest extends HttpClientTestCase { - /** - * Create stream from file. - * - * @param string $filename - * - * @return StreamInterface - */ - protected function createFileStream($filename): StreamInterface + protected function createFileStream(string $filename): StreamInterface { return new Stream($filename); } - /** - * Create HTTP client for tests. - * - * @return HttpClient - */ protected function createHttpAdapter(): HttpClient { return new Client(new ResponseFactory(), new StreamFactory()); diff --git a/tests/Functional/HttpClientGuzzleTest.php b/tests/Functional/HttpClientGuzzleTest.php index 02d1689..9cbe9da 100644 --- a/tests/Functional/HttpClientGuzzleTest.php +++ b/tests/Functional/HttpClientGuzzleTest.php @@ -12,26 +12,22 @@ use Psr\Http\Message\StreamInterface; /** - * Tests for Http\Client\Curl\Client. + * @covers \Http\Client\Curl\Client */ class HttpClientGuzzleTest extends HttpClientTestCase { /** - * @return HttpClient + * {@inheritdoc} */ - protected function createHttpAdapter() + protected function createHttpAdapter(): HttpClient { return new Client(new GuzzleMessageFactory(), new GuzzleStreamFactory()); } /** - * Create stream from file. - * - * @param string $filename - * - * @return StreamInterface + * {@inheritdoc} */ - protected function createFileStream($filename) + protected function createFileStream(string $filename): StreamInterface { return new Stream(fopen($filename, 'r')); } diff --git a/tests/Functional/HttpClientTestCase.php b/tests/Functional/HttpClientTestCase.php index e7cec47..6df8a8d 100644 --- a/tests/Functional/HttpClientTestCase.php +++ b/tests/Functional/HttpClientTestCase.php @@ -20,9 +20,6 @@ abstract class HttpClientTestCase extends HttpClientTest */ protected $tmpFiles = []; - /** - * Test sending large files. - */ public function testSendLargeFile(): void { $filename = $this->createTempFile(); @@ -55,63 +52,46 @@ public function testSendLargeFile(): void } /** - * TODO Summary. - * - * @param string $method HTTP method. - * @param string $uri Request URI. - * @param array $headers HTTP headers. - * @param string $body Request body. + * {@inheritdoc} * * @dataProvider requestProvider */ - public function testSendRequest($method, $uri, array $headers, $body): void + public function testSendRequest($httpMethod, $uri, array $httpHeaders, $requestBody): void { - if ($body !== null && in_array($method, ['GET', 'HEAD', 'TRACE'], true)) { - self::markTestSkipped('cURL can not send body using '.$method); + if ($requestBody !== null && in_array($httpMethod, ['GET', 'HEAD', 'TRACE'], true)) { + self::markTestSkipped('cURL can not send body using '.$httpMethod); } parent::testSendRequest( - $method, + $httpMethod, $uri, - $headers, - $body + $httpHeaders, + $requestBody ); } /** - * TODO Summary. - * - * @param array $uriAndOutcome TODO ??? - * @param string $protocolVersion HTTP version. - * @param array $headers HTTP headers. - * @param string $body Request body. + * {@inheritdoc} * * @dataProvider requestWithOutcomeProvider */ public function testSendRequestWithOutcome( $uriAndOutcome, - $protocolVersion, - array $headers, - $body + $httpVersion, + array $httpHeaders, + $requestBody ): void { - if ($body !== null) { + if ($requestBody !== null) { self::markTestSkipped('cURL can not send body using GET'); } parent::testSendRequestWithOutcome( $uriAndOutcome, - $protocolVersion, - $headers, - $body + $httpVersion, + $httpHeaders, + $requestBody ); } - /** - * Create stream from file. - * - * @param string $filename - * - * @return StreamInterface - */ - abstract protected function createFileStream($filename): StreamInterface; + abstract protected function createFileStream(string $filename): StreamInterface; /** * Create temporary file. @@ -127,7 +107,7 @@ protected function createTempFile(): string } /** - * Tears down the fixture. + * Delete files created with createTempFile */ protected function tearDown() { diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index d4274c1..264e977 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -12,8 +12,6 @@ use Zend\Diactoros\Request; /** - * Tests for Http\Client\Curl\Client. - * * @covers \Http\Client\Curl\Client */ class ClientTest extends TestCase diff --git a/tests/Unit/CurlPromiseTest.php b/tests/Unit/CurlPromiseTest.php index 2cf42d8..617b258 100644 --- a/tests/Unit/CurlPromiseTest.php +++ b/tests/Unit/CurlPromiseTest.php @@ -13,15 +13,10 @@ use Psr\Http\Message\ResponseInterface; /** - * Tests for Http\Client\Curl\CurlPromise. - * * @covers \Http\Client\Curl\CurlPromise */ class CurlPromiseTest extends TestCase { - /** - * TODO Summary - */ public function testCoreCallWaitFulfilled(): void { $core = $this->createMock(PromiseCore::class); @@ -38,9 +33,6 @@ public function testCoreCallWaitFulfilled(): void self::assertSame($response, $promise->wait()); } - /** - * TODO Summary - */ public function testCoreCallWaitRejected(): void { $core = $this->createMock(PromiseCore::class); @@ -59,9 +51,6 @@ public function testCoreCallWaitRejected(): void } } - /** - * Test that promise call core methods. - */ public function testCoreCalls(): void { $core = $this->createMock(PromiseCore::class); diff --git a/tests/Unit/PromiseCoreTest.php b/tests/Unit/PromiseCoreTest.php index 489f834..b52df28 100644 --- a/tests/Unit/PromiseCoreTest.php +++ b/tests/Unit/PromiseCoreTest.php @@ -16,8 +16,6 @@ use Psr\Http\Message\StreamInterface; /** - * Tests for Http\Client\Curl\PromiseCore. - * * @covers \Http\Client\Curl\PromiseCore */ class PromiseCoreTest extends TestCase @@ -87,9 +85,6 @@ function (RequestException $exception) { self::assertEquals('Bar', $core->getException()->getMessage()); } - /** - * @expectedException \LogicException - */ public function testNotRejected(): void { $request = $this->createMock(RequestInterface::class); @@ -98,12 +93,10 @@ public function testNotRejected(): void $this->handle = curl_init(); $core = new PromiseCore($request, $this->handle, $responseBuilder); + $this->expectException(\LogicException::class); $core->getException(); } - /** - * Test on fulfill actions. - */ public function testOnFulfill(): void { $request = $this->createMock(RequestInterface::class); @@ -132,9 +125,6 @@ function (ResponseInterface $response) use ($response1, $response2) { self::assertEquals(Promise::FULFILLED, $core->getState()); } - /** - * Test on reject actions. - */ public function testOnReject(): void { $request = $this->createMock(RequestInterface::class); @@ -162,9 +152,6 @@ function (RequestException $exception) { self::assertEquals('Bar', $core->getException()->getMessage()); } - /** - * Tears down the fixture. - */ protected function tearDown() { if (is_resource($this->handle)) {