-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathObject.magicMethod.types.phpt
66 lines (44 loc) · 1.37 KB
/
Object.magicMethod.types.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
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Test: Nette\Object magic @methods and types.
* @phpVersion < 7.2
*/
declare(strict_types=1);
namespace Test;
use Nette;
use stdClass;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
/**
* @method void setName(string $var)
* @method getName()
* @method addItem()
* @method self setItems()
* @method getItems()
* @method setEnabled(bool)
*/
class TestClass extends Nette\Object
{
public $name;
public $enabled;
/** @var TestClass[] */
public $items = [];
}
$obj = new TestClass;
$obj->setName(123);
Assert::same('123', $obj->name);
$obj->setEnabled(1);
Assert::same(true, $obj->enabled);
Assert::exception(function () use ($obj) {
$obj->setEnabled(new stdClass);
}, Nette\InvalidArgumentException::class, 'Argument passed to Test\TestClass::setEnabled() must be bool, object given.');
$obj->setItems([new TestClass]);
Assert::equal([new TestClass], $obj->items);
Assert::exception(function () use ($obj) {
$obj->setItems([1]);
}, Nette\InvalidArgumentException::class, 'Argument passed to Test\TestClass::setItems() must be Test\TestClass[], array given.');
$obj->addItem(new TestClass);
Assert::equal([new TestClass, new TestClass], $obj->items);
Assert::exception(function () use ($obj) {
$obj->addItem(1);
}, Nette\InvalidArgumentException::class, 'Argument passed to Test\TestClass::addItem() must be Test\TestClass, integer given.');