-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuloTest.php
More file actions
98 lines (84 loc) · 2.8 KB
/
ModuloTest.php
File metadata and controls
98 lines (84 loc) · 2.8 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Ezweb\Workflow\Test\Actions\Arithmetics;
class ModuloTest extends \PHPUnit\Framework\TestCase
{
private \Ezweb\Workflow\Test\Mocker\ScalarMocker $scalarBuilder;
protected function setUp(): void
{
$this->scalarBuilder = new \Ezweb\Workflow\Test\Mocker\ScalarMocker();
}
public function testCreateANewModuloElement()
{
$modulo = \Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::create();
$this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::class, $modulo);
}
public function testAddArg()
{
$modulo = \Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::create();
$modulo->addArgs($this->scalarBuilder->getMockWithValue(1));
$modulo->addArgs($this->scalarBuilder->getMockWithValue(2));
$this->assertCount(2, $modulo->getArgs());
}
/**
* @dataProvider resultIsOkProvider
*/
public function testResultIsOk($a, $b, $expected)
{
$modulo = \Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::create();
$modulo->addArgs($this->scalarBuilder->getMockWithValue(4));
$modulo->addArgs($this->scalarBuilder->getMockWithValue(2));
$method = new \ReflectionMethod($modulo, 'getResult');
$method->setAccessible(true);
$this->assertSame(
$expected,
$method->invoke($modulo, [], [$a, $b]),
'getResult for ' . $a . ' % ' . $b . ' = ' . $expected
);
}
public function resultIsOkProvider()
{
return [
[4, 2, 0],
[5, 2, 1],
[2, 5, 2],
[4.0, 2.0, 0],
[4.0, 2.1, 0],
[4.2, 2.2, 0],
[4.5, 2.2, 0],
[4.6, 2.2, 0],
[4.6, 2, 0],
["4.6", "2", 0],
[5.2, 2.2, 1],
[5.6, 2.2, 1],
[5.2, 2.5, 1],
[5.2, 2.8, 1],
[2.8, 5.2, 2],
];
}
/**
* @dataProvider isValidValuesProvider
*/
public function testIsValid($a, $b, $expected)
{
$modulo = \Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::create();
$modulo->addArgs($this->scalarBuilder->getMockWithValue(4));
$modulo->addArgs($this->scalarBuilder->getMockWithValue(2));
$method = new \ReflectionMethod($modulo, 'isValid');
$method->setAccessible(true);
$this->assertSame(
$expected,
$method->invokeArgs($modulo, [[], [$a, $b]]),
'isValid for ' . $a . ' and ' . $b . ' expect ' . ($expected ? "true" : "false")
);
}
public function isValidValuesProvider()
{
return [
[1, 2, true],
[1.1, 2.2, true],
['a', 2, false],
[1.1, 'b', false],
['a', 'b', false]
];
}
}