-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathObject.extensionMethodViaInterface.phpt
More file actions
63 lines (44 loc) · 1.18 KB
/
Object.extensionMethodViaInterface.phpt
File metadata and controls
63 lines (44 loc) · 1.18 KB
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
<?php
/**
* Test: Nette\Object extension method via interface.
* @phpVersion < 7.2
*/
declare(strict_types=1);
use Nette\Object;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
interface IFirst
{
}
interface ISecond extends IFirst
{
}
class TestClass extends Object implements ISecond
{
public $foo = 'Hello';
public $bar = 'World';
}
function IFirst_join(ISecond $that, $separator)
{
return __METHOD__ . ' says ' . $that->foo . $separator . $that->bar;
}
function ISecond_join(ISecond $that, $separator)
{
return __METHOD__ . ' says ' . $that->foo . $separator . $that->bar;
}
Object::extensionMethod('ISecond::join', 'ISecond_join');
Object::extensionMethod('IFirst::join', 'IFirst_join');
$obj = new TestClass;
Assert::same('ISecond_join says Hello*World', $obj->join('*'));
Assert::same(
['join' => 'ISecond_join'],
Nette\Utils\ObjectMixin::getExtensionMethods(TestClass::class)
);
Assert::same(
['join' => 'IFirst_join'],
Nette\Utils\ObjectMixin::getExtensionMethods(IFirst::class)
);
Assert::exception(function () {
$obj = new TestClass;
$obj->joi();
}, Nette\MemberAccessException::class, 'Call to undefined method TestClass::joi(), did you mean join()?');