From b480f9dd01ad7990a12e90e5e4d11ded558dd8fc Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Jun 2020 01:58:05 +0300 Subject: [PATCH] Updated env params --- src/App.php | 53 ++++++++++++++++++++++++++++++------------- tests/AppTest.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 15 deletions(-) create mode 100755 tests/AppTest.php diff --git a/src/App.php b/src/App.php index 61ea461d..a1c3709a 100755 --- a/src/App.php +++ b/src/App.php @@ -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 @@ -46,11 +45,11 @@ class App ]; /** - * Current running environment + * Current running mode * * @var string */ - protected $env = ''; + protected $mode = ''; /** * Error @@ -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; } /** @@ -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); } /** diff --git a/tests/AppTest.php b/tests/AppTest.php new file mode 100755 index 00000000..b9ba6bf9 --- /dev/null +++ b/tests/AppTest.php @@ -0,0 +1,57 @@ + + * @version 1.0 RC4 + * @license The MIT License (MIT) + */ + +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; + } +} \ No newline at end of file