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

Use Case Test Bundle Laravel Package

axstrad/use-case-test-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require axstrad/use-case-test-bundle
    

    Ensure your composer.json includes the required dev dependencies (e.g., liip/functional-test-bundle, phpunit/phpunit).

  2. Bundle Registration Add the bundle to your AppKernel.php under test environment:

    if (in_array($this->getEnvironment(), ['test'], true)) {
        $bundles[] = new Axstrad\UseCaseTestBundle\AxstradUseCaseTestBundle();
    }
    
  3. First Use Case Create a test class extending Axstrad\UseCaseTestBundle\Test\WebTestCase:

    use Axstrad\UseCaseTestBundle\Test\WebTestCase;
    
    class MyBundleTest extends WebTestCase
    {
        public function testUserCreationUseCase()
        {
            $this->loadFixtures(['path/to/fixtures']);
            $this->client->request('POST', '/register', [
                'user' => ['email' => 'test@example.com', 'password' => 'secret']
            ]);
            $this->assertTrue($this->client->getResponse()->isSuccessful());
        }
    }
    
  4. Key Configuration Check config/packages/axstrad_use_case_test.yaml for default settings (e.g., fixture paths, client defaults).


Implementation Patterns

Workflow: Use Case-Driven Testing

  1. Define Use Cases Group tests by business logic (e.g., UserRegistrationUseCase, OrderProcessingUseCase). Use traits or base classes for shared setup:

    trait UserRegistrationTrait
    {
        protected function registerUser(array $data)
        {
            $this->client->request('POST', '/register', $data);
            return $this->client->getResponse();
        }
    }
    
  2. Fixture Management Load fixtures per use case to isolate test data:

    protected function setUp(): void
    {
        $this->loadFixtures([
            'user_fixtures.yml',
            'product_fixtures.yml'
        ]);
    }
    
  3. Client Configuration Reuse client setup across tests:

    protected function createAuthenticatedClient()
    {
        $client = static::createClient();
        $client->loginUser($this->createTestUser());
        return $client;
    }
    
  4. Integration with Symfony Components Combine with Sensio\Bundle\FrameworkExtraBundle for routing/parameter testing:

    $this->assertRouteSame('app_register', $this->client->getRequest());
    
  5. Test Data Factories Use Axstrad\Common factories (if available) for dynamic test data:

    $user = $this->factory->create(User::class, ['email' => 'dynamic@example.com']);
    

Gotchas and Tips

Pitfalls

  1. Symfony 2.3 Dependency

    • The package targets Symfony 2.3. Ensure your AppKernel and dependencies align (e.g., Doctrine ORM 2.3).
    • Fix: Use a compatible Symfony monorepo branch or vendor patches.
  2. Fixture Loading Quirks

    • Fixtures may not load due to missing doctrine/orm or doctrine-fixtures-bundle config.
    • Tip: Verify config/packages/doctrine.yaml includes:
      doctrine:
          dbal:
              driver: 'pdo_sqlite'
              memory: true
      
  3. Client State Persistence

    • Functional tests may fail if the client state (e.g., cookies) isn’t reset between tests.
    • Solution: Extend WebTestCase and override setUp():
      protected function setUp(): void
      {
          parent::setUp();
          $this->client->getContainer()->get('session')->invalidate();
      }
      
  4. Archived Package Risks

    • No active maintenance; fork or patch if issues arise.
    • Mitigation: Check for open issues or create a fork with updates (e.g., PHP 7.4+ support).

Debugging Tips

  1. Enable Debug Mode Set APP_DEBUG=1 in .env.test to see detailed errors.

  2. Log Fixture Loading Add debug output in setUp():

    $this->logger->debug('Loaded fixtures:', ['fixtures' => $this->fixtures]);
    
  3. Isolate Tests Use @group annotations to run specific use cases:

    /**
     * @group user-registration
     */
    public function testRegistrationFlow()
    

Extension Points

  1. Custom Test Cases Extend WebTestCase to add domain-specific helpers:

    class ApiTestCase extends WebTestCase
    {
        protected function assertApiSuccess($response)
        {
            $this->assertEquals(200, $response->getStatusCode());
            $this->assertJson($response->getContent());
        }
    }
    
  2. Hook into Fixture Pipeline Override loadFixtures() to add pre/post-processing:

    protected function loadFixtures(array $fixtures)
    {
        $this->preprocessFixtures($fixtures);
        parent::loadFixtures($fixtures);
    }
    
  3. Mock External Services Use Symfony’s HttpClient or Psr\Http\Client to mock APIs:

    $this->client->getContainer()->set('payment_gateway', $this->createMock(PaymentGateway::class));
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui