1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\Skautis; |
4
|
|
|
|
5
|
|
|
use Skautis\User; |
6
|
|
|
use Skautis\Wsdl\Decorator\Cache\ArrayCache; |
7
|
|
|
use Skautis\Wsdl\Decorator\Cache\CacheDecorator; |
8
|
|
|
|
9
|
|
|
class CacheDecoratorTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
protected function tearDown() |
13
|
|
|
{ |
14
|
|
|
\Mockery::close(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testDecoratorRequireRequest() |
18
|
|
|
{ |
19
|
|
|
$value = ['id' => 'response']; |
20
|
|
|
$args = ['asd', 'uv', User::ID_LOGIN => 'a']; |
21
|
|
|
|
22
|
|
|
/** @var Skautis\Wsdl\WebServiceInterface */ |
23
|
|
|
$webService = \Mockery::mock('Skautis\Wsdl\WebServiceInterface'); |
24
|
|
|
$webService->shouldReceive('call')->with('funkceA', $args)->once()->andReturn($value); |
25
|
|
|
|
26
|
|
|
$cache = new ArrayCache(); |
27
|
|
|
|
28
|
|
|
//Prazdna cache, musi poslat request |
29
|
|
|
$decoratedServiceA = new CacheDecorator($webService, $cache); |
|
|
|
|
30
|
|
|
$response = $decoratedServiceA->call('funkceA', $args); |
31
|
|
|
$this->assertEquals($value, $response); |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
//Jina instance WS |
35
|
|
|
/** @var Skautis\Wsdl\WebServiceInterface */ |
36
|
|
|
$webServiceB = \Mockery::mock('Skautis\Wsdl\WebServiceInterface'); |
37
|
|
|
|
38
|
|
|
//Cache naplnena z prechoziho requestu |
39
|
|
|
$decoratedServiceB = new CacheDecorator($webServiceB, $cache); |
|
|
|
|
40
|
|
|
$response = $decoratedServiceB->call('funkceA', $args); |
41
|
|
|
|
42
|
|
|
//Vraci data z cache |
43
|
|
|
$this->assertEquals($value, $response); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testDecorator() |
47
|
|
|
{ |
48
|
|
|
$value = ['id' => 'response']; |
49
|
|
|
$args = ['asd', 'uv']; |
50
|
|
|
|
51
|
|
|
/** @var Skautis\Wsdl\WebServiceInterface */ |
52
|
|
|
$webService = \Mockery::mock('Skautis\Wsdl\WebServiceInterface'); |
53
|
|
|
$webService->shouldReceive('call')->with('funkceA', $args)->once()->andReturn($value); |
54
|
|
|
$webService->shouldReceive('call')->with('funkceB', $args)->once()->andReturn($value); |
55
|
|
|
|
56
|
|
|
$cache = new ArrayCache(); |
57
|
|
|
|
58
|
|
|
$decoratedService = new CacheDecorator($webService, $cache); |
|
|
|
|
59
|
|
|
|
60
|
|
|
|
61
|
|
|
|
62
|
|
|
|
63
|
|
|
// Stejne volani pouze 1x WebService |
64
|
|
|
$response = $decoratedService->call('funkceA', $args); |
65
|
|
|
$this->assertEquals($value, $response); |
66
|
|
|
|
67
|
|
|
// __call() stejny jako call() |
68
|
|
|
$response = $decoratedService->funkceA($args[0], $args[1]); |
69
|
|
|
$this->assertEquals($value, $response); |
70
|
|
|
|
71
|
|
|
// Stejne parametry jina funkce |
72
|
|
|
$response = $decoratedService->call('funkceB', $args); |
73
|
|
|
$this->assertEquals($value, $response); |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
// Zmena obsahu parametru |
77
|
|
|
$args[0] = 'qwe'; |
78
|
|
|
$webService->shouldReceive('call')->with('funkceA', $args)->once()->andReturn($value); |
79
|
|
|
|
80
|
|
|
$response = $decoratedService->call('funkceA', $args); |
81
|
|
|
$this->assertEquals($value, $response); |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
// Odebrani parametru |
85
|
|
|
unset($args['1']); |
86
|
|
|
$webService->shouldReceive('call')->with('funkceA', $args)->once()->andReturn($value); |
87
|
|
|
|
88
|
|
|
$response = $decoratedService->call('funkceA', $args); |
89
|
|
|
$this->assertEquals($value, $response); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: