Verifactu PHP ships with a comprehensive test suite covering models, serialization services, hash generation, XML signing, response parsing, QR generation, SOAP client creation, and live sandbox submissions. All tests are driven by PHPUnit 10 and are organized into clearly separated suites so you can run exactly the tests you need.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Eseperio/verifactu-php/llms.txt
Use this file to discover all available pages before exploring further.
Test Suite Overview
Tests live under thetests/ directory and are divided into three top-level groups:
phpunit.xml defines four named test suites:
| Suite | Directory / File | What It Tests |
|---|---|---|
Unit | tests/Unit/ | Models and services in isolation (no network) |
Services | tests/Unit/Services/ | Service-layer unit tests only |
Verifactu | ReadmeAltaExampleTest.php, ReadmeExamplesTest.php | Ensures README examples are always correct |
Integration | VerifactuSandboxTest.php | Live calls to the AEAT sandbox (requires certificate) |
Composer Test Commands
All test commands automatically check for a.env file and create one from .env.example if it is missing, displaying a warning if so.
| Command | What It Runs |
|---|---|
composer test | Full test suite (all suites) |
composer test-unit | Unit suite only — no network required |
composer test-sandbox | Integration suite — requires a configured .env certificate |
composer test-verifactu | README example tests and sandbox tests under tests/Verifactu/ |
composer coverage | Full suite with HTML coverage report written to var/coverage/html/ |
The
Integration suite (composer test-sandbox) makes real HTTPS calls to the AEAT homologation endpoint. You must supply a valid certificate and matching issuer details in .env. Tests skip automatically when the certificate configuration is absent or incomplete.Setting Up .env for Sandbox Tests
Copy the example environment file
The repository ships with If you run any
.env.example containing all required variable names. Copy it to .env in the project root:composer test* command without a .env present, the check-env Composer script creates it automatically from .env.example and prints a warning reminding you to configure it.Set your certificate details
Open
.env and fill in your certificate path and password. For sandbox tests, point to a certificate accepted by the AEAT pre-production environment:Set the issuer identity variables
Integration tests submit invoices on behalf of a real issuer identity. These values must exactly match the data AEAT holds for that NIF in their census — including punctuation and casing.If these values do not match AEAT’s census, you will receive error
4104 (“El valor del campo NIF del bloque ObligadoEmision no está identificado”). See the Error Handling guide for how to resolve this.Run the sandbox tests
- Load
.envviavlucas/phpdotenv. - Configure the library using the certificate and sandbox environment.
- Submit test invoices to
https://prewww1.aeat.es/…/VerifactuSOAP. - Assert that AEAT returns
STATUS_OK('Correcto') for each submission.
.env value call $this->markTestSkipped() automatically — they will appear as skipped rather than failed.Auto-Creation of .env from .env.example
The check-env Composer script is prepended to every test command:
- Running
composer teston a freshly cloned repo will never fail with a missing file error. - You will see a visible warning in the console output reminding you to populate the generated
.env. - The
.envfile is listed in.gitignore— it will never be accidentally committed.
Code Quality Tools
Beyond tests, the project provides several static-analysis and style-enforcement commands:| Command | Tool | What It Does |
|---|---|---|
composer phpstan | PHPStan | Static analysis — detects type errors and logic bugs without running code |
composer phpstan-baseline | PHPStan | Regenerate the PHPStan baseline to acknowledge existing issues |
composer cs-check | PHP CS Fixer | Check PSR-12 code style (dry run — no changes written) |
composer cs-fix | PHP CS Fixer | Auto-fix PSR-12 code style violations |
composer rector | Rector | Apply automated refactoring rules |
composer rector-dry | Rector | Preview Rector changes without writing them |
Writing Your Own Tests
When adding tests to the project, follow the conventions inCONTRIBUTING.md:
- Place unit tests under
tests/Unit/in a subdirectory that mirrors thesrc/path of the class under test. - Place integration tests (those that make real network calls) under
tests/Verifactu/and guard them with a skip check when the certificate is absent. - Target 80%+ code coverage for new code.
- Use descriptive test method names in the format
testItDoesX()ortest_it_does_x().