- How do I install lastdragon-ru/phpunit-xml in a Laravel project?
- Run `composer require lastdragon-ru/phpunit-xml --dev` in your project root. The package is designed as a PHPUnit extension, so no additional Laravel service provider or config is needed—just require it in your test classes.
- Does this package support Laravel’s testing helpers (e.g., $this->assertDatabaseHas) alongside XML assertions?
- Yes, it integrates seamlessly with Laravel’s testing tools. Use it alongside `assertDatabaseHas` or `assertJson` in the same test class, as it’s a standalone PHPUnit extension with no Laravel-specific dependencies.
- Can I validate XML schemas (XSD) with this package, or is it just for basic XML structure checks?
- This package supports XML schema validation (XSD) out of the box, unlike PHPUnit’s native `assertXmlFileEqualsXmlFile`. It’s designed for rigorous schema compliance checks, making it ideal for SOAP APIs or config files with strict validation rules.
- Will this work with Laravel’s Pest testing framework?
- No, this package is built for PHPUnit only. Pest uses a different assertion system, so you’d need to either stick with PHPUnit or explore alternatives like `spatie/laravel-pest` for Pest-specific XML validation.
- How do I handle large XML files (e.g., 50MB+) in tests without memory issues?
- The package isn’t optimized for streaming or async validation of massive XML files. For large files, pre-process them with tools like `xmllint` or use PHP’s `XMLReader` in a separate step before assertions. Test with smaller subsets first.
- Can I use this to validate XML responses from Guzzle HTTP clients in Laravel?
- Absolutely. After making a Guzzle request, extract the XML response (e.g., `$response->getBody()->getContents()`) and pass it to the package’s assertions like `assertXmlStringMatchesSchema()`. Works great for SOAP or XML-based APIs.
- Does this package support Laravel’s service container for runtime XML validation outside tests?
- No, it’s strictly for PHPUnit tests. For runtime validation, bind a custom service (e.g., `XMLValidator`) using Laravel’s container and leverage libraries like `SimpleXML` or `DOMDocument` instead.
- How do I migrate from PHPUnit’s native XML assertions to this package?
- Replace `assertXmlFileEqualsXmlFile()` with `assertXmlFileMatchesSchema()` or `assertXmlStringMatchesSchema()` for schema validation. The package offers a more fluent API, so refactor tests incrementally—start with critical XML checks first.
- Is there a way to generate or modify phpunit.xml dynamically using this package?
- Yes, the package includes tools to parse, build, and validate `phpunit.xml` files programmatically. Use `XmlConfigBuilder` to construct configs dynamically, which is useful for CI/CD pipelines or multi-environment setups.
- What Laravel versions and PHPUnit versions does this package support?
- The package requires PHPUnit ≥8.0 (compatible with Laravel 8+). It has no Laravel-specific dependencies, so it works as long as your project uses PHPUnit. Check the package’s `composer.json` for exact PHPUnit version constraints.