-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Testing
BOUNDLY embraces a robust Domain-Driven Design testing strategy by moving away from traditional frameworks' tests/Feature monolithic directories and bringing tests directly to the Domain layer where the logic lives.
To achieve this, the framework generates tests automatically based on your Entity definitions.
To generate test stubs for all discovered Domain entities, simply run:
php artisan core:make:test-
Intelligent Payload Mocking: BOUNDLY inspects every
#[Column]defined in your Entity. It parses the types (integer,boolean,date,email) and creates a valid mock payload automatically in the test file. -
Path Generation: It reads your Entity namespace and places the generated test file right next to it in a
Tests/directory:- Example:
Domain/Users/Entities/User.php→Domain/Users/Tests/UserApiTest.php
- Example:
Since the tests are generated in Domain/ (and potentially Application/), BOUNDLY updates your root phpunit.xml out-of-the-box to detect these directories.
To run the full suite:
php artisan testStandard Laravel tests rely on checking standard migration classes to recreate the test database (often using :memory: SQLite databases). Because BOUNDLY uses PHP Attributes instead of migration files, standard Laravel testing traits are useless.
This is solved by having all tests extend Infrastructure\FrameworkCore\Testing\BoundlyTestCase.
When you use BoundlyTestCase, before each test runs:
- It connects to your
testingdatabase connection (likesqlite :memory:). - It internally invokes
php artisan core:migratebehind the scenes. - BOUNDLY dynamically translates all your
#[Entity]and#[Column]metadata into real SQLite tables in milliseconds. - Your endpoints execute using a fully configured database schema perfectly synchronized to your entity code.
If your entity uses the #[Authorize] attribute, requests made in test environments will naturally return 401 Unauthorized or 403 Forbidden if there is no user authenticated.
To bypass authorization during unit tests that only focus on the generic entity CRUD, the auto-generated test stub includes commented-out code to disable the middleware:
// Uncomment to disable RBAC during CRUD tests:
// $this->withoutMiddleware(\Infrastructure\FrameworkCore\Http\Middleware\ResourceAuthorize::class);Alternatively, you can authenticate a dummy user using Laravel's standard standard helper:
$user = \Domain\Users\Entities\User::first();
$this->actingAs($user);Next Step: Roadmap 🚀