beapp/repository-tester-core
AppKernel, configuration). Risk: Version conflicts with existing Doctrine/Symfony versions.RepositoryTester) into Eloquent-compatible assertions. Example:
// Custom facade for Laravel
class RepositoryTesterFacade {
public static function assertQueryCount($repository, $method, $expected) {
// Use Laravel’s query logging or DB::assertQueryCount() equivalent
}
}
RepositoryTester::create()) cannot be directly used in Eloquent.DatabaseMigrations, RefreshDatabase) may overlap or conflict with the bundle’s transactional fixtures.| Risk Area | Severity (Symfony) | Severity (Laravel) | Mitigation Strategy |
|---|---|---|---|
| Version Conflicts | Medium | High | Lock Doctrine/Symfony versions in composer.json; use platform.sh or Docker for isolation. |
| Abstraction Overhead | Low | High | Invest in a facade layer or avoid adoption. |
| Testing Duplication | Low | Medium | Audit existing Laravel test utilities (e.g., PestPHP plugins, Laravel Debugbar). |
| Maintenance Burden | Low | High | Assign ownership to a Symfony specialist. |
| Performance Impact | Low | Low | Benchmark repository tests post-integration. |
| Component | Symfony Fit | Laravel Fit | Notes |
|---|---|---|---|
| Dependency Injection | Native | Partial | Laravel’s container can load Symfony bundles via symfony/flex, but requires configuration. |
| Doctrine ORM | Native | Low | Eloquent is not Doctrine; requires abstraction or dual-maintenance. |
| Testing Framework | PHPUnit/Pest | PHPUnit/Pest | Compatible, but assertions may need custom wrappers. |
| Configuration | Bundle-based | Manual | Laravel lacks Symfony’s AppKernel; may need custom service providers. |
composer require beapp/repository-tester-core
config/bundles.php.config/packages/test/doctrine.yaml.use BeApp\RepositoryTesterCore\RepositoryTester;
public function testUserRepository() {
$repository = self::$container->get('doctrine')->getRepository(User::class);
RepositoryTester::create()
->assertQueryCount($repository, 'findAll', 5)
->assertQuery($repository, 'findByEmail', 'SELECT ... WHERE email = ?');
}
RepositoryTester facade in app/Testing/RepositoryTester.php:
namespace App\Testing;
use Doctrine\ORM\EntityManagerInterface;
use Illuminate\Database\Eloquent\Model;
class RepositoryTester {
public static function assertQueryCount($repository, string $method, int $expected) {
$repository->{$method}();
// Use Laravel’s DB::assertQueryCount() or query logging.
}
}
| Feature | Symfony Support | Laravel Workaround |
|---|---|---|
| Transactional fixtures | ✅ Native | ✅ RefreshDatabase or DatabaseTransactions |
| Query assertion DSL | ✅ Custom | ❌ Manual (e.g., DB::enableQueryLog()) |
| Performance benchmarking | ✅ Built-in | ✅ Laravel Debugbar or custom timing |
| Mocking repository dependencies | ✅ Easy | ✅ Laravel’s Mockery or createMock() |
## Repository Testing with Laravel
To test `UserRepository::findActiveUsers()`, use:
```php
RepositoryTester::assertQueryCount(
app(UserRepository::class),
'findActiveUsers',
10
);
How can I help you explore Laravel packages today?