When to use
- When you want to ensure model relationships are correctly implemented.
- When you want to use Pest or PHPUnit for relationship testing.
- When you need to verify if the code matches a predefined relationship state.
Features
Pest Integration
Quickly register a full suite of relationship tests using RelationTestBridge::all().
use SchenkeIo\LaravelRelationManager\Pest\RelationTestBridge;
RelationTestBridge::all(
strict: true
);
You can also use fluent expectations:
it('has correct relations', function () {
expect(User::class)->toHasMany(Post::class);
});
PHPUnit Integration
Extend AbstractRelationTest to get automatic relationship verification.
namespace Tests\Feature;
use SchenkeIo\LaravelRelationManager\Phpunit\AbstractRelationTest;
class RelationshipTest extends AbstractRelationTest
{
protected bool $strict = true;
}
Manual Assertions
Use RelationTestTrait in your PHPUnit tests for manual assertions.
use SchenkeIo\LaravelRelationManager\Phpunit\RelationTestTrait;
class ModelRelationTest extends TestCase
{
use RelationTestTrait;
public function test_user_has_many_posts()
{
$this->assertModelHasMany(User::class, Post::class);
}
}
Converted and distributed by TomeVault — claim your Tome and manage your conversions.