-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathObject.closureProperty.phpt
More file actions
63 lines (44 loc) · 1.34 KB
/
Object.closureProperty.phpt
File metadata and controls
63 lines (44 loc) · 1.34 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 closure properties.
* @phpVersion < 7.2
*/
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
class TestClass extends Nette\Object
{
public $public;
public $onPublic;
protected $protected;
private $private;
public function __construct($func)
{
$this->public = $this->onPublic = $this->protected = $this->private = $func;
}
}
test(function () {
$obj = new TestClass(function ($a, $b) {
return "$a $b";
});
Assert::same('1 2', $obj->public(1, 2));
});
test(function () {
Assert::exception(function () {
$obj = new TestClass(123);
$obj->onPublic = function () {}; // accidentally forgotten []
$obj->onPublic(1, 2);
}, Nette\UnexpectedValueException::class, 'Property TestClass::$onPublic must be array or null, object given.');
Assert::exception(function () {
$obj = new TestClass(123);
$obj->public();
}, Nette\MemberAccessException::class, 'Call to undefined method TestClass::public().');
Assert::exception(function () {
$obj = new TestClass(function () {});
$obj->protected();
}, Nette\MemberAccessException::class, 'Call to undefined method TestClass::protected().');
Assert::exception(function () {
$obj = new TestClass(function () {});
$obj->private();
}, Nette\MemberAccessException::class, 'Call to undefined method TestClass::private().');
});