1
|
|
|
<?php |
2
|
|
|
class ServiceTest extends \PHPUnit\Framework\TestCase |
3
|
|
|
{ |
4
|
|
|
|
5
|
|
|
public function testGetException() |
6
|
|
|
{ |
7
|
|
|
$this->expectException(InvalidArgumentException::class); |
8
|
|
|
$service = new \Suricate\Service(); |
9
|
|
|
$service->undefVar; |
|
|
|
|
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
public function testSetException() |
13
|
|
|
{ |
14
|
|
|
$this->expectException(InvalidArgumentException::class); |
15
|
|
|
$service = new \Suricate\Service(); |
16
|
|
|
$service->undefVar = "123"; |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testGet() |
20
|
|
|
{ |
21
|
|
|
$testService = new \Suricate\Service(); |
22
|
|
|
|
23
|
|
|
self::mockProperty($testService, 'parametersList', ['param_1', 'param_2']); |
24
|
|
|
$this->assertNull($testService->param_1); |
|
|
|
|
25
|
|
|
self::mockProperty($testService, 'parametersValues', ['param_1' => 'value1', 'param_2' => 'value2']); |
26
|
|
|
$this->assertNotNull($testService->param_1); |
27
|
|
|
$this->assertEquals($testService->param_1, 'value1'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testSet() |
31
|
|
|
{ |
32
|
|
|
$testService = new \Suricate\Service(); |
33
|
|
|
|
34
|
|
|
self::mockProperty($testService, 'parametersList', ['param_1', 'param_2']); |
35
|
|
|
$this->assertNull($testService->param_1); |
|
|
|
|
36
|
|
|
$testService->param_1 = 'new_value'; |
|
|
|
|
37
|
|
|
$this->assertEquals($testService->param_1, 'new_value'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testConfigure() |
41
|
|
|
{ |
42
|
|
|
$testService = new \Suricate\Service(); |
43
|
|
|
|
44
|
|
|
self::mockProperty($testService, 'parametersList', ['param_1', 'param_2']); |
45
|
|
|
$testService->configure(['param_1' => 'value1', 'param_2' => 'value2']); |
46
|
|
|
|
47
|
|
|
$this->assertEquals($testService->param_1, 'value1'); |
|
|
|
|
48
|
|
|
$this->assertEquals($testService->param_2, 'value2'); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->expectException(InvalidArgumentException::class); |
51
|
|
|
$testService->configure(['param_3' => 'value3']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function mockProperty($object, string $propertyName, $value) |
55
|
|
|
{ |
56
|
|
|
$reflectionClass = new \ReflectionClass($object); |
57
|
|
|
|
58
|
|
|
$property = $reflectionClass->getProperty($propertyName); |
59
|
|
|
$property->setAccessible(true); |
60
|
|
|
$property->setValue($object, $value); |
61
|
|
|
$property->setAccessible(false); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|