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 Bundle Laravel Package

axstrad/test-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add to composer.json under require-dev:

    "axstrad/test-bundle": "dev-main"
    

    Run composer update axstrad/test-bundle --dev.

  2. Enable the Bundle Register in config/bundles.php:

    Axstrad\TestBundle\AxstradTestBundle::class => ['dev' => true, 'test' => true],
    
  3. First Use Case Use the TestCase base class for functional tests:

    use Axstrad\TestBundle\Test\WebTestCase;
    
    class MyBundleTest extends WebTestCase
    {
        public function testSomething()
        {
            $client = static::createClient();
            $client->request('GET', '/some-route');
            $this->assertEquals(200, $client->getResponse()->getStatusCode());
        }
    }
    

Implementation Patterns

Common Workflows

  1. Dependency Injection for Testing Override services in config/packages/test/axstrad_test.yaml:

    services:
        _defaults:
            bind:
                App\Service\MyService: '@Axstrad\TestBundle\Test\MockMyService'
    
  2. Database Testing Use the DatabaseTestCase for DB-aware tests:

    use Axstrad\TestBundle\Test\DatabaseTestCase;
    
    class UserRepositoryTest extends DatabaseTestCase
    {
        protected function getDatabaseConfig()
        {
            return [
                'driver'   => 'pdo_sqlite',
                'memory'   => true,
            ];
        }
    }
    
  3. Mocking External Services Leverage the MockBuilder trait:

    use Axstrad\TestBundle\Test\MockBuilder;
    
    class PaymentServiceTest extends WebTestCase
    {
        use MockBuilder;
    
        public function testPayment()
        {
            $this->mockService('payment.gateway', function ($mock) {
                $mock->method('charge')->willReturn(true);
            });
        }
    }
    

Integration Tips

  • Symfony Kernel Integration Extend AxstradTestBundle to add custom test utilities:

    namespace App\Tests;
    
    use Axstrad\TestBundle\AxstradTestBundle;
    
    class AppTestBundle extends AxstradTestBundle
    {
        public function load(array $config)
        {
            // Custom test configurations
        }
    }
    
  • PHPUnit Configuration Add to phpunit.xml.dist:

    <php>
        <env name="KERNEL_CLASS" value="App\Kernel"/>
        <env name="APP_ENV" value="test"/>
    </php>
    

Gotchas and Tips

Pitfalls

  1. Bundle Version Mismatch The package targets Symfony 2.3 and PHPUnit 4.1. Ensure compatibility:

    composer require symfony/symfony:^2.3 --dev
    
  2. Database Isolation SQLite in-memory DBs (default) do not persist between tests. Use transactions or fixtures:

    protected function setUp()
    {
        $this->loadFixtures(['user.yml']);
    }
    
  3. Service Overrides Overrides in axstrad_test.yaml must match the exact service ID. Use:

    php bin/console debug:container | grep "payment.gateway"
    

Debugging Tips

  • Enable Debug Mode Set APP_DEBUG=1 in .env.testing for detailed error logs.

  • Test Case Isolation Clear caches between test suites:

    public static function tearDownAfterClass()
    {
        self::bootKernel();
        self::$kernel->getContainer()->get('cache')->clear();
    }
    

Extension Points

  1. Custom Test Traits Extend AxstradTestBundle to add reusable traits:

    namespace Axstrad\TestBundle\Test;
    
    trait AssertionHelpers
    {
        protected function assertJsonResponse($client, $expected)
        {
            $this->assertEquals($expected, json_decode($client->getResponse()->getContent(), true));
        }
    }
    
  2. Event Listeners Add test-specific listeners in config/packages/test/axstrad_test.yaml:

    services:
        app.test.event_listener:
            class: App\Tests\EventListener\TestListener
            tags:
                - { name: kernel.event_listener, event: kernel.test, method: onKernelTest }
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware