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

Ddd Test Laravel Package

aulasoftwarelibre/ddd-test

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require aulasoftwarelibre/ddd-test
    

    Ensure your Laravel project meets the PHP 7.2+ requirement and includes the listed dependencies (e.g., prooph/event-store, doctrine/collections).

  2. First Use Case: Domain Event Testing Extend the provided DomainEventTestCase in your test:

    use AulaSoftwareLibre\DDDTest\DomainEventTestCase;
    
    class MyDomainEventTest extends DomainEventTestCase
    {
        public function testEventSerialization()
        {
            $event = new MyDomainEvent(['key' => 'value']);
            $this->assertEventSerialization($event);
        }
    }
    
    • Where to look first: Browse src/DomainEventTestCase.php for built-in assertions like assertEventSerialization(), assertEventDeserialization(), and assertEventPublished().

Implementation Patterns

Core Workflows

  1. Domain Event Testing

    • Use DomainEventTestCase for Prooph Event Sourcing events.
    • Example: Verify event payloads, metadata, and serialization.
    $event = new OrderCreatedEvent($orderId, $customerId);
    $this->assertEventPublished($event, 'order_created');
    
  2. Aggregate Root Testing

    • Extend AggregateRootTestCase for Prooph aggregates.
    • Test state transitions and event emission:
    class OrderAggregateTest extends AggregateRootTestCase
    {
        public function testOrderCreation()
        {
            $order = new OrderAggregate($orderId);
            $order->create($customerId);
            $this->assertEventsEmitted($order, [
                new OrderCreatedEvent($orderId, $customerId)
            ]);
        }
    }
    
  3. Command/Query Testing

    • Use CommandTestCase and QueryTestCase for Symfony Messenger integration.
    • Mock handlers and verify dispatch:
    $command = new CreateOrderCommand($orderId, $customerId);
    $this->assertCommandHandled($command, CreateOrderHandler::class);
    

Integration Tips

  • Laravel-Specific: Pair with Laravel’s Mockery or PHPUnit for mocking services.
  • Event Store: Configure Prooph’s EventStore in config/prooph.php to match your test environment.
  • Assertions: Leverage php-matcher for custom assertions (e.g., nested object validation).

Gotchas and Tips

Pitfalls

  1. Dependency Conflicts

    • Prooph v5.6+ may conflict with Laravel’s Symfony components. Pin versions in composer.json:
      "prooph/event-sourcing": "5.6.*",
      "symfony/http-foundation": "4.4.*"
      
  2. Event Store Configuration

    • Tests assume an in-memory EventStore. For CI/CD, mock the store:
      $this->eventStore = $this->createMock(EventStore::class);
      
  3. Serialization Issues

    • Ensure events implement JsonSerializable or Arrayable. Use assertEventSerialization() to debug.

Debugging Tips

  • Event Dumping: Override DomainEventTestCase::dumpEvent() to log raw event data.
  • Handler Mocking: Use createMock() for Symfony Messenger handlers:
    $handler = $this->createMock(CreateOrderHandler::class);
    $this->messenger->setHandler($handler);
    

Extension Points

  1. Custom Assertions Add methods to DomainEventTestCase for project-specific rules:

    protected function assertCustomRule(Event $event)
    {
        $this->assertTrue($event->getPayload()['valid'] ?? false);
    }
    
  2. Test Traits Extract reusable logic into traits (e.g., AssertsEventMetadata):

    trait AssertsEventMetadata
    {
        protected function assertMetadata(Event $event, array $expected)
        {
            $this->assertEquals($expected, $event->getMetadata());
        }
    }
    
  3. Laravel Artisan Commands Test commands with ArtisanTestCase (if extended):

    $this->artisan('order:create', ['id' => 123])
         ->assertExitCode(0);
    
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor