prewk/xml-faker
Generate fake XML easily for tests and demos with prewk/xml-faker. Define elements and attributes, create realistic sample documents fast, and avoid hand-writing fixtures. Lightweight helper for PHP projects that need quick XML payloads.
prewk/xml-faker package leverages Fzaninotto/Faker to generate fake XML data, making it ideal for:
Http::fake(), Mockery) and Faker integration (via laravel/faker).php-soap or XML parsers like SimpleXMLElement).Fzaninotto/Faker (v1.4+), which is compatible with Laravel’s fakerphp/faker (v1.9+).spatie/array-to-xml (for complex transformations).phpunit/phpunit (for test assertions).use Prewk\XmlFaker\XmlFaker;
$xmlFaker = new XmlFaker();
$fakeXml = $xmlFaker->fake('{{<root>{{<user>{{name|Faker\Name::name}}</user>}}</root>}}');
// In DatabaseSeeder.php
$xml = (new XmlFaker())->fake('{{<catalog>{{<product>{{name|Faker\Commerce::productName}}</product>}}</catalog>}}');
File::put(database_path('fake_data.xml'), $xml);
// In a test
Http::fake(fn ($request) => Http::response($xmlFaker->fake('{{<response>{{<data|Faker\Lorem::word}}</data>}}</response>'), 200));
XmlFaker to support Laravel-specific data (e.g., Faker\Provider\Laravel).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Schema Complexity | Medium | Validate generated XML against XSD schemas. |
| Performance | Low | Benchmark bulk generation; cache templates. |
| Dependency Conflicts | Low | Pin Faker version in composer.json. |
| Lack of Laravel Hooks | Medium | Build custom facade/service provider. |
| Maintenance | Low | MIT license; active fork if upstream stalls. |
spatie/array-to-xml or simplexml_load_string() with Faker achieve the same goals with less overhead?DatabaseSeeder, Model factories, or Laravel\Sanctum for API testing.Http::fake() or Mockery tests.fakerphp/faker (v1.9+).SimpleXMLElement or DOMDocument.XmlFaker in a feature branch.products.xml to dynamic generation.XmlFakerService) to wrap the package.composer.json:
"require-dev": {
"prewk/xml-faker": "^1.0",
"fakerphp/faker": "^1.9"
}
| Component | Compatibility Notes |
|---|---|
| Laravel 8+ | Full support (uses Faker v1.9+). |
| Laravel 7 | May require downgrading Faker to v1.8 (check composer.json). |
| PHP 8.0+ | Recommended; PHP 7.4 may need polyfills for Faker. |
| SOAP/XML APIs | Works with php-soap or guzzlehttp/guzzle for XML payloads. |
| Database Seeders | Can generate XML files for import (e.g., via Artisan::call('db:seed')). |
| Third-Party XML Tools | May conflict with tools like spatie/array-to-xml; evaluate overlap. |
storage/app/fake_data.xml).post-update-cmd in composer.json to test XML generation after updates.Faker::debug() to inspect generated data.\Log::debug('XML Template:', ['template' => $xmlFaker->getTemplate()]);
prewk/xml-faker.Faker community for provider questions.SimpleXMLElement directly if the package fails.Faker::multiple() for batches.memory_limit; stream output if possible.php artisan tinker --execute='for ($i=0; $i<1000; $i++)
How can I help you explore Laravel packages today?