15
15
16
16
class LoaderContainerTest extends TestCase
17
17
{
18
- protected function setUp (): void
19
- {
20
- parent ::setUp ();
21
- vfsStream::setup ('/temp/ ' );
22
- }
23
-
24
- protected function tearDown (): void
25
- {
26
- vfsStreamWrapper::unregister ();
27
- parent ::tearDown ();
28
- }
29
-
30
- public function testConstructor (): void
31
- {
32
- $ loader = new LoaderContainer ;
33
- static ::assertInstanceOf (LoaderContainerInterface::class, $ loader );
34
- }
35
-
36
- public function testAddExtension (): void
37
- {
38
- $ loader = new LoaderContainer ;
39
- $ prop = new ReflectionProperty ($ loader , 'extensions ' );
40
- $ prop ->setAccessible (true );
41
-
42
- static ::assertCount (0 , $ prop ->getValue ($ loader ));
43
-
44
- $ loader = $ loader ->addExtension (new TestExtension );
45
- static ::assertInstanceOf (LoaderContainerInterface::class, $ loader );
46
- static ::assertCount (1 , $ prop ->getValue ($ loader ));
47
- }
48
-
49
- public function testSetCheckExpired (): void
50
- {
51
- $ loader = new LoaderContainer ;
52
- $ prop = new ReflectionProperty ($ loader , 'checkExpired ' );
53
- $ prop ->setAccessible (true );
54
-
55
- static ::assertTrue ($ prop ->getValue ($ loader ));
56
-
57
- $ loader = $ loader ->setCheckExpired (false );
58
- static ::assertInstanceOf (LoaderContainerInterface::class, $ loader );
59
- static ::assertFalse ($ prop ->getValue ($ loader ));
60
-
61
- $ loader = $ loader ->setCheckExpired (true );
62
- static ::assertTrue ($ prop ->getValue ($ loader ));
63
- }
64
-
65
- public function testGetWatcher (): void
66
- {
67
- $ loader = new LoaderContainer ;
68
- static ::assertInstanceOf (CacheWatcher::class, $ loader ->getWatcher ());
69
- }
70
-
71
- public function testGetContainer (): void
72
- {
73
- $ loader = new LoaderContainer ;
74
- $ container = $ loader ->getContainer ([__DIR__ .'/config/di.yml ' ], 'vfs://temp/cache.php ' );
75
- static ::assertInstanceOf (ContainerBuilder::class, $ container );
76
- static ::assertInstanceOf (Container::class, $ container );
77
- static ::assertFileExists ('vfs://temp/cache.php ' );
78
- static ::assertFileExists ('vfs://temp/cache.php.v2.meta ' );
79
- }
80
-
81
- public function testGetContainerFromCacheFile (): void
82
- {
83
- // build case
84
- $ loader = new LoaderContainer ;
85
- $ container = $ loader ->getContainer ([__DIR__ .'/config/di.yml ' ], 'vfs://temp/cache.php ' );
86
- static ::assertInstanceOf (ContainerBuilder::class, $ container );
87
-
88
- // file cache case
89
- $ loader ->clearProcessCache ();
90
- $ container2 = $ loader ->getContainer ([__DIR__ .'/config/di.yml ' ], 'vfs://temp/cache.php ' );
91
- static ::assertNotInstanceOf (ContainerBuilder::class, $ container2 );
92
- static ::assertInstanceOf (Container::class, $ container2 );
93
- }
94
-
95
- public function testGetContainerFromCacheProcess (): void
96
- {
97
- // Build
98
- $ loader = new LoaderContainer ;
99
- $ loader ->getContainer ([__DIR__ .'/config/di.yml ' ], 'vfs://temp/cache.php ' );
100
-
101
- // Process cache
102
- $ container = $ loader ->getContainer ([__DIR__ .'/config/di.yml ' ], 'vfs://temp/cache.php ' );
103
- static ::assertInstanceOf (ContainerBuilder::class, $ container );
104
-
105
- // file cache
106
- $ loader ->clearProcessCache ();
107
- $ container = $ loader ->getContainer ([__DIR__ .'/config/di.yml ' ], 'vfs://temp/cache.php ' );
108
- static ::assertNotInstanceOf (ContainerBuilder::class, $ container );
109
- static ::assertInstanceOf (Container::class, $ container );
110
-
111
- // Process cache
112
- unlink ('vfs://temp/cache.php ' );
113
- $ container = $ loader ->getContainer ([__DIR__ .'/config/di.yml ' ], 'vfs://temp/cache.php ' );
114
- static ::assertNotInstanceOf (ContainerBuilder::class, $ container );
115
- static ::assertInstanceOf (Container::class, $ container );
116
- }
18
+ protected function setUp (): void
19
+ {
20
+ parent ::setUp ();
21
+ vfsStream::setup ('/temp/ ' );
22
+ }
23
+
24
+ protected function tearDown (): void
25
+ {
26
+ vfsStreamWrapper::unregister ();
27
+ parent ::tearDown ();
28
+ }
29
+
30
+ public function testConstructor (): void
31
+ {
32
+ $ loader = new LoaderContainer ;
33
+ static ::assertInstanceOf (LoaderContainerInterface::class, $ loader );
34
+ }
35
+
36
+ public function testAddExtension (): void
37
+ {
38
+ $ loader = new LoaderContainer ;
39
+ $ prop = new ReflectionProperty ($ loader , 'extensions ' );
40
+ $ prop ->setAccessible (true );
41
+
42
+ static ::assertCount (0 , $ prop ->getValue ($ loader ));
43
+
44
+ $ loader = $ loader ->addExtension (new TestExtension );
45
+ static ::assertInstanceOf (LoaderContainerInterface::class, $ loader );
46
+ static ::assertCount (1 , $ prop ->getValue ($ loader ));
47
+ }
48
+
49
+ public function testSetCheckExpired (): void
50
+ {
51
+ $ loader = new LoaderContainer ;
52
+ $ prop = new ReflectionProperty ($ loader , 'checkExpired ' );
53
+ $ prop ->setAccessible (true );
54
+
55
+ static ::assertTrue ($ prop ->getValue ($ loader ));
56
+
57
+ $ loader = $ loader ->setCheckExpired (false );
58
+ static ::assertInstanceOf (LoaderContainerInterface::class, $ loader );
59
+ static ::assertFalse ($ prop ->getValue ($ loader ));
60
+
61
+ $ loader = $ loader ->setCheckExpired (true );
62
+ static ::assertTrue ($ prop ->getValue ($ loader ));
63
+ }
64
+
65
+ public function testGetWatcher (): void
66
+ {
67
+ $ loader = new LoaderContainer ;
68
+ static ::assertInstanceOf (CacheWatcher::class, $ loader ->getWatcher ());
69
+ }
70
+
71
+ public function testGetContainer (): void
72
+ {
73
+ $ loader = new LoaderContainer ;
74
+ $ container = $ loader ->getContainer ([__DIR__ . '/config/di.yml ' ], 'vfs://temp/cache.php ' );
75
+ static ::assertInstanceOf (ContainerBuilder::class, $ container );
76
+ static ::assertInstanceOf (Container::class, $ container );
77
+ static ::assertFileExists ('vfs://temp/cache.php ' );
78
+ static ::assertFileExists ('vfs://temp/cache.php.v2.meta ' );
79
+ }
80
+
81
+ public function testGetContainerFromCacheFile (): void
82
+ {
83
+ // build case
84
+ $ loader = new LoaderContainer ;
85
+ $ container = $ loader ->getContainer ([__DIR__ . '/config/di.yml ' ], 'vfs://temp/cache.php ' );
86
+ static ::assertInstanceOf (ContainerBuilder::class, $ container );
87
+
88
+ // file cache case
89
+ $ loader ->clearProcessCache ();
90
+ $ container2 = $ loader ->getContainer ([__DIR__ . '/config/di.yml ' ], 'vfs://temp/cache.php ' );
91
+ static ::assertNotInstanceOf (ContainerBuilder::class, $ container2 );
92
+ static ::assertInstanceOf (Container::class, $ container2 );
93
+ }
94
+
95
+ public function testGetContainerFromCacheProcess (): void
96
+ {
97
+ // Build
98
+ $ loader = new LoaderContainer ;
99
+ $ loader ->getContainer ([__DIR__ . '/config/di.yml ' ], 'vfs://temp/cache.php ' );
100
+
101
+ // Process cache
102
+ $ container = $ loader ->getContainer ([__DIR__ . '/config/di.yml ' ], 'vfs://temp/cache.php ' );
103
+ static ::assertInstanceOf (ContainerBuilder::class, $ container );
104
+
105
+ // file cache
106
+ $ loader ->clearProcessCache ();
107
+ $ container = $ loader ->getContainer ([__DIR__ . '/config/di.yml ' ], 'vfs://temp/cache.php ' );
108
+ static ::assertNotInstanceOf (ContainerBuilder::class, $ container );
109
+ static ::assertInstanceOf (Container::class, $ container );
110
+
111
+ // Process cache
112
+ unlink ('vfs://temp/cache.php ' );
113
+ $ container = $ loader ->getContainer ([__DIR__ . '/config/di.yml ' ], 'vfs://temp/cache.php ' );
114
+ static ::assertNotInstanceOf (ContainerBuilder::class, $ container );
115
+ static ::assertInstanceOf (Container::class, $ container );
116
+ }
117
117
}
0 commit comments