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.
HasFactory trait integration (v1.3.0+) aligns with Laravel’s testing conventions, making it a natural extension for Laravel applications needing dynamic test data. The removal of Laravel as a hard dependency (v1.1.0+) ensures backward compatibility with non-Laravel PHP projects, though with reduced feature parity.HasFactory) to enable stateful, reusable test data generation, which is critical for complex test scenarios (e.g., nested relationships, conditional states). This reduces boilerplate compared to manual DB::table()->insert() calls or static seeders.Arr helper optimizations (v1.3.1+) improve performance and consistency with Laravel’s collection utilities.Factory class.Artisan or ServiceProvider, making it easy to integrate into existing projects. This is ideal for legacy systems or monorepos with mixed tech stacks.withPassword(), hasRoles()), reducing the learning curve for teams familiar with Laravel’s Eloquent factories.pestphp/pest and orchestra/testbench, indicating first-class support for Laravel’s modern testing tools. This reduces friction for teams already using these frameworks.HasFactory and Arr helpers assume familiarity with Laravel’s factory pattern and collection utilities. Non-Laravel projects may need custom adapters or wrapper classes to achieve equivalent functionality.
Factory or fakerphp/faker. Teams using PHPUnit (without Testbench) may face additional setup complexity.
stateAsAdmin(), stateAsGuest()) and isolate stateful factories in dedicated test modules.Factory::new()) or generic PHP fake data generation?Factory: More integrated but heavier.fakerphp/faker: More generic, no Laravel ties.mockery/mockery: For mock objects, not fake data.Fake or DatabaseMigrations?HasFactory?| Stack Component | Fit Level | Notes |
|---|---|---|
| Laravel 11/12/13 | ✅ Excellent | Full feature parity, including HasFactory and Arr helpers. |
| Non-Laravel PHP | ⚠️ Partial | Works for basic fake data, but HasFactory and Arr require adapters. |
| PestPHP | ✅ Excellent | Native support (dev dependency). |
| PHPUnit | ✅ Good | Works, but testbench adds Laravel-specific features. |
| Symfony/Lumen | ⚠️ Limited | Possible with custom wrappers for HasFactory and Arr. |
| **Legacy Laravel (<11) | ❌ Poor | May require helper shims or feature flags. |
Assessment Phase:
fakerphp/faker, Laravel’s Factory) for performance and flexibility.Pilot Integration:
composer.json and test basic factory usage in a non-critical module.
composer require directorytree/dummy --dev
UserFactory) with Dummy-powered dynamic factories.
use DirectoryTree\Dummy\Dummy;
use App\Models\User;
$dummy = new Dummy();
$user = $dummy->make(User::class, ['name' => 'Test User']);
Dependency Updates:
composer.json:
"require-dev": {
"directorytree/dummy": "^1.5",
"orchestra/testbench": "^9.0", // Only if using Laravel tests
"pestphp/pest": "^2.0" // If migrating from PHPUnit
}
phpunit.xml or pest.php to recognize HasFactory traits.Refactoring:
Dummy for basic data generation.HasFactory for stateful factories (e.g., User::factory()->stateAsAdmin()).data_get() calls with Arr::get() (v1.3.1+).CI/CD Adjustments:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- run: composer install
- run: composer test # Runs PestPHP or PHPUnit
How can I help you explore Laravel packages today?