2019-03-11 00:44:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\EnvironmentCheck\Tests\Checks;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Kernel;
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
2019-03-11 01:03:48 +01:00
|
|
|
use SilverStripe\EnvironmentCheck\Checks\EnvTypeCheck;
|
2019-03-11 00:44:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the env setting check.
|
|
|
|
*/
|
|
|
|
class EnvTypeCheckTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Check is OK when in live mode
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testEnvSettingLive()
|
|
|
|
{
|
|
|
|
/** @var Kernel $kernel */
|
|
|
|
$kernel = Injector::inst()->get(Kernel::class);
|
|
|
|
$kernel->setEnvironment('live');
|
|
|
|
|
|
|
|
$this->assertTrue(Director::isLive());
|
|
|
|
|
2019-03-11 01:03:48 +01:00
|
|
|
$checker = Injector::inst()->get(EnvTypeCheck::class);
|
2019-03-11 00:44:24 +01:00
|
|
|
$result = $checker->check();
|
|
|
|
|
|
|
|
$this->assertSame($result[0], EnvironmentCheck::OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check is ERROR when in test mode
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testEnvSettingTest()
|
|
|
|
{
|
|
|
|
/** @var Kernel $kernel */
|
|
|
|
$kernel = Injector::inst()->get(Kernel::class);
|
|
|
|
$kernel->setEnvironment('test');
|
|
|
|
|
|
|
|
$this->assertTrue(Director::isTest());
|
|
|
|
|
2019-03-11 01:03:48 +01:00
|
|
|
$checker = Injector::inst()->get(EnvTypeCheck::class);
|
2019-03-11 00:44:24 +01:00
|
|
|
$result = $checker->check();
|
|
|
|
|
|
|
|
$this->assertSame($result[0], EnvironmentCheck::ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check is ERROR when in dev mode
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testEnvSettingDev()
|
|
|
|
{
|
|
|
|
/** @var Kernel $kernel */
|
|
|
|
$kernel = Injector::inst()->get(Kernel::class);
|
|
|
|
$kernel->setEnvironment('dev');
|
|
|
|
|
|
|
|
$this->assertTrue(Director::isDev());
|
|
|
|
|
2019-03-11 01:03:48 +01:00
|
|
|
$checker = Injector::inst()->get(EnvTypeCheck::class);
|
2019-03-11 00:44:24 +01:00
|
|
|
$result = $checker->check();
|
|
|
|
|
|
|
|
$this->assertSame($result[0], EnvironmentCheck::ERROR);
|
|
|
|
}
|
|
|
|
}
|