|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
namespace Skaut\Skautis\Test\Unit\Wsdl\Event; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use RuntimeException; |
|
11
|
|
|
use Skaut\Skautis\Wsdl\Event\RequestFailEvent; |
|
12
|
|
|
use SoapFault; |
|
13
|
|
|
|
|
14
|
|
|
class RequestFailEventTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
public function testExceptionMessage(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$throwable = new RuntimeException('my message'); |
|
20
|
|
|
|
|
21
|
|
|
$event = new RequestFailEvent('asd', [], $throwable, 30); |
|
22
|
|
|
$this->assertStringContainsString('my message', $event->getExceptionString()); |
|
23
|
|
|
$this->assertSame(RuntimeException::class, $event->getExceptionClass()); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testDeserialization(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$throwable = new SoapFault('code-is-string', 'fault-string'); |
|
29
|
|
|
$args = [ |
|
30
|
|
|
[ |
|
31
|
|
|
'argument' => 'value', |
|
32
|
|
|
], |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
$event = new RequestFailEvent('asd', $args, $throwable, 30.22); |
|
36
|
|
|
|
|
37
|
|
|
$serialized = serialize($event); |
|
38
|
|
|
/** @var RequestFailEvent $unserialized */ |
|
39
|
|
|
$unserialized = unserialize($serialized); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertSame('asd', $unserialized->getFname()); |
|
42
|
|
|
$this->assertSame(30.22, $unserialized->getDuration()); |
|
43
|
|
|
$this->assertArrayHasKey(0, $unserialized->getArgs()); |
|
44
|
|
|
$this->assertArrayHasKey('argument', $unserialized->getArgs()[0]); |
|
45
|
|
|
$this->assertSame('value', $unserialized->getArgs()[0]['argument']); |
|
46
|
|
|
$this->assertStringContainsString('code-is-string', $unserialized->getExceptionString()); |
|
47
|
|
|
$this->assertStringContainsString('fault-string', $unserialized->getExceptionString()); |
|
48
|
|
|
$this->assertSame(SoapFault::class, $unserialized->getExceptionClass()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testRepeatedSerializationDeserialization(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$throwable = new SoapFault('code-is-string', 'fault-string'); |
|
54
|
|
|
$args = [ |
|
55
|
|
|
[ |
|
56
|
|
|
'argument' => 'value', |
|
57
|
|
|
], |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
$event = new RequestFailEvent('asd', $args, $throwable, 30.22); |
|
61
|
|
|
|
|
62
|
|
|
$serialized = serialize($event); |
|
63
|
|
|
$unserialized = unserialize($serialized); |
|
64
|
|
|
$serialized = serialize($unserialized); |
|
65
|
|
|
$unserialized = unserialize($serialized); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertSame('asd', $unserialized->getFname()); |
|
68
|
|
|
$this->assertSame(30.22, $unserialized->getDuration()); |
|
69
|
|
|
$this->assertArrayHasKey(0, $unserialized->getArgs()); |
|
70
|
|
|
$this->assertArrayHasKey('argument', $unserialized->getArgs()[0]); |
|
71
|
|
|
$this->assertSame('value', $unserialized->getArgs()[0]['argument']); |
|
72
|
|
|
$this->assertStringContainsString('code-is-string', $unserialized->getExceptionString()); |
|
73
|
|
|
$this->assertStringContainsString('fault-string', $unserialized->getExceptionString()); |
|
74
|
|
|
$this->assertSame(SoapFault::class, $unserialized->getExceptionClass()); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|