Weave 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

Hexagonal Maker Bundle Laravel Package

ahmed-bhs/hexagonal-maker-bundle

View on GitHub
Deep Wiki
Context7

layout: default title: Testing Guide parent: Examples nav_order: 3

Testing Examples

Examples of testing hexagonal architecture with generated tests.


Generate Tests

# With command
bin/console make:hexagonal:command blog/post create --with-tests

# Standalone
bin/console make:hexagonal:use-case-test blog/post CreatePost
bin/console make:hexagonal:controller-test blog/post CreatePost /posts/new

Unit Test Example

<?php

namespace Tests\Blog\Post\Application\Create;

use PHPUnit\Framework\TestCase;

final class CreatePostHandlerTest extends TestCase
{
    public function testCreatesPost(): void
    {
        $repository = $this->createMock(PostRepositoryInterface::class);
        $repository->expects($this->once())->method('save');

        $handler = new CreatePostHandler($repository);
        $command = new CreatePostCommand('Title', 'Content');

        $handler($command);
    }
}

Integration Test Example

<?php

namespace Tests\Blog\Post\Application\Create;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

final class CreatePostIntegrationTest extends KernelTestCase
{
    public function testCreatesPostInDatabase(): void
    {
        self::bootKernel();

        $commandBus = static::getContainer()->get(MessageBusInterface::class);
        $command = new CreatePostCommand('Title', 'Content');

        $commandBus->dispatch($command);

        $repository = static::getContainer()->get(PostRepositoryInterface::class);
        $posts = $repository->findAll();

        $this->assertCount(1, $posts);
    }
}

Run Tests

vendor/bin/phpunit

See generated test files for complete examples.

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.
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table