6
6
7
7
use PHPUnit \Framework \TestCase ;
8
8
use Psr \Container \ContainerInterface ;
9
+ use stdClass ;
9
10
use WoohooLabs \Zen \Exception \NotFoundException ;
10
- use WoohooLabs \Zen \Tests \Double \StubContainer ;
11
+ use WoohooLabs \Zen \Tests \Double \StubPrototypeContainer ;
11
12
use WoohooLabs \Zen \Tests \Double \StubContainerEntry ;
13
+ use WoohooLabs \Zen \Tests \Double \StubSingletonContainer ;
12
14
use WoohooLabs \Zen \Tests \Fixture \Container \ContainerWithInjectedProperty ;
13
15
14
16
class AbstractCompiledContainerTest extends TestCase
@@ -18,7 +20,7 @@ class AbstractCompiledContainerTest extends TestCase
18
20
*/
19
21
public function hasReturnsFalse (): void
20
22
{
21
- $ container = $ this ->createStubContainer ();
23
+ $ container = $ this ->createStubSingletonContainer ();
22
24
23
25
$ hasEntry = $ container ->has ("TestContainerEntry " );
24
26
@@ -30,7 +32,7 @@ public function hasReturnsFalse(): void
30
32
*/
31
33
public function hasReturnsTrue (): void
32
34
{
33
- $ container = $ this ->createStubContainer ();
35
+ $ container = $ this ->createStubSingletonContainer ();
34
36
35
37
$ hasEntry = $ container ->has (StubContainerEntry::class);
36
38
@@ -42,7 +44,7 @@ public function hasReturnsTrue(): void
42
44
*/
43
45
public function getThrowsNotFoundException (): void
44
46
{
45
- $ container = $ this ->createStubContainer ();
47
+ $ container = $ this ->createStubSingletonContainer ();
46
48
47
49
$ this ->expectException (NotFoundException::class);
48
50
@@ -54,7 +56,7 @@ public function getThrowsNotFoundException(): void
54
56
*/
55
57
public function getReturnsPrototypeEntry (): void
56
58
{
57
- $ container = $ this ->createStubContainer ();
59
+ $ container = $ this ->createStubPrototypeContainer ();
58
60
59
61
$ entry1 = $ container ->get (StubContainerEntry::class);
60
62
$ entry2 = $ container ->get (StubContainerEntry::class);
@@ -69,11 +71,14 @@ public function getReturnsPrototypeEntry(): void
69
71
*/
70
72
public function getReturnsSingletonEntry (): void
71
73
{
72
- $ container = $ this ->createStubContainer ( true );
74
+ $ container = $ this ->createStubSingletonContainer ( );
73
75
74
- $ entry = $ container ->get (StubContainerEntry::class);
76
+ $ entry1 = $ container ->get (StubContainerEntry::class);
77
+ $ entry2 = $ container ->get (StubContainerEntry::class);
75
78
76
- $ this ->assertSame ($ container ->get (StubContainerEntry::class), $ entry );
79
+ $ this ->assertInstanceOf (StubContainerEntry::class, $ entry1 );
80
+ $ this ->assertInstanceOf (StubContainerEntry::class, $ entry2 );
81
+ $ this ->assertSame ($ entry1 , $ entry2 );
77
82
}
78
83
79
84
/**
@@ -85,11 +90,16 @@ public function setProperty(): void
85
90
86
91
$ property = $ container ->getProperty ();
87
92
88
- $ this ->assertTrue ($ property );
93
+ $ this ->assertInstanceOf (stdClass::class, $ property );
94
+ }
95
+
96
+ private function createStubSingletonContainer (): ContainerInterface
97
+ {
98
+ return new StubSingletonContainer ();
89
99
}
90
100
91
- private function createStubContainer ( bool $ isSingleton = false ): ContainerInterface
101
+ private function createStubPrototypeContainer ( ): ContainerInterface
92
102
{
93
- return new StubContainer ( $ isSingleton );
103
+ return new StubPrototypeContainer ( );
94
104
}
95
105
}
0 commit comments