Skip to content
Open
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
52 changes: 16 additions & 36 deletions Tests/HttpFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand All @@ -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(
Expand All @@ -52,23 +54,15 @@ 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);

$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);
Expand All @@ -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(
Expand All @@ -111,29 +99,21 @@ 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);

$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()
);
Expand Down
83 changes: 17 additions & 66 deletions Tests/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down Expand Up @@ -57,25 +60,17 @@ 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);

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');
Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
21 changes: 6 additions & 15 deletions Tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Loading