← Lararand 8 / 9

Testing

Point the config at system and it never leaves the machine:

'chain' => ['system'],

Do this in every suite. An external generator there spends quota on nothing, makes the suite slow, and makes it fail on somebody else's bad day rather than on your bugs.

Asserting exact numbers

Randomness is the one thing you cannot test by looking at the output. Take the randomness away and assert the arithmetic:

use EduLazaro\Lararand\Contracts\RandomSource;
use EduLazaro\Lararand\Randomness;

$scripted = new class implements RandomSource {
    public function bytes(int $count): string
    {
        return str_repeat("\x00", $count);
    }
};

$this->app->instance(Randomness::class, new Randomness($scripted));

Now every draw is the first outcome, and a test can say which card came out rather than that a card came out.

Feed the bytes you need for the case you are pinning. A source that hands out \x00 proves the mapping; one that hands out a value in the rejected tail proves the rejection.

What to assert about the source

That the test suite is on system, for one:

$this->assertInstanceOf(SystemSource::class, app(RandomSource::class));

It reads like a test of the package and it is not. It is a test that nobody has quietly changed the chain and pointed your suite at a metered endpoint.