-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathObject.magicMethod.phpt
56 lines (41 loc) · 1.02 KB
/
Object.magicMethod.phpt
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
<?php
/**
* Test: Nette\Object magic @methods.
* @phpVersion < 7.2
*/
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
/**
* @method void setName($var)
* @method getName()
* @method self addItem()
* @method self setItems()
* @method getItems()
* @method setEnabled($enabled)
* @method isEnabled() comment
*/
class TestClass extends Nette\Object
{
public $name;
protected $enabled;
private $items = [];
}
$obj = new TestClass;
// public
Assert::same($obj, $obj->setName('hello'));
Assert::same('hello', $obj->name);
Assert::same('hello', $obj->getName());
// protected
Assert::same($obj, $obj->setEnabled(11));
Assert::same(11, $obj->isEnabled());
// magic accessors for magic methods
$obj->enabled = 22;
Assert::same(22, $obj->enabled);
// adder
Assert::same($obj, $obj->addItem('world'));
Assert::same(['world'], $obj->items);
Assert::same(['world'], $obj->getItems());
Assert::same($obj, $obj->setItems([]));
Assert::same([], $obj->items);
Assert::same([], $obj->getItems());