File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,21 @@ public function isEnv(string $env)
9898 return $ this ->getEnvironment () === $ env ;
9999 }
100100
101+ public function isLocal ()
102+ {
103+ return $ this ->isEnv (static ::ENV_LOCAL );
104+ }
105+
106+ public function isProd ()
107+ {
108+ return $ this ->isEnv (static ::ENV_PROD );
109+ }
110+
111+ public function isUnitTest ()
112+ {
113+ return $ this ->isEnv (static ::ENV_PHPUNIT );
114+ }
115+
101116 public function getEnvironment (): string
102117 {
103118 if ($ this ->_env === null )
Original file line number Diff line number Diff line change @@ -49,6 +49,21 @@ public function testEnvironment()
4949 $ this ->assertFalse ($ ctx ->isEnv (Context::ENV_QA ));
5050 $ ctx ->setEnvironment (Context::ENV_QA );
5151 $ this ->assertTrue ($ ctx ->isEnv (Context::ENV_QA ));
52+
53+ $ ctx ->setEnvironment ('invalid ' );
54+ $ this ->assertFalse ($ ctx ->isLocal ());
55+ $ ctx ->setEnvironment (Context::ENV_LOCAL );
56+ $ this ->assertTrue ($ ctx ->isLocal ());
57+
58+ $ ctx ->setEnvironment ('invalid ' );
59+ $ this ->assertFalse ($ ctx ->isProd ());
60+ $ ctx ->setEnvironment (Context::ENV_PROD );
61+ $ this ->assertTrue ($ ctx ->isProd ());
62+
63+ $ ctx ->setEnvironment ('invalid ' );
64+ $ this ->assertFalse ($ ctx ->isUnitTest ());
65+ $ ctx ->setEnvironment (Context::ENV_PHPUNIT );
66+ $ this ->assertTrue ($ ctx ->isUnitTest ());
5267 }
5368
5469 public function testContextAware ()
You can’t perform that action at this time.
0 commit comments