1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Skaut\Skautis\Test\Unit; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Skaut\Skautis; |
7
|
|
|
use Skaut\Skautis\Exception as SkautisException; |
8
|
|
|
use Skaut\Skautis\SkautisQuery; |
9
|
|
|
use Skaut\Skautis\Wsdl\WebService; |
10
|
|
|
use Skaut\Skautis\Wsdl\WebServiceFactory; |
11
|
|
|
|
12
|
|
|
class WebServiceTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
protected $queries = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var WebServiceFactory |
19
|
|
|
*/ |
20
|
|
|
private $wsFactory; |
21
|
|
|
|
22
|
|
|
protected function setUp(): void |
23
|
|
|
{ |
24
|
|
|
$this->wsFactory = new WebServiceFactory(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
public function queryCallback($query) |
29
|
|
|
{ |
30
|
|
|
$this->queries[] = $query; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testCallback() |
34
|
|
|
{ |
35
|
|
|
$callback = [$this, 'queryCallback']; |
36
|
|
|
|
37
|
|
|
$data = [ |
38
|
|
|
'ID_Application' => 123, |
39
|
|
|
Skautis\User::ID_LOGIN => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
$webService = $this->wsFactory->createWebService( |
44
|
|
|
'https://test-is.skaut.cz/JunakWebservice/UserManagement.asmx?WSDL', |
45
|
|
|
$data |
46
|
|
|
); |
47
|
|
|
$webService->subscribe(WebService::EVENT_FAILURE, $callback); |
48
|
|
|
|
49
|
|
|
try { |
50
|
|
|
$webService->call('UserDetail'); |
51
|
|
|
$this->fail(); |
52
|
|
|
} catch (SkautisException $e) { |
53
|
|
|
//Vyjimku chceme |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->assertCount(1, $this->queries); |
|
|
|
|
57
|
|
|
$this->assertInstanceOf(SkautisQuery::class, $this->queries[0]); |
58
|
|
|
$this->assertEquals('UserDetail', $this->queries[0]->fname); |
59
|
|
|
$this->assertGreaterThan(0, strlen($this->queries[0]->getExceptionString())); |
60
|
|
|
$this->assertEquals('SoapFault', $this->queries[0]->getExceptionClass()); |
61
|
|
|
$this->assertTrue($this->queries[0]->hasFailed()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testCall() |
65
|
|
|
{ |
66
|
|
|
$callback = [$this, 'queryCallback']; |
67
|
|
|
|
68
|
|
|
$data = [ |
69
|
|
|
'ID_Application' => 123, |
70
|
|
|
Skautis\User::ID_LOGIN => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', |
71
|
|
|
]; |
72
|
|
|
$webService = $this->wsFactory->createWebService( |
73
|
|
|
'https://test-is.skaut.cz/JunakWebservice/UserManagement.asmx?WSDL', |
74
|
|
|
$data |
75
|
|
|
); |
76
|
|
|
$webService->subscribe(WebService::EVENT_FAILURE, $callback); |
77
|
|
|
|
78
|
|
|
try { |
79
|
|
|
$webService->UserDetail(); |
80
|
|
|
$this->fail(); |
81
|
|
|
} catch (SkautisException $e) { |
82
|
|
|
//Vyjimku chceme |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->assertCount(1, $this->queries); |
|
|
|
|
86
|
|
|
$this->assertInstanceOf(SkautisQuery::class, $this->queries[0]); |
87
|
|
|
$this->assertEquals('UserDetail', $this->queries[0]->fname); |
88
|
|
|
$this->assertGreaterThan(0, strlen($this->queries[0]->getExceptionString())); |
89
|
|
|
$this->assertEquals('SoapFault', $this->queries[0]->getExceptionClass()); |
90
|
|
|
$this->assertTrue($this->queries[0]->hasFailed()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
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: