1
|
|
|
<?php |
2
|
|
|
namespace Dokobit\Gateway\Tests; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Base test case |
6
|
|
|
*/ |
7
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
8
|
|
|
|
9
|
|
|
class TestCase extends BaseTestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Assert if setter exists |
13
|
|
|
* @param string $property |
14
|
|
|
* @param object $object |
15
|
|
|
* @param mixed $setValue |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
protected function assertSetterExists($property, $object, $setValue = 'foo') |
19
|
|
|
{ |
20
|
|
|
$setter = 'set' . $this->toMethodName($property); |
21
|
|
|
$this->assertTrue( |
22
|
|
|
method_exists($object, $setter), |
23
|
|
|
sprintf('Method is %s missing', $setter) |
24
|
|
|
); |
25
|
|
|
$object->$setter($setValue); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Assert if getter exists. Setter assertion should be executed before. |
30
|
|
|
* @param string $property |
31
|
|
|
* @param object $object |
32
|
|
|
* @param mixed $testValue |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
protected function assertGetterExists($property, $object, $testValue = 'foo') |
36
|
|
|
{ |
37
|
|
|
$getter = 'get' . $this->toMethodName($property); |
38
|
|
|
$this->assertTrue( |
39
|
|
|
method_exists($object, $getter), |
40
|
|
|
sprintf('Method is %s missing', $getter) |
41
|
|
|
); |
42
|
|
|
$this->assertSame($testValue, $object->$getter()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function toMethodName($value) |
46
|
|
|
{ |
47
|
|
|
$parts = explode('_', $value); |
48
|
|
|
$parts = array_map('ucfirst', $parts); |
49
|
|
|
|
50
|
|
|
return implode('', $parts); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|