-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculatorTest.php
45 lines (36 loc) · 1.24 KB
/
CalculatorTest.php
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
<?php
namespace App\Tests\Unit\Service;
use App\Enum\CalculatorOperationEnumType;
use App\Model\CalculatorDto;
use App\Service\Calculator;
use PHPUnit\Framework\TestCase;
final class CalculatorTest extends TestCase
{
private Calculator $calculator;
protected function setUp(): void
{
$this->calculator = new Calculator();
}
/**
* @dataProvider calculatorProvider
*/
public function testCalculate(CalculatorOperationEnumType $calculatorOperationEnumType): void
{
$firstArgument = rand(1, 100);
$secondArgument = rand(1, 100);
$dto = new CalculatorDto();
$dto->firstArgument = $firstArgument;
$dto->secondArgument = $secondArgument;
$dto->operation = $calculatorOperationEnumType;
$this->assertEquals(eval(sprintf('return %d %s %d;', $firstArgument, $calculatorOperationEnumType->value, $secondArgument)), $this->calculator->calculate($dto));
}
private function calculatorProvider(): array
{
return [
[CalculatorOperationEnumType::ADDITION],
[CalculatorOperationEnumType::MULTIPLICATION],
[CalculatorOperationEnumType::SUBTRACTION],
[CalculatorOperationEnumType::DIVISION],
];
}
}