Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
Base | n/a |
0 / 0 |
n/a |
0 / 0 |
13 | n/a |
0 / 0 |
|||
setUp | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
tearDown | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
getApiMockup | n/a |
0 / 0 |
n/a |
0 / 0 |
9 | |||||
getApiCalls | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
setApiCalls | n/a |
0 / 0 |
n/a |
0 / 0 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * |
5 | */ |
6 | |
7 | namespace BO\Zmsmessaging\PhpUnit; |
8 | |
9 | use PHPUnit\Framework\TestCase; |
10 | use Prophecy\PhpUnit\ProphecyTrait; |
11 | use Prophecy\Argument; |
12 | |
13 | /** |
14 | * @codeCoverageIgnore |
15 | */ |
16 | abstract class Base extends TestCase |
17 | { |
18 | /** |
19 | * An array of API-Calls, e.g.: |
20 | * [ |
21 | * [ |
22 | * 'function' => 'readGetResult', |
23 | * 'url' => '/status/', |
24 | * 'response' => '{}' |
25 | * ], |
26 | * ] |
27 | */ |
28 | use ProphecyTrait; |
29 | |
30 | protected $apiCalls = array(); |
31 | |
32 | public function setUp(): void |
33 | { |
34 | \App::$http = $this->getApiMockup(); |
35 | } |
36 | |
37 | public function tearDown(): void |
38 | { |
39 | } |
40 | |
41 | protected function getApiMockup() |
42 | { |
43 | $mock = $this->prophesize('BO\Zmsclient\Http'); |
44 | foreach ($this->getApiCalls() as $options) { |
45 | $parameters = isset($options['parameters']) ? $options['parameters'] : null; |
46 | $function = $options['function']; |
47 | if ($function == 'readGetResult' || $function == 'readDeleteResult') { |
48 | $function = $mock->__call( |
49 | $function, |
50 | [ |
51 | $options['url'], |
52 | $parameters |
53 | ] |
54 | ); |
55 | } elseif ($function == 'readPostResult') { |
56 | $function = $mock->__call( |
57 | $function, |
58 | [ |
59 | $options['url'], |
60 | Argument::that(function ($value) { |
61 | return |
62 | ($value instanceof \BO\Zmsentities\Schema\Entity) || |
63 | ($value instanceof \BO\Zmsentities\Collection\Base); |
64 | }), |
65 | $parameters |
66 | ] |
67 | ); |
68 | } else { |
69 | $function = $mock->__call( |
70 | $function, |
71 | $parameters |
72 | ); |
73 | } |
74 | if (isset($options['exception'])) { |
75 | $function->will(new \Prophecy\Promise\ThrowPromise($options['exception'])); |
76 | } elseif (isset($options['response'])) { |
77 | $function->shouldBeCalled() |
78 | ->willReturn( |
79 | new \BO\Zmsclient\Result( |
80 | $this->getResponse($options['response'], 200), |
81 | $this->getRequest() |
82 | ) |
83 | ); |
84 | } else { |
85 | $function->shouldBeCalled(); |
86 | } |
87 | } |
88 | $api = $mock->reveal(); |
89 | return $api; |
90 | } |
91 | |
92 | /** |
93 | * Overwrite this function if api calls definition needs function calls |
94 | */ |
95 | protected function getApiCalls() |
96 | { |
97 | return $this->apiCalls; |
98 | } |
99 | |
100 | public function setApiCalls($apiCalls) |
101 | { |
102 | $this->apiCalls = $apiCalls; |
103 | \App::$http = $this->getApiMockup(); |
104 | } |
105 | } |