joomla/test
A small Joomla Framework utility package that streamlines PHPUnit unit testing. Provides a TestHelper with bulk mock configuration (callbacks and canned return values) plus reflection helpers to reduce repetitive test setup and access internals when needed.
Install joomla/test as a dev dependency with Composer:
composer require --dev joomla/test "^4.0"
Then import Joomla\Test\TestHelper in your test classes and start using its static methods to reduce boilerplate. Your first practical use case: accessing private/protected state in legacy classes during testing:
use Joomla\Test\TestHelper;
class UserServiceTest extends TestCase
{
public function testCanReadHiddenConfig(): void
{
$user = new UserService();
TestHelper::setValue($user, 'config', ['timezone' => 'UTC']);
$this->assertEquals('UTC', $user->getTimezone());
}
}
->willReturn() with a single call:
$httpClient = $this->createMock(HttpClient::class);
TestHelper::assignMockReturns($httpClient, $this, [
'get' => '{"status":"ok"}',
'post' => '{"id":123}',
]);
TestHelper::invoke() for protected methods:
$taxCalculator = new TaxCalculator();
$amount = TestHelper::invoke($taxCalculator, 'calculateByRegion', 'CA', 100.0);
$this->assertEquals(108.0, $amount);
abstract class TestCase extends BaseTestCase
{
protected function getProtected(object $object, string $property): mixed
{
return TestHelper::getValue($object, $property);
}
}
setAccessible()—patch versions like 4.0.1 fix this. Always lock: "joomla/test": "^4.0"getValue()/setValue() indicate missing test seams. Use sparingly—prefer injecting dependencies or introducing protected hooks over poking internal state.TestHelper; it’s not designed for that.4.0.1 for PHP 8.5 deprecations), not new features.TestHelper functions have native equivalents (assertAttribute*, createStub() with willReturnMap). Use this package only if you already need bulk config helpers and have legacy Joomla code.How can I help you explore Laravel packages today?