1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
require_once __DIR__.'/../../Base.php';
use Core\Plugin\Hook;
class HookTest extends Base
{
public function testGetListeners()
{
$h = new Hook;
$this->assertEmpty($h->getListeners('myhook'));
$h->on('myhook', 'A');
$h->on('myhook', 'B');
$this->assertEquals(array('A', 'B'), $h->getListeners('myhook'));
}
public function testMergeWithNoBinding()
{
$h = new Hook;
$values = array('A', 'B');
$result = $h->merge('myhook', $values, array('p' => 'c'));
$this->assertEquals($values, $result);
}
public function testMergeWithBindings()
{
$h = new Hook;
$values = array('A', 'B');
$expected = array('A', 'B', 'c', 'D');
$h->on('myhook', function($p) {
return array($p);
});
$h->on('myhook', function() {
return array('D');
});
$result = $h->merge('myhook', $values, array('p' => 'c'));
$this->assertEquals($expected, $result);
$this->assertEquals($expected, $values);
}
public function testMergeWithBindingButReturningBadData()
{
$h = new Hook;
$values = array('A', 'B');
$expected = array('A', 'B');
$h->on('myhook', function() {
return 'string';
});
$result = $h->merge('myhook', $values);
$this->assertEquals($expected, $result);
$this->assertEquals($expected, $values);
}
}
|