timg/fuzzymock

dev-master 2018-06-22 11:05 UTC

This package is not auto-updated.

Last update: 2024-12-22 07:28:26 UTC


README

composer require timg/fuzzymock

Fuzzymock is a small library that helps to create tests for edge-cases.

Sometimes you want to check if 2 different implementations that are using such a class are working the same way. Something like:

static::assertEquals((new GreeterA)->greet($person), (new GreeterB)->greet($person));

consider you've such a Person class:

class Person {

    public $age;
  
    public function getAge() {
        return $this->age;
    }

}

you can create a FuzzyMock for the Person:

$fuzzyPersonMock = new \Tg\Fuzzymock\FuzzyBuilder(Person::class);
$fuzzyPersonMock->fn('getAge')
    ->couldReturn(new FuzzyFloat(1, 2, 2))
    ->couldReturn(new FuzzyCastString(new FuzzyInt()))
;

/** @var Person $person */
$personBuilder = $fuzzyPersonMock->createBuilder();

while (true) {
    $person = $personBuilder->createNew();
    echo $person->getAge() . "\n"; // a float, or a string containing a random int
}

the createBuilder method creates a PHP-Class on the fly (no reflection etc.). currently there are no benchmarks but FuzzyMock should be extrem fast.