-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Definitions.LocatorDefinition.api.phpt
142 lines (102 loc) 路 3.2 KB
/
Definitions.LocatorDefinition.api.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Test: LocatorDefinition API
*/
declare(strict_types=1);
use Nette\DI\Definitions\LocatorDefinition;
use Nette\DI\Definitions\Reference;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
interface Bad1
{
}
interface Bad2
{
public function create();
}
interface Bad3
{
public function get();
}
interface Bad4
{
public function get($name);
public function foo();
}
interface Bad5
{
public static function get($name);
}
interface Bad6
{
public function get($arg, $arg2);
}
interface Good1
{
public function get($name);
}
interface Good3
{
public function createA(): stdClass;
public function getB(): stdClass;
}
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement('Foo');
}, Nette\InvalidArgumentException::class, "[Service ?]
Interface 'Foo' not found.");
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(stdClass::class);
}, Nette\InvalidArgumentException::class, "[Service ?]
Interface 'stdClass' not found.");
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad1::class);
}, Nette\InvalidArgumentException::class, '[Service ?]
Interface Bad1 must have at least one method.');
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad2::class);
}, Nette\InvalidArgumentException::class, '[Service ?]
Method Bad2::create() does not meet the requirements: is create*(), get*() or get($name) and is non-static.');
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad3::class);
}, Nette\InvalidArgumentException::class, '[Service ?]
Method Bad3::get() does not meet the requirements: is create*(), get*() or get($name) and is non-static.');
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad4::class);
}, Nette\InvalidArgumentException::class, '[Service ?]
Method Bad4::foo() does not meet the requirements: is create*(), get*() or get($name) and is non-static.');
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad5::class);
}, Nette\InvalidArgumentException::class, '[Service ?]
Method Bad5::get() does not meet the requirements: is create*(), get*() or get($name) and is non-static.');
Assert::exception(function () {
$def = new LocatorDefinition;
$def->setImplement(Bad6::class);
}, Nette\InvalidArgumentException::class, '[Service ?]
Method Bad6::get() does not meet the requirements: is create*(), get*() or get($name) and is non-static.');
Assert::noError(function () {
$def = new LocatorDefinition;
$def->setImplement(Good1::class);
Assert::same(Good1::class, $def->getImplement());
Assert::same(Good1::class, $def->getType());
});
Assert::noError(function () {
$def = new LocatorDefinition;
$def->setImplement(Good3::class);
Assert::same(Good3::class, $def->getImplement());
Assert::same(Good3::class, $def->getType());
});
test('', function () {
$def = new LocatorDefinition;
$def->setImplement(Good1::class);
$def->setReferences(['a' => 'stdClass', 'b' => '@one']);
Assert::equal(['a' => new Reference('\stdClass'), 'b' => new Reference('one')], $def->getReferences());
$def->setTagged('tagName');
Assert::same('tagName', $def->getTagged());
});