ancarda/high-test-coverage

This package is abandoned and no longer maintained. The author suggests using the psr/clock package instead.

Classes and Interfaces to help you get higher test coverage

Installs: 1 202

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

pkg:composer/ancarda/high-test-coverage

1.1.3 2022-02-26 11:30 UTC

This package is auto-updated.

Last update: 2025-12-28 14:29:41 UTC


README

Classes and Interfaces to help you get higher test coverage

License Latest Stable Version Total Downloads builds.sr.ht status

Note

This repository is no longer being maintained. You should replace DateTimeImmutableFactory with the much better psr/clock interface. The random functions can now be replaced with the excellent \Random\Randomizer class built into PHP 8.2+.

High Test Coverage is a collection of classes and interfaces designed to help you get higher test coverage when using impure parts of the PHP Standard Library. It provides a RandomInt interface which you can use in place of the random_int function, like so:

Pull down with composer:

composer require --dev ancarda/high-test-coverage

Example Usage

<?php

use Ancarda\HighTestCoverage\RandomInt\RandomInt;

final class Genie
{
    public function __construct(private RandomInt $randomInt) {}

    public function fortune(): string
    {
        return 'Your lucky number is ' . $this->randomInt(1, 10);
    }
}

In production, this class would be given an instance of RandomInt\Real, likely via your Dependency Injection container. Under test, you would use one of the many built-in classes, such as Fixed or OneShot, like so:

<?php

use Ancarda\HighTestCoverage\RandomInt\Fixed;

final class GenieTest extends TestCase
{
    public function testFortune(): void
    {
        $genie = new Genie(new Fixed(42));
        self::assertSame('Your lucky number is 42', $genie->fortune());
    }
}

Useful Links