directorytree/dummy
directorytree/dummy is a Laravel/PHP package providing a lightweight dummy/test utility for generating placeholder data and fixtures. Useful for local development, demos, and automated tests where realistic sample content is needed quickly and consistently.
Factory or Faker. The package’s HasFactory trait (v1.3.0+) enables stateful factories, critical for complex test scenarios (e.g., simulating failed payments, nested relationships).Arr helper (v1.3.1+) replaces older data_* helpers, aligning with Laravel’s modern conventions.orchestra/testbench) make it a drop-in replacement for Laravel’s native factories in test suites.Dummy class can be adapted with minimal effort (e.g., replacing Arr::get() with array_key_first()).HasFactory trait and Arr helpers assume familiarity with Laravel’s factory pattern and collection utilities. Non-Laravel projects may require custom wrappers.fakerphp/faker (10K+ stars) or laravel/model-factory (Laravel-native).orchestra/testbench for Laravel integration tests, adding CI/CD complexity if not already in use.Factory::new()) or generic PHP fake data?fakerphp/faker (more generic, no Laravel ties, higher adoption).laravel/model-factory (Laravel-native, but heavier and tied to framework).mockery/mockery (for mock objects, not fake data).Factory or Fake?HasFactory?Factory?HasFactory?| Stack Component | Fit Level | Notes |
|---|---|---|
| Laravel 11/12/13 | ✅ Full | Native support for modern Laravel, including Arr helpers and HasFactory. |
| Laravel <11 | ⚠️ Partial | May require shims for Arr helpers or HasFactory. |
| Non-Laravel PHP | ⚠️ Partial | Core Dummy class works, but HasFactory and Arr helpers need adapters. |
| PestPHP | ✅ Full | Native support (dev dependency); ideal for Pest users. |
| PHPUnit | ✅ Partial | Works but lacks Laravel-specific features without testbench. |
| Symfony/Lumen | ⚠️ Partial | Possible with custom integration for HasFactory. |
| CI/CD (GitHub Actions, etc.) | ✅ Full | Lightweight; no major infrastructure changes needed. |
Assessment Phase:
Faker or Laravel’s Factory.fakerphp/faker, Laravel’s Factory).Pilot Integration:
// Before (Laravel Factory)
$user = User::factory()->create(['email' => 'test@example.com']);
// After (DirectoryTree/Dummy)
$user = Dummy::factory(User::class)->state(['email' => 'test@example.com']);
$user = Dummy::factory(User::class)->state(['role' => 'admin'])->create();
Dependency Updates:
composer.json:
"require-dev": {
"directorytree/dummy": "^2.0",
"orchestra/testbench": "^9.0" // Only if using Laravel tests
}
phpunit.xml or pest.php to recognize HasFactory:
<!-- Example for PHPUnit -->
<php>
<env name="APP_ENV" value="testing"/>
<autoLoad>
<classmap>
<prefix>DirectoryTree\Dummy</prefix>
</classmap>
</autoLoad>
</php>
Refactoring:
Dummy::factory().HasFactory for dynamic states:
use DirectoryTree\Dummy\HasFactory;
class User extends Model {
use HasFactory;
}
data_* helpers with Arr::* (v1.3.1+):
// Before
$value = data_get($array, 'user.name');
// After
$value = Arr::get($array, 'user.name');
Dummy for mock data.CI/CD Adjustments:
testbench and pest are compatible with your CI (e.g., GitHub Actions)."scripts": {
"test:factories": "php artisan dummy:test" // Hypothetical command
}
| Feature | Laravel 11 | Laravel 12 | Laravel 13 | Non-Laravel PHP | Notes |
|---|---|---|---|---|---|
| Basic Factory Usage | ✅ | ✅ |
How can I help you explore Laravel packages today?