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

Tests Bundle Laravel Package

blast-project/tests-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require blast-project/tests-bundle
    

    Add the bundle to your config/bundles.php:

    return [
        // ...
        Blast\TestsBundle\TestsBundle::class => ['test' => true],
    ];
    
  2. First Test Class: Extend BlastTestCase in your test file (located in tests/Functional/ or similar):

    use Blast\TestsBundle\Functional\BlastTestCase;
    
    class MyServiceTest extends BlastTestCase
    {
        public function testServiceInitialization()
        {
            $this->isServicesAreInitializable('blast'); // Checks if services prefixed with 'blast' are loadable
        }
    }
    
  3. Run Tests:

    php bin/phpunit
    

Key First-Use Cases

  • Service Validation: Quickly verify if services (e.g., blast.*) are autowired and functional.
  • Kernel Bootstrapping: Leverage Symfony’s KernelTestCase for HTTP/container testing with Blast-specific shortcuts.

Implementation Patterns

Core Workflows

  1. Service Initialization Checks: Use isServicesAreInitializable() to validate service autowiring for a given prefix (e.g., blast.*).

    $this->isServicesAreInitializable('blast', ['blast.command.*']); // Exclude specific services
    
  2. HTTP Test Integration: Combine with Symfony’s Client for API testing:

    public function testApiEndpoint()
    {
        $client = static::createClient();
        $response = $client->request('GET', '/api/endpoint');
        $this->assertEquals(200, $response->getStatusCode());
    }
    
  3. Database Transactions: Override setUp() to enable transactions:

    protected function setUp(): void
    {
        parent::setUp();
        $this->enableTransactions();
    }
    
  4. Custom Assertions: Extend BlastTestCase to add domain-specific assertions:

    protected function assertServiceHasMethod($serviceId, $method)
    {
        $service = $this->getService($serviceId);
        $this->assertTrue(method_exists($service, $method));
    }
    

Integration Tips

  • Dependency Injection: Access services via $this->getService('blast.service') (wrapped by the bundle).
  • Configuration Testing: Use static::getContainer()->getParameter('blast.config') to validate config values.
  • Event Dispatching: Test event listeners by dispatching events in tests:
    $this->getService('event_dispatcher')->dispatch(new BlastEvent());
    

Gotchas and Tips

Pitfalls

  1. Service Prefix Mismatch:

    • isServicesAreInitializable() defaults to blast.*. Explicitly pass the correct prefix:
      $this->isServicesAreInitializable('app.*'); // Not 'blast.*'
      
    • Fix: Use ['prefix' => 'custom.'] as the second argument.
  2. Transaction Isolation:

    • enableTransactions() rolls back after each test. For multi-test scenarios, disable it:
      $this->disableTransactions();
      
  3. Kernel Caching:

    • Clear cache between tests if services behave inconsistently:
      $this->getKernel()->getContainer()->get('kernel')->clearContainer();
      
  4. Missing Readme:

    • The package lacks detailed docs. Refer to src/Functional/BlastTestCase.php for undocumented methods.

Debugging Tips

  • Service Dump: Inspect loaded services with:
    $this->dumpServices(); // Lists all services (debug:dump-service)
    
  • Container Dump: Dump container parameters:
    $this->dumpContainerParameters();
    

Extension Points

  1. Custom Assertions: Override BlastTestCase to add methods like:

    protected function assertBlastConfigValid()
    {
        $config = $this->getParameter('blast.config');
        $this->assertArrayHasKey('required_key', $config);
    }
    
  2. Pre-Test Hooks: Extend setUp() to inject test data:

    protected function setUp(): void
    {
        parent::setUp();
        $this->loadFixtures([__DIR__.'/fixtures/blast.yml']);
    }
    
  3. Post-Test Cleanup: Override tearDown() to reset state:

    protected function tearDown(): void
    {
        $this->clearDatabase(); // Hypothetical method
        parent::tearDown();
    }
    

Config Quirks

  • No Default Configuration: The bundle doesn’t introduce config files. All behavior is code-driven (e.g., isServicesAreInitializable()).
  • Symfony Version Compatibility: Tested with Symfony 5.x/6.x. For older versions, check composer.json constraints.
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.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium