Skip to content

Commit

Permalink
Added setMode method
Browse files Browse the repository at this point in the history
  • Loading branch information
eldadfux committed Jun 18, 2020
1 parent c6d43bc commit c431583
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
16 changes: 15 additions & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function getEnv($key, $default = null)
/**
* Get Mode
*
* Get current defined mode
* Get current mode
*
* @return string
*/
Expand All @@ -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?
*/
Expand Down
36 changes: 21 additions & 15 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c431583

Please sign in to comment.