Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Test Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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());
    }
}

Implementation Patterns

  • Bulk Mock Setup: Replace chains of ->willReturn() with a single call:
    $httpClient = $this->createMock(HttpClient::class);
    TestHelper::assignMockReturns($httpClient, $this, [
        'get' => '{"status":"ok"}',
        'post' => '{"id":123}',
    ]);
    
  • Targeted Reflection for Legacy Code: When refactoring tightly-coupled classes where refactoring for test seams isn’t feasible, use TestHelper::invoke() for protected methods:
    $taxCalculator = new TaxCalculator();
    $amount = TestHelper::invoke($taxCalculator, 'calculateByRegion', 'CA', 100.0);
    $this->assertEquals(108.0, $amount);
    
  • Base TestCase Extension: DRY up repeated access patterns:
    abstract class TestCase extends BaseTestCase
    {
        protected function getProtected(object $object, string $property): mixed
        {
            return TestHelper::getValue($object, $property);
        }
    }
    

Gotchas and Tips

  • PHP Version Compatibility: v4+ requires PHP 8.3+ and PHPUnit 12. Using v3 on PHP 8.1–8.2 may break if you rely on deprecated setAccessible()—patch versions like 4.0.1 fix this. Always lock: "joomla/test": "^4.0"
  • Reflection Overuse Alert: getValue()/setValue() indicate missing test seams. Use sparingly—prefer injecting dependencies or introducing protected hooks over poking internal state.
  • No Modern DI Integration: This is a procedural helper, not DI-friendly. Don’t try to mock or extend TestHelper; it’s not designed for that.
  • Minimal Maintenance Footprint: The package has 0 dependents and few contributors. Accept it as stable but static—expect only PHP compatibility patches (e.g., 4.0.1 for PHP 8.5 deprecations), not new features.
  • Redundancy Check: If you’re on modern PHPUnit (≥9.5), many 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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport