@@ -2039,6 +2039,17 @@ public function testGetEnvReturnsStringFromMapFactory(): void
20392039 $ this ->assertEquals ('bar ' , $ container ->getEnv ('X_FOO ' ));
20402040 }
20412041
2042+ public function testGetEnvReturnsStringFromGlobalEnvIfNotSetInMap (): void
2043+ {
2044+ $ container = new Container ([]);
2045+
2046+ $ _ENV ['X_FOO ' ] = 'bar ' ;
2047+ $ ret = $ container ->getEnv ('X_FOO ' );
2048+ unset($ _ENV ['X_FOO ' ]);
2049+
2050+ $ this ->assertEquals ('bar ' , $ ret );
2051+ }
2052+
20422053 public function testGetEnvReturnsStringFromGlobalServerIfNotSetInMap (): void
20432054 {
20442055 $ container = new Container ([]);
@@ -2050,6 +2061,42 @@ public function testGetEnvReturnsStringFromGlobalServerIfNotSetInMap(): void
20502061 $ this ->assertEquals ('bar ' , $ ret );
20512062 }
20522063
2064+ public function testGetEnvReturnsStringFromProcessEnvIfNotSetInMap (): void
2065+ {
2066+ $ container = new Container ([]);
2067+
2068+ putenv ('X_FOO=bar ' );
2069+ $ ret = $ container ->getEnv ('X_FOO ' );
2070+ putenv ('X_FOO ' );
2071+
2072+ $ this ->assertEquals ('bar ' , $ ret );
2073+ }
2074+
2075+ public function testGetEnvReturnsStringFromGlobalEnvBeforeServerIfNotSetInMap (): void
2076+ {
2077+ $ container = new Container ([]);
2078+
2079+ $ _ENV ['X_FOO ' ] = 'foo ' ;
2080+ $ _SERVER ['X_FOO ' ] = 'bar ' ;
2081+ $ ret = $ container ->getEnv ('X_FOO ' );
2082+ unset($ _ENV ['X_FOO ' ], $ _SERVER ['X_FOO ' ]);
2083+
2084+ $ this ->assertEquals ('foo ' , $ ret );
2085+ }
2086+
2087+ public function testGetEnvReturnsStringFromGlobalEnvBeforeProcessEnvIfNotSetInMap (): void
2088+ {
2089+ $ container = new Container ([]);
2090+
2091+ $ _ENV ['X_FOO ' ] = 'foo ' ;
2092+ putenv ('X_FOO=bar ' );
2093+ $ ret = $ container ->getEnv ('X_FOO ' );
2094+ unset($ _ENV ['X_FOO ' ]);
2095+ putenv ('X_FOO ' );
2096+
2097+ $ this ->assertEquals ('foo ' , $ ret );
2098+ }
2099+
20532100 public function testGetEnvReturnsStringFromPsrContainer (): void
20542101 {
20552102 $ psr = $ this ->createMock (ContainerInterface::class);
@@ -2074,10 +2121,42 @@ public function testGetEnvReturnsNullIfPsrContainerHasNoEntry(): void
20742121 $ this ->assertNull ($ container ->getEnv ('X_FOO ' ));
20752122 }
20762123
2124+ public function testGetEnvReturnsStringFromProcessEnvIfPsrContainerHasNoEntry (): void
2125+ {
2126+ $ psr = $ this ->createMock (ContainerInterface::class);
2127+ $ psr ->expects ($ this ->atLeastOnce ())->method ('has ' )->with ('X_FOO ' )->willReturn (false );
2128+ $ psr ->expects ($ this ->never ())->method ('get ' );
2129+
2130+ assert ($ psr instanceof ContainerInterface);
2131+ $ container = new Container ($ psr );
2132+
2133+ putenv ('X_FOO=bar ' );
2134+ $ ret = $ container ->getEnv ('X_FOO ' );
2135+ putenv ('X_FOO ' );
2136+
2137+ $ this ->assertEquals ('bar ' , $ ret );
2138+ }
2139+
2140+ public function testGetEnvReturnsStringFromGlobalEnvIfPsrContainerHasNoEntry (): void
2141+ {
2142+ $ psr = $ this ->createMock (ContainerInterface::class);
2143+ $ psr ->expects ($ this ->atLeastOnce ())->method ('has ' )->with ('X_FOO ' )->willReturn (false );
2144+ $ psr ->expects ($ this ->never ())->method ('get ' );
2145+
2146+ assert ($ psr instanceof ContainerInterface);
2147+ $ container = new Container ($ psr );
2148+
2149+ $ _ENV ['X_FOO ' ] = 'bar ' ;
2150+ $ ret = $ container ->getEnv ('X_FOO ' );
2151+ unset($ _ENV ['X_FOO ' ]);
2152+
2153+ $ this ->assertEquals ('bar ' , $ ret );
2154+ }
2155+
20772156 public function testGetEnvReturnsStringFromGlobalServerIfPsrContainerHasNoEntry (): void
20782157 {
20792158 $ psr = $ this ->createMock (ContainerInterface::class);
2080- $ psr ->expects ($ this ->once ())->method ('has ' )->with ('X_FOO ' )->willReturn (false );
2159+ $ psr ->expects ($ this ->atLeastOnce ())->method ('has ' )->with ('X_FOO ' )->willReturn (false );
20812160 $ psr ->expects ($ this ->never ())->method ('get ' );
20822161
20832162 assert ($ psr instanceof ContainerInterface);
@@ -2090,6 +2169,41 @@ public function testGetEnvReturnsStringFromGlobalServerIfPsrContainerHasNoEntry(
20902169 $ this ->assertEquals ('bar ' , $ ret );
20912170 }
20922171
2172+ public function testGetEnvReturnsStringFromGlobalEnvBeforeServerIfPsrContainerHasNoEntry (): void
2173+ {
2174+ $ psr = $ this ->createMock (ContainerInterface::class);
2175+ $ psr ->expects ($ this ->atLeastOnce ())->method ('has ' )->with ('X_FOO ' )->willReturn (false );
2176+ $ psr ->expects ($ this ->never ())->method ('get ' );
2177+
2178+ assert ($ psr instanceof ContainerInterface);
2179+ $ container = new Container ($ psr );
2180+
2181+ $ _ENV ['X_FOO ' ] = 'foo ' ;
2182+ $ _SERVER ['X_FOO ' ] = 'bar ' ;
2183+ $ ret = $ container ->getEnv ('X_FOO ' );
2184+ unset($ _ENV ['X_FOO ' ], $ _SERVER ['X_FOO ' ]);
2185+
2186+ $ this ->assertEquals ('foo ' , $ ret );
2187+ }
2188+
2189+ public function testGetEnvReturnsStringFromGlobalEnvBeforeProcessEnvIfPsrContainerHasNoEntry (): void
2190+ {
2191+ $ psr = $ this ->createMock (ContainerInterface::class);
2192+ $ psr ->expects ($ this ->atLeastOnce ())->method ('has ' )->with ('X_FOO ' )->willReturn (false );
2193+ $ psr ->expects ($ this ->never ())->method ('get ' );
2194+
2195+ assert ($ psr instanceof ContainerInterface);
2196+ $ container = new Container ($ psr );
2197+
2198+ $ _ENV ['X_FOO ' ] = 'foo ' ;
2199+ putenv ('X_FOO=bar ' );
2200+ $ ret = $ container ->getEnv ('X_FOO ' );
2201+ unset($ _ENV ['X_FOO ' ]);
2202+ putenv ('X_FOO ' );
2203+
2204+ $ this ->assertEquals ('foo ' , $ ret );
2205+ }
2206+
20932207 public function testGetEnvThrowsIfMapContainsInvalidType (): void
20942208 {
20952209 $ container = new Container ([
0 commit comments