---
title: "Testing — QR for Laravel | Roundly"
description: "Assert on real output — decode matrices with MatrixDecoder, check Qr::info() and Qr::fits(), and test response headers over HTTP."
url: https://roundly-consulting.com/open-source/docs/qr-for-laravel/testing
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[QR for Laravel](https://roundly-consulting.com/open-source/docs/qr-for-laravel.md)

# 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():

```php
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:

```php
use RoundlyConsulting\Qr\Facades\Qr;
use RoundlyConsulting\Qr\Testing\MatrixDecoder;

it('encodes the provisioning URI unchanged', function () {
    $uri = 'otpauth://totp/Acme:jane@example.com?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, treating a value outside its mode’s range as an error rather than repairing it; failures throw MatrixDecodeException. The result:

```php
$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;    // ?int — the first ECI designator, as in EncodingInfo
```

## Testing responses

Routes that return a code are plain HTTP responses, so the usual Laravel assertions apply:

```php
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 crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/qr-for-laravel.md)
