-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathObject.magicMethod.errors.phpt
68 lines (52 loc) · 1.62 KB
/
Object.magicMethod.errors.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
67
68
<?php
/**
* Test: Nette\Object magic @methods errors.
* @phpVersion < 7.2
*/
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
/**
* @method self addItem()
* @method self setItems()
* @method getItems()
* @method getAbc()
*/
class TestClass extends Nette\Object
{
protected $items = [];
public function abc()
{
parent::abc();
}
}
// Undeclared method access
Assert::exception(function () {
$obj = new TestClass;
$obj->setAbc();
}, Nette\MemberAccessException::class, 'Call to undefined method TestClass::setAbc(), did you mean getAbc()?');
Assert::exception(function () {
$obj = new TestClass;
$obj->abc();
}, Nette\MemberAccessException::class, 'Call to undefined method parent::abc().');
Assert::exception(function () {
$obj = new TestClass;
$obj->adItem();
}, Nette\MemberAccessException::class, 'Call to undefined method TestClass::adItem(), did you mean addItem()?');
// Wrong parameters count
Assert::exception(function () {
$obj = new TestClass;
$obj->setItems();
}, Nette\InvalidArgumentException::class, 'TestClass::setItems() expects 1 argument, 0 given.');
Assert::exception(function () {
$obj = new TestClass;
$obj->setItems(1, 2);
}, Nette\InvalidArgumentException::class, 'TestClass::setItems() expects 1 argument, 2 given.');
Assert::exception(function () {
$obj = new TestClass;
$obj->getItems(1);
}, Nette\InvalidArgumentException::class, 'TestClass::getItems() expects no argument, 1 given.');
Assert::exception(function () {
$obj = new TestClass;
$obj->addItem();
}, Nette\InvalidArgumentException::class, 'TestClass::addItem() expects 1 argument, 0 given.');