-
Notifications
You must be signed in to change notification settings - Fork 0
Contributing
The library lives entirely under build/. All commands must be run from that directory, not from the repository root.
git clone https://github.com/dragonofmercy/phppdf.git
cd build/
composer install| Command | What it does |
|---|---|
composer check |
PHPStan level max + full PHPUnit suite (unit + golden) |
composer analyse |
PHPStan only |
composer test |
PHPUnit only (1,000+ tests across unit + golden) |
Run a single test file:
vendor/bin/phpunit tests/Unit/PageMarginsTest.phpRun a single test by name:
vendor/bin/phpunit --filter testSomeBehaviourRequirements:
- PHP
^8.4 - PHPStan runs at
level: maxonsrc/andtests/. New code must pass with zero errors. Do not add@phpstan-ignoreto silence a finding - add a real accessor instead (e.g. if PHPStan reports anonlyWrittenproperty, expose a getter). - PHPUnit is configured with
failOnWarning="true"andfailOnRisky="true": a warning counts as a test failure.
Fixtures under tests/Golden/fixtures/ are byte-compared to a fresh render on every test run. Any change to rendering output - even an apparently harmless refactor that leaves the PDF visually identical - breaks the suite. This is intentional:
- It catches accidental output drift (operator order changes, whitespace shifts in streams, etc.).
- It documents intended changes: when you do change rendering on purpose, you regenerate the fixtures and the commit diff shows exactly what bytes changed.
Inputs (fonts, raster images used by the generators) live under tests/Golden/assets/. The fixtures/ directory is output-only. Fixtures are organised in sub-folders by category: doc/, page/, markdown/, form/, barcode/1d/, barcode/2d/, svg/<topic>/.
When you intentionally change generator output, rebuild the fixtures and commit them alongside the code:
php tests/Golden/regenerate.phpEach golden test also has a paired qpdf --check step. It auto-skips when qpdf is not on PATH, so the suite always passes on a minimal CI environment. When present, qpdf validates structural integrity: xref table, stream lengths, and object references. This means even a byte-identical fixture would be caught if you somehow produced a broken xref.
Installing qpdf:
- Linux:
sudo apt-get install qpdf - macOS:
brew install qpdf - Windows:
choco install qpdf
The 12 PHP files in src/Font/Metrics/ are generated from Adobe Type 1 AFM source files. Place the AFM files in bin/afm-source/ (that directory is gitignored), then run:
php bin/generate-font-metrics.phpThe script applies the WinAnsi glyph-name mapping and emits one PHP file per font. You only need this if you are modifying the Standard 14 font metric data.
MIT licensed. Source on GitHub - if phppdf helps you, you can buy me a coffee.