From c4315837d5586fdec2327e2bc042864b46885cc4 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Jun 2020 02:27:32 +0300 Subject: [PATCH] Added setMode method --- src/App.php | 16 +++++++++++++++- tests/AppTest.php | 36 +++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/App.php b/src/App.php index 1c73a407..ddcf4713 100755 --- a/src/App.php +++ b/src/App.php @@ -263,7 +263,7 @@ public function getEnv($key, $default = null) /** * Get Mode * - * Get current defined mode + * Get current mode * * @return string */ @@ -272,6 +272,20 @@ public function getMode() return $this->mode; } + /** + * Set Mode + * + * Set current mode + * + * @return string + */ + public function setMode($value) + { + $this->mode = $value; + + return $this; + } + /** * Is app in production mode? */ diff --git a/tests/AppTest.php b/tests/AppTest.php index bd4b534b..05ff7447 100755 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -28,26 +28,32 @@ public function setUp() } public function testIsMode() { - $app = new App('Asia/Tel_Aviv', App::MODE_TYPE_PRODUCTION); - $this->assertEquals(App::MODE_TYPE_PRODUCTION, $app->getMode()); - $this->assertEquals(true, $app->isProduction()); - $this->assertEquals(false, $app->isDevelopment()); - $this->assertEquals(false, $app->isStage()); + $this->assertEquals(App::MODE_TYPE_PRODUCTION, $this->app->getMode()); + $this->assertEquals(true, $this->app->isProduction()); + $this->assertEquals(false, $this->app->isDevelopment()); + $this->assertEquals(false, $this->app->isStage()); - $app = new App('Asia/Tel_Aviv', App::MODE_TYPE_DEVELOPMENT); + $this->app->setMode(App::MODE_TYPE_PRODUCTION); - $this->assertEquals(App::MODE_TYPE_DEVELOPMENT, $app->getMode()); - $this->assertEquals(false, $app->isProduction()); - $this->assertEquals(true, $app->isDevelopment()); - $this->assertEquals(false, $app->isStage()); + $this->assertEquals(App::MODE_TYPE_PRODUCTION, $this->app->getMode()); + $this->assertEquals(true, $this->app->isProduction()); + $this->assertEquals(false, $this->app->isDevelopment()); + $this->assertEquals(false, $this->app->isStage()); - $app = new App('Asia/Tel_Aviv', App::MODE_TYPE_STAGE); + $this->app->setMode(App::MODE_TYPE_DEVELOPMENT); - $this->assertEquals(App::MODE_TYPE_STAGE, $app->getMode()); - $this->assertEquals(false, $app->isProduction()); - $this->assertEquals(false, $app->isDevelopment()); - $this->assertEquals(true, $app->isStage()); + $this->assertEquals(App::MODE_TYPE_DEVELOPMENT, $this->app->getMode()); + $this->assertEquals(false, $this->app->isProduction()); + $this->assertEquals(true, $this->app->isDevelopment()); + $this->assertEquals(false, $this->app->isStage()); + + $this->app->setMode(App::MODE_TYPE_STAGE); + + $this->assertEquals(App::MODE_TYPE_STAGE, $this->app->getMode()); + $this->assertEquals(false, $this->app->isProduction()); + $this->assertEquals(false, $this->app->isDevelopment()); + $this->assertEquals(true, $this->app->isStage()); } public function testGetEnv()