Skip to content
Merged
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
43 changes: 15 additions & 28 deletions Tests/AbstractControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
use Joomla\Application\AbstractApplication;
use Joomla\Controller\AbstractController;
use Joomla\Input\Input;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;

/**
* Tests for the Joomla\Controller\AbstractController class.
*/
#[CoversClass(AbstractController::class)]
class AbstractControllerTest extends TestCase
{
/**
* Object being tested
*
* @var MockObject|AbstractController
* @var AbstractController
*/
private $instance;

Expand All @@ -35,53 +37,37 @@ protected function setUp(): void
$this->instance = new TestController();
}

/**
* @testdox Tests the controller is instantiated correctly
*
* @covers Joomla\Controller\AbstractController
*/
#[TestDox('Tests the controller is instantiated correctly')]
public function test__constructDefaultBehaviour()
{
$this->assertNull($this->instance->getApplication());
$this->assertNull($this->instance->getInput());
}

/**
* @testdox Tests the controller is instantiated correctly
*
* @covers Joomla\Controller\AbstractController
*/
#[TestDox('Tests the controller is instantiated correctly')]
public function test__constructDependencyInjection()
{
$mockInput = $this->createMock(Input::class);
$mockApp = $this->createMock(AbstractApplication::class);
$object = new TestController($mockInput, $mockApp);
$mockInput = $this->createStub(Input::class);
$mockApp = $this->createStub(AbstractApplication::class);
$object = new TestController($mockInput, $mockApp);

$this->assertSame($mockApp, $object->getApplication());
$this->assertSame($mockInput, $object->getInput());
}

/**
* @testdox Tests an application object is injected into the controller and retrieved correctly
*
* @covers Joomla\Controller\AbstractController
*/
#[TestDox('Tests an application object is injected into the controller and retrieved correctly')]
public function testSetAndGetApplication()
{
$mockApp = $this->createMock(AbstractApplication::class);
$mockApp = $this->createStub(AbstractApplication::class);

$this->assertSame($this->instance, $this->instance->setApplication($mockApp), 'The setApplication method has a fluent interface');
$this->assertSame($mockApp, $this->instance->getApplication());
}

/**
* @testdox Tests an input object is injected into the controller and retrieved correctly
*
* @covers Joomla\Controller\AbstractController
*/
#[TestDox('Tests an input object is injected into the controller and retrieved correctly')]
public function testSetAndGetInput()
{
$mockInput = $this->createMock(Input::class);
$mockInput = $this->createStub(Input::class);

$this->assertSame($this->instance, $this->instance->setInput($mockInput), 'The setInput method has a fluent interface');
$this->assertSame($mockInput, $this->instance->getInput());
Expand All @@ -96,7 +82,8 @@ public function testSetAndGetInput()
* @package Joomla\Controller\Tests
* @since 1.0
*/
class TestController extends AbstractController {
class TestController extends AbstractController
{
public function execute()
{
// TODO: Implement execute() method.
Expand Down
Loading