File tree 2 files changed +17
-2
lines changed
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ public function set(string $name, $entry)
100
100
*/
101
101
public function define (string $ name , $ definition )
102
102
{
103
- $ this ->definitionSource -> addDefinition ($ name , $ definition );
103
+ $ this ->setDefinition ($ name , $ definition );
104
104
}
105
105
106
106
/**
@@ -153,7 +153,10 @@ public function getDefinitionSource(): Definition\DefinitionSourceInterface
153
153
return $ this ->definitionSource ;
154
154
}
155
155
156
- protected function setDefinition (string $ name , DefinitionInterface $ definition ): void
156
+ /**
157
+ * @param array|callable|string $definition
158
+ */
159
+ private function setDefinition (string $ name , $ definition ): void
157
160
{
158
161
// Clear existing entry if it exists
159
162
if (array_key_exists ($ name , $ this ->resolvedEntries )) {
Original file line number Diff line number Diff line change 13
13
14
14
use Hyperf \Di \Container ;
15
15
use Hyperf \Di \Definition \DefinitionSource ;
16
+ use HyperfTest \Di \Stub \Bar ;
16
17
use HyperfTest \Di \Stub \Foo ;
17
18
use HyperfTest \Di \Stub \FooInterface ;
19
+ use Mockery ;
18
20
use PHPUnit \Framework \TestCase ;
19
21
20
22
/**
23
25
*/
24
26
class ContainerTest extends TestCase
25
27
{
28
+ protected function tearDown (): void
29
+ {
30
+ Mockery::close ();
31
+ }
32
+
26
33
public function testHas ()
27
34
{
28
35
$ container = new Container (new DefinitionSource ([]));
@@ -44,5 +51,10 @@ public function testDefine()
44
51
$ container = new Container (new DefinitionSource ([]));
45
52
$ container ->define (FooInterface::class, Foo::class);
46
53
$ this ->assertInstanceOf (Foo::class, $ container ->make (FooInterface::class));
54
+
55
+ $ container ->define (FooInterface::class, function () {
56
+ return Mockery::mock (Bar::class);
57
+ });
58
+ $ this ->assertInstanceOf (Bar::class, $ foo = $ container ->make (FooInterface::class));
47
59
}
48
60
}
You can’t perform that action at this time.
0 commit comments