|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Test\PHPUnitGenerator\Example\BaseClass; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use PHPUnitGenerator\Example\BaseClass; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class BaseClassTest |
|
10
|
|
|
* |
|
11
|
|
|
* @covers \PHPUnitGenerator\Example\BaseClass |
|
12
|
|
|
*/ |
|
13
|
|
|
class BaseClassTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var BaseClass $instance The class instance to test |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $instance; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Build the instance of BaseClass |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function setUp() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->instance = new BaseClass(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @covers \PHPUnitGenerator\Example\BaseClass::__construct() |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testConstruct() |
|
32
|
|
|
{ |
|
33
|
|
|
// @todo: Complete this test |
|
34
|
|
|
$this->markTestIncomplete(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @covers \PHPUnitGenerator\Example\BaseClass::simpleAddition() |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testSimpleAddition() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertEquals(5, BaseClass::simpleAddition(2, 3)); |
|
43
|
|
|
$this->assertEquals(0, BaseClass::simpleAddition()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @covers \PHPUnitGenerator\Example\BaseClass::setProperty1() |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testSetProperty1() |
|
50
|
|
|
{ |
|
51
|
|
|
$expected = 'A simple string'; |
|
52
|
|
|
|
|
53
|
|
|
$property = (new \ReflectionClass(BaseClass::class))->getProperty('property1'); |
|
54
|
|
|
$property->setAccessible(true); |
|
55
|
|
|
|
|
56
|
|
|
$this->instance->setProperty1($expected); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertEquals($expected, $property->getValue($this->instance)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @covers \PHPUnitGenerator\Example\BaseClass::getProperty2() |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testGetProperty2() |
|
65
|
|
|
{ |
|
66
|
|
|
$method = (new \ReflectionClass(get_class($this->instance)))->getMethod('getProperty2'); |
|
67
|
|
|
$method->setAccessible(true); |
|
68
|
|
|
$expected = 'A simple string'; |
|
69
|
|
|
|
|
70
|
|
|
$property = (new \ReflectionClass(BaseClass::class))->getProperty('property2'); |
|
71
|
|
|
$property->setAccessible(true); |
|
72
|
|
|
$property->setValue($this->instance, $expected); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertEquals($expected, $method->invoke($this->instance)); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|