diff --git a/Tests/HttpFactoryTest.php b/Tests/HttpFactoryTest.php index 76b4fda6..dde9d6ca 100644 --- a/Tests/HttpFactoryTest.php +++ b/Tests/HttpFactoryTest.php @@ -7,14 +7,23 @@ namespace Joomla\Http\Tests; +use Joomla\Http\AbstractTransport; use Joomla\Http\Http; use Joomla\Http\HttpFactory; +use Joomla\Http\Transport\Curl; use Joomla\Http\TransportInterface; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestDox; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; /** * Test class for Joomla\Http\HttpFactory. */ +#[CoversClass(HttpFactory::class)] +#[UsesClass(AbstractTransport::class)] +#[UsesClass(Http::class)] +#[UsesClass(Curl::class)] class HttpFactoryTest extends TestCase { /** @@ -36,14 +45,7 @@ protected function setUp(): void $this->instance = new HttpFactory(); } - /** - * @testdox A HTTP client can be created - * - * @covers Joomla\Http\HttpFactory - * @uses Joomla\Http\AbstractTransport - * @uses Joomla\Http\Http - * @uses Joomla\Http\Transport\Curl - */ + #[TestDox('A HTTP client can be created')] public function testGetHttp() { $this->assertInstanceOf( @@ -52,11 +54,7 @@ public function testGetHttp() ); } - /** - * @testdox A HTTP client can only be created with an appropriate options data type - * - * @covers Joomla\Http\HttpFactory - */ + #[TestDox('A HTTP client can only be created with an appropriate options data type')] public function testGetHttpDisallowsNonArrayObjects() { $this->expectException(\InvalidArgumentException::class); @@ -64,11 +62,7 @@ public function testGetHttpDisallowsNonArrayObjects() $this->instance->getHttp(new \stdClass()); } - /** - * @testdox A HTTP client cannot be created when no transport driver is available - * - * @covers Joomla\Http\HttpFactory - */ + #[TestDox('A HTTP client cannot be created when no transport driver is available')] public function testGetHttpException() { $this->expectException(\RuntimeException::class); @@ -79,13 +73,7 @@ public function testGetHttpException() ); } - /** - * @testdox A transport driver can be created - * - * @covers Joomla\Http\HttpFactory - * @uses Joomla\Http\AbstractTransport - * @uses Joomla\Http\Transport\Curl - */ + #[TestDox('A transport driver can be created')] public function testGetAvailableDriver() { $this->assertInstanceOf( @@ -111,11 +99,7 @@ public function testGetAvailableDriver() ); } - /** - * @testdox A driver can only be created with an appropriate options data type - * - * @covers Joomla\Http\HttpFactory - */ + #[TestDox('A driver can only be created with an appropriate options data type')] public function testGetAvailableDriverDisallowsNonArrayObjects() { $this->expectException(\InvalidArgumentException::class); @@ -123,17 +107,13 @@ public function testGetAvailableDriverDisallowsNonArrayObjects() $this->instance->getAvailableDriver(new \stdClass()); } - /** - * @testdox The list of transport drivers is returned - * - * @covers Joomla\Http\HttpFactory - */ + #[TestDox('The list of transport drivers is returned')] public function testGetHttpTransports() { $transports = ['Stream', 'Socket', 'Curl']; sort($transports); - $this->assertEquals( + $this->assertSame( $transports, $this->instance->getHttpTransports() ); diff --git a/Tests/HttpTest.php b/Tests/HttpTest.php index 74090c9b..7c2c7c1b 100644 --- a/Tests/HttpTest.php +++ b/Tests/HttpTest.php @@ -12,13 +12,16 @@ use Joomla\Http\TransportInterface; use Joomla\Uri\Uri; use Laminas\Diactoros\Request; +use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; /** * Test class for Joomla\Http\Http. */ +#[CoversClass(Http::class)] class HttpTest extends TestCase { /** @@ -57,12 +60,8 @@ protected function setUp(): void $this->object = new Http($this->options, $this->transport); } - /** - * @testdox The constructor disallows invalid data objects - * - * @covers Joomla\Http\Http - */ #[AllowMockObjectsWithoutExpectations] + #[TestDox('The constructor disallows invalid data objects')] public function testConstructorDisallowsNonArrayObjects() { $this->expectException(\InvalidArgumentException::class); @@ -70,12 +69,8 @@ public function testConstructorDisallowsNonArrayObjects() new Http(new \stdClass()); } - /** - * @testdox The driver's options can be managed - * - * @covers Joomla\Http\Http - */ #[AllowMockObjectsWithoutExpectations] + #[TestDox("The driver's options can be managed")] public function testOptionManagement() { $this->object->setOption('testKey', 'testValue'); @@ -86,11 +81,7 @@ public function testOptionManagement() ); } - /** - * @testdox A OPTIONS request can be sent - * - * @covers Joomla\Http\Http - */ + #[TestDox('A OPTIONS request can be sent')] public function testOptions() { $response = new Response(); @@ -106,11 +97,7 @@ public function testOptions() ); } - /** - * @testdox A HEAD request can be sent - * - * @covers Joomla\Http\Http - */ + #[TestDox('A HEAD request can be sent')] public function testHead() { // Set header option @@ -137,11 +124,7 @@ public function testHead() ); } - /** - * @testdox A GET request can be sent - * - * @covers Joomla\Http\Http - */ + #[TestDox('A GET request can be sent')] public function testGet() { // Set timeout option @@ -168,11 +151,7 @@ public function testGet() ); } - /** - * @testdox A GET request can be sent when passing a URI object - * - * @covers Joomla\Http\Http - */ + #[TestDox('A GET request can be sent when passing a URI object')] public function testGetWithUri() { // Set timeout option @@ -199,12 +178,8 @@ public function testGetWithUri() ); } - /** - * @testdox Sending a GET request fails with an invalid data type for the URI - * - * @covers Joomla\Http\Http - */ #[AllowMockObjectsWithoutExpectations] + #[TestDox('Sending a GET request fails with an invalid data type for the URI')] public function testGetWithInvalidUrl() { $this->expectException(\InvalidArgumentException::class); @@ -213,11 +188,7 @@ public function testGetWithInvalidUrl() $this->object->get([]); } - /** - * @testdox A POST request can be sent - * - * @covers Joomla\Http\Http - */ + #[TestDox('A POST request can be sent')] public function testPost() { $response = new Response(); @@ -242,11 +213,7 @@ public function testPost() ); } - /** - * @testdox A PUT request can be sent - * - * @covers Joomla\Http\Http - */ + #[TestDox('A PUT request can be sent')] public function testPut() { $response = new Response(); @@ -271,11 +238,7 @@ public function testPut() ); } - /** - * @testdox A DELETE request can be sent - * - * @covers Joomla\Http\Http - */ + #[TestDox('A DELETE request can be sent')] public function testDelete() { $response = new Response(); @@ -298,11 +261,7 @@ public function testDelete() ); } - /** - * @testdox A TRACE request can be sent - * - * @covers Joomla\Http\Http - */ + #[TestDox('A TRACE request can be sent')] public function testTrace() { $response = new Response(); @@ -325,11 +284,7 @@ public function testTrace() ); } - /** - * @testdox A PATCH request can be sent - * - * @covers Joomla\Http\Http - */ + #[TestDox('A PATCH request can be sent')] public function testPatch() { $response = new Response(); @@ -354,11 +309,7 @@ public function testPatch() ); } - /** - * @testdox A request can be sent using a PSR-18 RequestInterface - * - * @covers Joomla\Http\Http - */ + #[TestDox('A request can be sent using a PSR-18 RequestInterface')] public function testSendRequest() { $response = new Response(); diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index 17c94008..db3db4ac 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -8,18 +8,17 @@ namespace Joomla\Http\Tests; use Joomla\Http\Response; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; /** * Test class for Joomla\Http\Response. */ +#[CoversClass(Response::class)] class ResponseTest extends TestCase { - /** - * @testdox The status code can be accessed through the deprecated property access - * - * @covers \Joomla\Http\Response - */ + #[TestDox('The status code can be accessed through the deprecated property access')] public function testReadResponseCode() { $this->assertSame( @@ -28,11 +27,7 @@ public function testReadResponseCode() ); } - /** - * @testdox The response body can be accessed through the deprecated property access - * - * @covers \Joomla\Http\Response - */ + #[TestDox('The response body can be accessed through the deprecated property access')] public function testReadResponseBody() { $this->assertSame( @@ -41,11 +36,7 @@ public function testReadResponseBody() ); } - /** - * @testdox The response headers can be accessed through the deprecated property access - * - * @covers \Joomla\Http\Response - */ + #[TestDox('The response headers can be accessed through the deprecated property access')] public function testReadResponseHeaders() { $this->assertSame( diff --git a/Tests/TransportTest.php b/Tests/TransportTest.php index 3ba14a0d..7a8ebb60 100644 --- a/Tests/TransportTest.php +++ b/Tests/TransportTest.php @@ -7,12 +7,16 @@ namespace Joomla\Http\Tests; +use Joomla\Http\AbstractTransport; use Joomla\Http\Transport\Curl; use Joomla\Http\Transport\Socket; use Joomla\Http\Transport\Stream; use Joomla\Http\TransportInterface; use Joomla\Uri\Uri; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\TestDox; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use function array_merge; @@ -24,6 +28,10 @@ * * @since 1.0 */ +#[CoversClass(Curl::class)] +#[CoversClass(Socket::class)] +#[CoversClass(Stream::class)] +#[UsesClass(AbstractTransport::class)] class TransportTest extends TestCase { /** @@ -88,16 +96,10 @@ public static function relevantOnlyForStreamTransportProvider(): array } /** - * @testdox A transport can only be created with an appropriate data type for the options - * * @param string $transportClass The transport class to test - * - * @covers \Joomla\Http\Transport\Curl - * @covers \Joomla\Http\Transport\Socket - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport */ #[DataProvider('transportProvider')] + #[TestDox('A transport can only be created with an appropriate data type for the options')] public function testConstructorWithBadDataObject(string $transportClass) { if (!$transportClass::isSupported()) { @@ -111,16 +113,10 @@ public function testConstructorWithBadDataObject(string $transportClass) } /** - * @testdox A transport can make a GET request - * * @param string $transportClass The transport class to test - * - * @covers \Joomla\Http\Transport\Curl - * @covers \Joomla\Http\Transport\Socket - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport */ #[DataProvider('transportProvider')] + #[TestDox('A transport can make a GET request')] public function testRequestGet(string $transportClass) { if (!$transportClass::isSupported()) { @@ -146,17 +142,13 @@ public function testRequestGet(string $transportClass) } /** - * @testdox A stream transport can make a GET request when blocking mode is enabled - * * @param string $transportClass The transport class to test * - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport - * * Blocking mode is only relevant for OPTION,HEAD,GET request since it only affects reading from the stream * @see https://www.php.net/manual/en/function.stream-set-blocking.php */ #[DataProvider('relevantOnlyForStreamTransportProvider')] + #[TestDox('A stream transport can make a GET request when blocking mode is enabled')] public function testRequestGetWhenBlockingModeIsEnabled(string $transportClass) { if (!$transportClass::isSupported() || $transportClass != Stream::class) { @@ -182,17 +174,13 @@ public function testRequestGetWhenBlockingModeIsEnabled(string $transportClass) } /** - * @testdox A stream transport can make a GET request when blocking mode is disabled - * * @param string $transportClass The transport class to test * - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport - * * Blocking mode is only relevant for OPTION,HEAD,GET request since it only affects reading from the stream * @see https://www.php.net/manual/en/function.stream-set-blocking.php */ #[DataProvider('relevantOnlyForStreamTransportProvider')] + #[TestDox('A stream transport can make a GET request when blocking mode is disabled')] public function testRequestGetWhenBlockingModeIsDisabled(string $transportClass) { if (!$transportClass::isSupported() || $transportClass != Stream::class) { @@ -219,16 +207,10 @@ public function testRequestGetWhenBlockingModeIsDisabled(string $transportClass) /** - * @testdox A transport fails to make a GET request to an invalid domain - * * @param string $transportClass The transport class to test - * - * @covers \Joomla\Http\Transport\Curl - * @covers \Joomla\Http\Transport\Socket - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport */ #[DataProvider('transportProvider')] + #[TestDox('A transport fails to make a GET request to an invalid domain')] public function testBadDomainRequestGet(string $transportClass) { if (!$transportClass::isSupported()) { @@ -244,16 +226,10 @@ public function testBadDomainRequestGet(string $transportClass) } /** - * @testdox A transport fails to make a GET request to an invalid URL - * * @param string $transportClass The transport class to test - * - * @covers \Joomla\Http\Transport\Curl - * @covers \Joomla\Http\Transport\Socket - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport */ #[DataProvider('transportProvider')] + #[TestDox('A transport fails to make a GET request to an invalid URL')] public function testRequestGet404(string $transportClass) { if (!$transportClass::isSupported()) { @@ -272,16 +248,10 @@ public function testRequestGet404(string $transportClass) } /** - * @testdox A transport can make a GET request - * * @param string $transportClass The transport class to test - * - * @covers \Joomla\Http\Transport\Curl - * @covers \Joomla\Http\Transport\Socket - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport */ #[DataProvider('transportProvider')] + #[TestDox('A transport can make a GET request')] public function testRequestPut(string $transportClass) { if (!$transportClass::isSupported()) { @@ -307,16 +277,10 @@ public function testRequestPut(string $transportClass) } /** - * @testdox A transport can make a GET request with basic authentication - * * @param string $transportClass The transport class to test - * - * @covers \Joomla\Http\Transport\Curl - * @covers \Joomla\Http\Transport\Socket - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport */ #[DataProvider('transportProvider')] + #[TestDox('A transport can make a GET request with basic authentication')] public function testRequestCredentials(string $transportClass) { if (!$transportClass::isSupported()) { @@ -351,16 +315,10 @@ public function testRequestCredentials(string $transportClass) } /** - * @testdox A transport can make a POST request with an array as the request data - * * @param string $transportClass The transport class to test - * - * @covers \Joomla\Http\Transport\Curl - * @covers \Joomla\Http\Transport\Socket - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport */ #[DataProvider('transportProvider')] + #[TestDox('A transport can make a POST request with an array as the request data')] public function testRequestPost(string $transportClass) { if (!$transportClass::isSupported()) { @@ -391,16 +349,10 @@ public function testRequestPost(string $transportClass) } /** - * @testdox A transport can make a POST request with a scalar value as the request data - * * @param string $transportClass The transport class to test - * - * @covers \Joomla\Http\Transport\Curl - * @covers \Joomla\Http\Transport\Socket - * @covers \Joomla\Http\Transport\Stream - * @uses \Joomla\Http\AbstractTransport */ #[DataProvider('transportProvider')] + #[TestDox('A transport can make a POST request with a scalar value as the request data')] public function testRequestPostScalar(string $transportClass) { if (!$transportClass::isSupported()) {