Skip to content

Commit

Permalink
Updated env params
Browse files Browse the repository at this point in the history
  • Loading branch information
eldadfux committed Jun 18, 2020
1 parent 9c3bb4f commit b480f9d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 15 deletions.
53 changes: 38 additions & 15 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ class App
const REQUEST_METHOD_HEAD = 'HEAD';

/**
* Env Type
* Mode Type
*/
const ENV_TYPE_DEVELOPMENT = 'development';
const ENV_TYPE_BUILD = 'build';
const ENV_TYPE_STAGE = 'stage';
const ENV_TYPE_PRODUCTION = 'production';
const MODE_TYPE_DEVELOPMENT = 'development';
const MODE_TYPE_STAGE = 'stage';
const MODE_TYPE_PRODUCTION = 'production';

/**
* Routes
Expand All @@ -46,11 +45,11 @@ class App
];

/**
* Current running environment
* Current running mode
*
* @var string
*/
protected $env = '';
protected $mode = '';

/**
* Error
Expand Down Expand Up @@ -110,20 +109,20 @@ class App
* App
*
* @param string $timezone
* @param bool $env When current environment
* @param bool $mode Current mode
*/
public function __construct($timezone, $env)
public function __construct($timezone, $mode)
{
date_default_timezone_set($timezone);

// Turn errors on when not in production or stage
if($env != self::ENV_TYPE_PRODUCTION && $env != self::ENV_TYPE_STAGE) {
if($mode != self::MODE_TYPE_PRODUCTION && $mode != self::MODE_TYPE_STAGE) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}

$this->env = $env;
$this->mode = $mode;
}

/**
Expand Down Expand Up @@ -248,15 +247,39 @@ public function error($callback)
}

/**
* Get Env
* Get Mode
*
* Get current defined environment
* Get current defined mode
*
* @return string
*/
public function getEnv()
public function getMode()
{
return $this->env;
return $this->mode;
}

/**
* Is app in production mode?
*/
public function isProduction(): bool
{
return (self::MODE_TYPE_PRODUCTION === $this->mode);
}

/**
* Is app in development mode?
*/
public function isDevelopment(): bool
{
return (self::MODE_TYPE_DEVELOPMENT === $this->mode);
}

/**
* Is app in stage mode?
*/
public function isStage(): bool
{
return (self::MODE_TYPE_STAGE === $this->mode);
}

/**
Expand Down
57 changes: 57 additions & 0 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Utopia PHP Framework
*
* @package Framework
* @subpackage Tests
*
* @link https://github.com/utopia-php/framework
* @author Eldad Fux <[email protected]>
* @version 1.0 RC4
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/

namespace Utopia;

use PHPUnit\Framework\TestCase;

class AppTest extends TestCase
{
/**
* @var App
*/
protected $app = null;

public function setUp()
{
$this->app = new App('Asia/Tel_Aviv', App::MODE_TYPE_PRODUCTION);
}

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());

$app = new App('Asia/Tel_Aviv', App::MODE_TYPE_DEVELOPMENT);

$this->assertEquals(App::MODE_TYPE_DEVELOPMENT, $app->getMode());
$this->assertEquals(false, $app->isProduction());
$this->assertEquals(true, $app->isDevelopment());
$this->assertEquals(false, $app->isStage());

$app = new App('Asia/Tel_Aviv', App::MODE_TYPE_STAGE);

$this->assertEquals(App::MODE_TYPE_STAGE, $app->getMode());
$this->assertEquals(false, $app->isProduction());
$this->assertEquals(false, $app->isDevelopment());
$this->assertEquals(true, $app->isStage());
}

public function tearDown()
{
$this->view = null;
}
}

0 comments on commit b480f9d

Please sign in to comment.