-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathInvokeClosureTraitTest.php
68 lines (59 loc) · 1.74 KB
/
InvokeClosureTraitTest.php
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
63
64
65
66
67
68
<?php
namespace Aura\Dispatcher;
class InvokeClosureTraitTest extends \PHPUnit_Framework_TestCase
{
use InvokeClosureTrait;
public function testInvokeClosure_namedParams()
{
$closure = function ($foo, $bar, $baz = 'baz') {
return "$foo $bar $baz";
};
$expect = 'FOO BAR baz';
$actual = $this->invokeClosure($closure, [
'foo' => 'FOO',
'bar' => 'BAR',
]);
$this->assertSame($expect, $actual);
}
public function testInvokeClosure_positionalParams()
{
$closure = function ($foo, $bar, $baz = 'baz') {
return "$foo $bar $baz";
};
$expect = 'FOO BAR baz';
$actual = $this->invokeClosure($closure, [
0 => 'FOO',
1 => 'BAR',
]);
$this->assertSame($expect, $actual);
}
public function testInvokeClosure_directParams()
{
$closure = function (array $params) {
return "{$params['foo']} {$params['bar']} {$params['baz']}";
};
$params = [
'foo' => 'foo',
'bar' => 'bar',
'baz' => 'baz',
];
$params['params'] =& $params;
$expect = 'foo bar baz';
$actual = $this->invokeClosure($closure, $params);
$this->assertSame($expect, $actual);
}
public function testInvokeClosure_paramNotSpecified()
{
$closure = function ($foo, $bar, $baz = 'baz') {
return "$foo $bar $baz";
};
$this->setExpectedException(
'Aura\Dispatcher\Exception\ParamNotSpecified',
'Closure(1 : $bar)'
);
$this->invokeClosure($closure, [
'foo' => 'foo',
'baz' => 'baz',
]);
}
}