1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test; |
4
|
|
|
|
5
|
|
|
use Basis\Converter; |
6
|
|
|
use Basis\Event; |
7
|
|
|
use Basis\Http; |
8
|
|
|
use Basis\Test; |
9
|
|
|
|
10
|
|
|
class EventTest extends Test |
11
|
|
|
{ |
12
|
|
|
public $mocks = [ |
13
|
|
|
['event.fire', [], 'fireEvent'] |
14
|
|
|
]; |
15
|
|
|
|
16
|
|
|
private $firedEvents = []; |
17
|
|
|
|
18
|
|
|
public function fireEvent($params) |
19
|
|
|
{ |
20
|
|
|
$this->firedEvents[] = $params; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testEventFire() |
24
|
|
|
{ |
25
|
|
|
$this->get(Event::class)->fire('person.authorized', ['name' => 'nekufa']); |
26
|
|
|
$this->assertCount(1, $this->firedEvents); |
|
|
|
|
27
|
|
|
$this->assertSame($this->firedEvents[0]->event, 'test.person.authorized'); |
28
|
|
|
$this->assertSame(get_object_vars($this->firedEvents[0]->context), ['name' => 'nekufa']); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testSubscription() |
32
|
|
|
{ |
33
|
|
|
$event = $this->get(Event::class); |
34
|
|
|
$subscription = $event->getSubscription(); |
35
|
|
|
|
36
|
|
|
$this->assertArrayHasKey('person.created', $subscription); |
37
|
|
|
$this->assertSame($subscription['person.created'], ['CreateLogin']); |
38
|
|
|
|
39
|
|
|
$this->assertArrayHasKey('person.person.*', $subscription); |
40
|
|
|
$this->assertSame($subscription['person.person.*'], ['CreateLogin']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testProcessing() |
44
|
|
|
{ |
45
|
|
|
$_REQUEST = array_merge($_REQUEST, [ |
46
|
|
|
'event' => 'person.created', |
47
|
|
|
'context' => json_encode([ 'name' => 'nekufa' ]), |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
$result = $this->get(Http::class)->process('/event'); |
51
|
|
|
$response = json_decode($result); |
52
|
|
|
|
53
|
|
|
$this->assertTrue($response->success); |
54
|
|
|
$this->assertNotNull($response->data->CreateLogin); |
55
|
|
|
|
56
|
|
|
$this->assertSame($response->data->CreateLogin->msg, 'person was created with name nekufa'); |
57
|
|
|
|
58
|
|
|
$_REQUEST = array_merge($_REQUEST, [ |
59
|
|
|
'event' => 'person.person.updated', |
60
|
|
|
'context' => json_encode([ 'name' => 'dmitry' ]), |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
$result = $this->get(Http::class)->process('/event'); |
64
|
|
|
$response = json_decode($result); |
65
|
|
|
|
66
|
|
|
$this->assertTrue($response->success); |
67
|
|
|
$this->assertNotNull($response->data->CreateLogin); |
68
|
|
|
|
69
|
|
|
$this->assertSame($response->data->CreateLogin->msg, 'person.person was updated with name dmitry'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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: