Testing
No fake, by design
Qr has no fake(). Encoding is pure and deterministic — the same input always yields the same symbol — and nothing is written, queued, mailed or sent (the optional SVG cache only memoises public output). So tests assert on the real output: decode the matrix, and read the encoding decisions through Qr::info() and Qr::fits():
use RoundlyConsulting\Qr\Facades\Qr;
use RoundlyConsulting\Qr\Testing\MatrixDecoder;
expect(MatrixDecoder::decode(Qr::otpauth($uri)->matrix())->bytes)->toBe($uri)
->and(Qr::info($uri)->version)->toBeLessThanOrEqual(10)
->and(Qr::fits($uri, maxVersion: 10))->toBeTrue();MatrixDecoder
RoundlyConsulting\Qr\Testing\MatrixDecoder reads a generated matrix back, so you can assert exactly what a code contains:
use RoundlyConsulting\Qr\Facades\Qr;
use RoundlyConsulting\Qr\Testing\MatrixDecoder;
it('encodes the provisioning URI unchanged', function () {
$uri = 'otpauth://totp/Acme:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Acme';
expect(MatrixDecoder::decode(Qr::otpauth($uri)->matrix())->bytes)->toBe($uri);
});It is a perfect-matrix decoder for tests, not an image scanner. It checks the format and version information, unmasks, de-interleaves, requires a clean Reed-Solomon syndrome for every block and parses every segment; failures throw MatrixDecodeException. The result:
$decoded = MatrixDecoder::decode($matrix); // QrMatrix or a list of rows
$decoded->bytes; // the encoded data
$decoded->version;
$decoded->errorCorrection;
$decoded->mask;
$decoded->segments; // list<SegmentInfo>
$decoded->eciDesignator; // ?intTesting responses
Routes that return a code are plain HTTP responses, so the usual Laravel assertions apply:
it('serves the table QR code as SVG', function () {
$response = $this->get('/tables/12/qr');
$response->assertOk()
->assertHeader('Content-Type', 'image/svg+xml; charset=utf-8')
->assertHeader('X-Content-Type-Options', 'nosniff');
expect($response->headers->get('Cache-Control'))->toContain('public');
});Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.