-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseUnitTest.php
67 lines (63 loc) · 1.46 KB
/
BaseUnitTest.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
public $stringMaker;
public function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->stringMaker = new StringMaker();
}
/**
* @test
*/
public function it_test_sum_two_number(){
$calc = new Calculate();
$resp = $calc->sum(1,4);
$this->assertEquals(5,$resp);
}
/**
* @test
* @dataProvider additionDataProvider
*/
public function it_test_subtract_two_number($a, $b, $result){
$calc = new Calculate();
$resp = $calc->subtract($a,$b);
$this->assertEquals($result,$resp);
}
public function additionDataProvider(){
return [
[1,2,1],
[1,5,4],
[1,5,4],
];
}
/**
* @test
*/
public function it_should_convert_number_to_string(){
$resp = $this->stringMaker->process(123);
$this->assertSame('123', $resp);
}
/**
*
*/
public function it_test_number_is_zero(){
$resp = $this->stringMaker->process(0);
$this->assertSame('Nothing', $resp);
}
}
class StringMaker{
public function process($number){
return (string)$number;
}
}
class Calculate{
public function sum($arg1,$arg2){
return $arg1 + $arg2;
}
public function subtract($arg1,$arg2){
return $arg2 - $arg1;
}
}