- Can I use directorytree/dummy to replace Laravel’s built-in Factory class for test data?
- Yes, the package integrates with Laravel’s `HasFactory` trait (v1.3.0+) and mimics Eloquent factory syntax, making it a drop-in alternative. It’s lighter than Laravel’s native Factory but lacks some built-in Laravel-specific features like model events or observers. For pure test data generation, it’s a solid choice.
- How do I install directorytree/dummy in a Laravel project?
- Run `composer require directorytree/dummy` in your project root. No Laravel service provider or Artisan command is required—just use the factory classes directly. For Laravel models, add the `HasFactory` trait to leverage Laravel’s factory conventions.
- Does directorytree/dummy work with Laravel 13, or should I stick to Laravel’s native Factory?
- The package explicitly supports Laravel 11, 12, and 13 (v1.2.0–v1.4.0). If you’re on Laravel 13, it’s fully compatible, but weigh whether you need Laravel-specific features like model events. For generic test data, this package is a lightweight alternative.
- Can I generate nested relationships (e.g., a User with multiple Posts) with this package?
- Yes, the package supports nested factory definitions via method chaining (e.g., `Post::factory()->for(User::factory())`). Stateful factories (v1.3.0+) also allow conditional relationships, like `Post::factory()->stateAsPublished()->forAuthor()`.
- Is directorytree/dummy compatible with PestPHP or PHPUnit for testing?
- It works seamlessly with PestPHP (dev dependency included) and PHPUnit via Orchestra/Testbench. The syntax aligns with Laravel’s testing conventions, so you can use it in both frameworks without major adjustments. For PHPUnit-only projects, no extra setup is needed.
- How does directorytree/dummy handle production data vs. test data?
- This package is designed for test data only—it doesn’t include database migrations or production-safe seeding. For production, use Laravel migrations or seeders. The package’s focus is on generating consistent, disposable test fixtures.
- What’s the difference between directorytree/dummy and fakerphp/faker?
- While `fakerphp/faker` generates raw fake data (e.g., names, emails), this package builds on Faker to create full PHP class instances with relationships and states. It’s ideal for Laravel models, whereas Faker is more generic. Use Faker if you need standalone fake data.
- Can I use directorytree/dummy in a non-Laravel PHP project?
- Yes, the package is framework-agnostic (no Laravel core dependency since v1.1.0). However, Laravel-specific features like `HasFactory` or Arr helper optimizations won’t work. For non-Laravel use, treat it as a Faker wrapper for object generation.
- How do I create a stateful factory (e.g., a User with admin privileges)?
- Define states in your factory class using `state()` methods, like `stateAsAdmin()` or `stateAsGuest()`. Then call them during generation: `User::factory()->stateAsAdmin()`. Stateful factories (v1.3.0+) support conditional logic for complex test scenarios.
- Are there performance concerns with directorytree/dummy vs. Laravel’s Factory?
- The package is optimized for speed, especially with Arr helper improvements (v1.3.1+). For large-scale tests, it’s comparable to Laravel’s Factory but avoids some overhead like model event triggers. Benchmark in your CI pipeline to compare with your existing setup.