1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
namespace Skaut\Skautis\Test\Unit\WebService; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use Skaut\Skautis\Wsdl\WebService; |
12
|
|
|
use Skaut\Skautis\Wsdl\WebServiceInterface; |
13
|
|
|
|
14
|
|
|
class ParsingSOAPOutputTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
protected function tearDown(): void |
18
|
|
|
{ |
19
|
|
|
\Mockery::close(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
private function loadData(string $methodName): \stdClass { |
23
|
|
|
$filePath = __DIR__.'/resources/'.$methodName.'.txt'; |
24
|
|
|
|
25
|
|
|
if (!file_exists($filePath) || !is_readable($filePath)) { |
26
|
|
|
throw new \RuntimeException("Cannot access file '$filePath'"); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$text = file_get_contents($filePath); |
30
|
|
|
|
31
|
|
|
return unserialize($text, ['allowed_classes' => [\stdClass::class]]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
private function createMockedWebService(\stdClass $data): WebServiceInterface { |
35
|
|
|
$client = \Mockery::mock(\SoapClient::class); |
36
|
|
|
$client->shouldReceive('__soapCall')->once()->andReturn($data); |
37
|
|
|
|
38
|
|
|
return new WebService($client, [], null); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testObjectForExistentRecord(): void { |
42
|
|
|
$service = $this->createMockedWebService($this->loadData(__FUNCTION__)); |
43
|
|
|
|
44
|
|
|
$result = $service->unitDetail(['ID' => 24404]); |
45
|
|
|
|
46
|
|
|
$this->assertNotNull($result); |
47
|
|
|
$this->assertInstanceOf(\stdClass::class, $result); |
48
|
|
|
$this->assertSame('Středisko', $result->UnitType); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testNullForNonExistentRecord(): void { |
52
|
|
|
$service = $this->createMockedWebService($this->loadData(__FUNCTION__)); |
53
|
|
|
|
54
|
|
|
$result = $service->unitDetail(['ID' => 999]); |
55
|
|
|
|
56
|
|
|
$this->assertNull($result); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testArrayOfResults(): void { |
60
|
|
|
$service = $this->createMockedWebService($this->loadData(__FUNCTION__)); |
61
|
|
|
|
62
|
|
|
$results = $service->unitAll(['ID_UnitParent' => 24404]); |
63
|
|
|
|
64
|
|
|
$this->assertIsArray($results); |
65
|
|
|
$this->assertCount(5, $results); |
66
|
|
|
|
67
|
|
|
foreach ($results as $result) { |
68
|
|
|
$this->assertInstanceOf(\stdClass::class, $result); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testEmptyArrayOfResults(): void { |
73
|
|
|
$service = $this->createMockedWebService($this->loadData(__FUNCTION__)); |
74
|
|
|
|
75
|
|
|
$result = $service->unitAll(['ID_UnitParent' => 999]); |
76
|
|
|
|
77
|
|
|
$this->assertIsArray($result); |
78
|
|
|
$this->assertCount(0, $result); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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: