1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
<?php
namespace phpmock\functions;
use PHPUnit\Framework\TestCase;
/**
* Tests Incrementable and all its implementations.
*
* @author Markus Malkusch <markus@malkusch.de>
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
* @license http://www.wtfpl.net/txt/copying/ WTFPL
* @see Incrementable
*/
class IncrementableTest extends TestCase
{
/**
* Tests increment().
*
* @param mixed $expected The expected value.
* @param mixed $increment The amount of increase.
* @param Incrementable $incrementable The tested Incrementable.
* @param callable $getValue The lambda for getting the value.
* @dataProvider provideTestIncrement
*/
public function testIncrement(
$expected,
$increment,
Incrementable $incrementable,
callable $getValue
) {
$incrementable->increment($increment);
$this->assertEquals($expected, $getValue($incrementable));
}
/**
* Test cases for testIncrement().
*
* @return array Test cases.
*/
public static function provideTestIncrement()
{
$getFixedValue = function (FixedValueFunction $function) {
return call_user_func($function->getCallable());
};
$getMicrotime = function (FixedMicrotimeFunction $function) {
return $function->getMicrotime(true);
};
$getDate = function (FixedDateFunction $function) {
return call_user_func($function->getCallable(), "U");
};
return [
[1, 1, new FixedValueFunction(0), $getFixedValue],
[2, 1, new FixedValueFunction(1), $getFixedValue],
[-1, -1, new FixedValueFunction(0), $getFixedValue],
[1, 1, new FixedMicrotimeFunction(0), $getMicrotime],
[-1, -1, new FixedMicrotimeFunction(0), $getMicrotime],
[2, 1, new FixedMicrotimeFunction(1), $getMicrotime],
[1, 1, new FixedDateFunction(0), $getDate],
[-1, -1, new FixedDateFunction(0), $getDate],
[2, 1, new FixedDateFunction(1), $getDate],
[
1.00000001,
0.00000001,
new FixedMicrotimeFunction(1),
$getMicrotime
],
[
1.00000009,
0.00000009,
new FixedMicrotimeFunction(1),
$getMicrotime
],
];
}
}
|