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