mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
NEW Remove Phockito test dependency, update config API use
This commit is contained in:
parent
9dcfc4f337
commit
2131840da4
@ -18,7 +18,6 @@
|
|||||||
"silverstripe/framework": "^4.0@dev"
|
"silverstripe/framework": "^4.0@dev"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"hafriedlander/phockito": "dev-master",
|
|
||||||
"silverstripe/versioned": "^1.0@dev"
|
"silverstripe/versioned": "^1.0@dev"
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
@ -28,11 +27,7 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"SilverStripe\\EnvironmentCheck\\": "src/"
|
"SilverStripe\\EnvironmentCheck\\": "src/",
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload-dev": {
|
|
||||||
"psr-4": {
|
|
||||||
"SilverStripe\\EnvironmentCheck\\Tests\\": "tests/"
|
"SilverStripe\\EnvironmentCheck\\Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,10 +193,10 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
'ErrorCode' => $this->errorCode,
|
'ErrorCode' => $this->errorCode,
|
||||||
])->renderWith(__CLASS__);
|
])->renderWith(__CLASS__);
|
||||||
|
|
||||||
if ($this->config()->email_results && !$result->ShouldPass()) {
|
if ($this->config()->get('email_results') && !$result->ShouldPass()) {
|
||||||
$email = new Email(
|
$email = new Email(
|
||||||
$this->config()->from_email_address,
|
$this->config()->get('from_email_address'),
|
||||||
$this->config()->to_email_address,
|
$this->config()->get('to_email_address'),
|
||||||
$this->title,
|
$this->title,
|
||||||
$resultText
|
$resultText
|
||||||
);
|
);
|
||||||
@ -205,15 +205,15 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
|
|
||||||
// Optionally log errors and warnings individually
|
// Optionally log errors and warnings individually
|
||||||
foreach ($result->Details() as $detail) {
|
foreach ($result->Details() as $detail) {
|
||||||
if ($this->config()->log_results_warning && $detail->StatusCode == EnvironmentCheck::WARNING) {
|
if ($this->config()->get('log_results_warning') && $detail->StatusCode == EnvironmentCheck::WARNING) {
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf('EnvironmentChecker warning at "%s" check. Message: %s', $detail->Check, $detail->Message),
|
sprintf('EnvironmentChecker warning at "%s" check. Message: %s', $detail->Check, $detail->Message),
|
||||||
$this->config()->log_results_warning_level
|
$this->config()->get('log_results_warning_level')
|
||||||
);
|
);
|
||||||
} elseif ($this->config()->log_results_error && $detail->StatusCode == EnvironmentCheck::ERROR) {
|
} elseif ($this->config()->get('log_results_error') && $detail->StatusCode == EnvironmentCheck::ERROR) {
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf('EnvironmentChecker error at "%s" check. Message: %s', $detail->Check, $detail->Message),
|
sprintf('EnvironmentChecker error at "%s" check. Message: %s', $detail->Check, $detail->Message),
|
||||||
$this->config()->log_results_error_level
|
$this->config()->get('log_results_error_level')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,7 +260,7 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
public static function set_from_email_address($from)
|
public static function set_from_email_address($from)
|
||||||
{
|
{
|
||||||
Deprecation::notice('2.0', 'Use config API instead');
|
Deprecation::notice('2.0', 'Use config API instead');
|
||||||
Config::modify()->set(__CLASS__, 'from_email_address', $from);
|
static::config()->set('from_email_address', $from);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,7 +270,7 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
public static function get_from_email_address()
|
public static function get_from_email_address()
|
||||||
{
|
{
|
||||||
Deprecation::notice('2.0', 'Use config API instead');
|
Deprecation::notice('2.0', 'Use config API instead');
|
||||||
return Config::inst()->get(__CLASS__, 'from_email_address');
|
return static::config()->get('from_email_address');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -280,7 +280,7 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
public static function set_to_email_address($to)
|
public static function set_to_email_address($to)
|
||||||
{
|
{
|
||||||
Deprecation::notice('2.0', 'Use config API instead');
|
Deprecation::notice('2.0', 'Use config API instead');
|
||||||
Config::modify()->set(__CLASS__, 'to_email_address', $to);
|
static::config()->set('to_email_address', $to);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -290,7 +290,7 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
public static function get_to_email_address()
|
public static function get_to_email_address()
|
||||||
{
|
{
|
||||||
Deprecation::notice('2.0', 'Use config API instead');
|
Deprecation::notice('2.0', 'Use config API instead');
|
||||||
return Config::inst()->get(__CLASS__, 'to_email_address');
|
return static::config()->get('to_email_address');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -300,7 +300,7 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
public static function set_email_results($results)
|
public static function set_email_results($results)
|
||||||
{
|
{
|
||||||
Deprecation::notice('2.0', 'Use config API instead');
|
Deprecation::notice('2.0', 'Use config API instead');
|
||||||
Config::modify()->set(__CLASS__, 'email_results', $results);
|
static::config()->set('email_results', $results);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -310,6 +310,6 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
public static function get_email_results()
|
public static function get_email_results()
|
||||||
{
|
{
|
||||||
Deprecation::notice('2.0', 'Use config API instead');
|
Deprecation::notice('2.0', 'Use config API instead');
|
||||||
return Config::inst()->get(__CLASS__, 'email_results');
|
return static::config()->get('email_results');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace SilverStripe\EnvironmentCheck\Tests;
|
namespace SilverStripe\EnvironmentCheck\Tests;
|
||||||
|
|
||||||
use Phockito;
|
use Monolog\Logger;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Psr\Log\LogLevel;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\Dev\TestOnly;
|
|
||||||
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
|
||||||
use SilverStripe\EnvironmentCheck\EnvironmentChecker;
|
use SilverStripe\EnvironmentCheck\EnvironmentChecker;
|
||||||
use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
|
use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
|
||||||
|
|
||||||
@ -19,43 +18,11 @@ use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
|
|||||||
*/
|
*/
|
||||||
class EnvironmentCheckerTest extends SapphireTest
|
class EnvironmentCheckerTest extends SapphireTest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $usesDatabase = true;
|
protected $usesDatabase = true;
|
||||||
|
|
||||||
/**
|
protected function tearDown()
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public static function setUpBeforeClass()
|
|
||||||
{
|
{
|
||||||
parent::setUpBeforeClass();
|
EnvironmentCheckSuite::reset();
|
||||||
|
|
||||||
Phockito::include_hamcrest();
|
|
||||||
|
|
||||||
$logger = Injector::inst()->get(LoggerInterface::class);
|
|
||||||
if ($logger instanceof \Monolog\Logger) {
|
|
||||||
// It logs to stderr by default - disable
|
|
||||||
$logger->pushHandler(new \Monolog\Handler\NullHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
Config::nest();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
Config::unnest();
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,75 +30,68 @@ class EnvironmentCheckerTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
|
||||||
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
|
||||||
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckNoErrors());
|
|
||||||
$checker = Phockito::spy(
|
|
||||||
EnvironmentChecker::class,
|
|
||||||
'test suite',
|
|
||||||
'test'
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $checker->index();
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckNoErrors());
|
||||||
Phockito::verify($checker, 0)->log(\anything(), \anything());
|
|
||||||
EnvironmentCheckSuite::reset();
|
$logger = $this->getMockBuilder(Logger::class)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->setMethods(['log'])
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$logger->expects($this->never())->method('log');
|
||||||
|
|
||||||
|
Injector::inst()->registerService($logger, LoggerInterface::class);
|
||||||
|
|
||||||
|
(new EnvironmentChecker('test suite', 'test'))->index();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLogsWithWarnings()
|
public function testLogsWithWarnings()
|
||||||
{
|
{
|
||||||
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
|
||||||
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
|
||||||
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings());
|
|
||||||
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors());
|
|
||||||
$checker = Phockito::spy(
|
|
||||||
EnvironmentChecker::class,
|
|
||||||
'test suite',
|
|
||||||
'test'
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $checker->index();
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings());
|
||||||
Phockito::verify($checker, 1)->log(containsString('warning'), \anything());
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors());
|
||||||
Phockito::verify($checker, 0)->log(containsString('error'), \anything());
|
|
||||||
EnvironmentCheckSuite::reset();
|
$logger = $this->getMockBuilder(Logger::class)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->setMethods(['log'])
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$logger->expects($this->once())
|
||||||
|
->method('log')
|
||||||
|
->withConsecutive(
|
||||||
|
$this->equalTo(LogLevel::WARNING),
|
||||||
|
$this->anything()
|
||||||
|
);
|
||||||
|
|
||||||
|
Injector::inst()->registerService($logger, LoggerInterface::class);
|
||||||
|
|
||||||
|
(new EnvironmentChecker('test suite', 'test'))->index();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLogsWithErrors()
|
public function testLogsWithErrors()
|
||||||
{
|
{
|
||||||
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
|
||||||
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
|
||||||
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings());
|
|
||||||
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors());
|
|
||||||
$checker = Phockito::spy(
|
|
||||||
EnvironmentChecker::class,
|
|
||||||
'test suite',
|
|
||||||
'test'
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $checker->index();
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings());
|
||||||
Phockito::verify($checker, 0)->log(containsString('warning'), \anything());
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors());
|
||||||
Phockito::verify($checker, 1)->log(containsString('error'), \anything());
|
|
||||||
EnvironmentCheckSuite::reset();
|
$logger = $this->getMockBuilder(Logger::class)
|
||||||
}
|
->disableOriginalConstructor()
|
||||||
}
|
->setMethods(['log'])
|
||||||
|
->getMock();
|
||||||
class EnvironmentCheckerTest_CheckNoErrors implements EnvironmentCheck, TestOnly
|
|
||||||
{
|
$logger->expects($this->once())
|
||||||
public function check()
|
->method('log')
|
||||||
{
|
->withConsecutive(
|
||||||
return [EnvironmentCheck::OK, ''];
|
[$this->equalTo(LogLevel::ALERT), $this->anything()],
|
||||||
}
|
[$this->equalTo(LogLevel::WARNING), $this->anything()]
|
||||||
}
|
);
|
||||||
|
|
||||||
class EnvironmentCheckerTest_CheckWarnings implements EnvironmentCheck, TestOnly
|
Injector::inst()->registerService($logger, LoggerInterface::class);
|
||||||
{
|
|
||||||
public function check()
|
(new EnvironmentChecker('test suite', 'test'))->index();
|
||||||
{
|
|
||||||
return [EnvironmentCheck::WARNING, 'test warning'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class EnvironmentCheckerTest_CheckErrors implements EnvironmentCheck, TestOnly
|
|
||||||
{
|
|
||||||
public function check()
|
|
||||||
{
|
|
||||||
return [EnvironmentCheck::ERROR, 'test error'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
tests/EnvironmentCheckerTest/CheckErrors.php
Normal file
14
tests/EnvironmentCheckerTest/CheckErrors.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\EnvironmentCheck\Tests\EnvironmentCheckerTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
||||||
|
|
||||||
|
class CheckErrors implements EnvironmentCheck, TestOnly
|
||||||
|
{
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
return [EnvironmentCheck::ERROR, 'test error'];
|
||||||
|
}
|
||||||
|
}
|
14
tests/EnvironmentCheckerTest/CheckNoErrors.php
Normal file
14
tests/EnvironmentCheckerTest/CheckNoErrors.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\EnvironmentCheck\Tests\EnvironmentCheckerTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
||||||
|
|
||||||
|
class CheckNoErrors implements EnvironmentCheck, TestOnly
|
||||||
|
{
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
return [EnvironmentCheck::OK, ''];
|
||||||
|
}
|
||||||
|
}
|
14
tests/EnvironmentCheckerTest/CheckWarnings.php
Normal file
14
tests/EnvironmentCheckerTest/CheckWarnings.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\EnvironmentCheck\Tests\EnvironmentCheckerTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
||||||
|
|
||||||
|
class CheckWarnings implements EnvironmentCheck, TestOnly
|
||||||
|
{
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
return [EnvironmentCheck::WARNING, 'test warning'];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user