2015-11-20 00:01:21 +01:00
|
|
|
<?php
|
2017-01-04 23:16:12 +01:00
|
|
|
|
|
|
|
namespace SilverStripe\EnvironmentCheck\Tests;
|
|
|
|
|
2017-08-25 05:19:45 +02:00
|
|
|
use Monolog\Logger;
|
2017-03-21 11:57:07 +01:00
|
|
|
use Psr\Log\LoggerInterface;
|
2017-08-25 05:19:45 +02:00
|
|
|
use Psr\Log\LogLevel;
|
2017-01-04 23:16:12 +01:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-03-21 11:57:07 +01:00
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentChecker;
|
2017-01-04 23:16:12 +01:00
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class EnvironmentCheckerTest
|
|
|
|
*
|
|
|
|
* @package environmentcheck
|
|
|
|
*/
|
2015-11-21 07:18:35 +01:00
|
|
|
class EnvironmentCheckerTest extends SapphireTest
|
|
|
|
{
|
2016-07-12 04:08:29 +02:00
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
2017-08-25 05:19:45 +02:00
|
|
|
protected function tearDown()
|
2015-11-21 07:18:35 +01:00
|
|
|
{
|
2017-08-25 05:19:45 +02:00
|
|
|
EnvironmentCheckSuite::reset();
|
2015-11-21 07:18:35 +01:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOnlyLogsWithErrors()
|
|
|
|
{
|
2017-03-21 11:57:07 +01:00
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
|
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
|
2017-08-25 05:19:45 +02:00
|
|
|
|
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckNoErrors());
|
|
|
|
|
|
|
|
$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();
|
2015-11-21 07:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLogsWithWarnings()
|
|
|
|
{
|
2017-03-21 11:57:07 +01:00
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
|
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
|
2017-08-25 05:19:45 +02:00
|
|
|
|
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings());
|
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors());
|
|
|
|
|
|
|
|
$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();
|
2015-11-21 07:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLogsWithErrors()
|
|
|
|
{
|
2017-03-21 11:57:07 +01:00
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
|
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
|
2015-11-20 00:01:21 +01:00
|
|
|
|
2017-08-25 05:19:45 +02:00
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings());
|
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors());
|
2015-11-20 00:01:21 +01:00
|
|
|
|
2017-08-25 05:19:45 +02:00
|
|
|
$logger = $this->getMockBuilder(Logger::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods(['log'])
|
|
|
|
->getMock();
|
2015-11-20 00:01:21 +01:00
|
|
|
|
2017-08-25 05:19:45 +02:00
|
|
|
$logger->expects($this->once())
|
|
|
|
->method('log')
|
|
|
|
->withConsecutive(
|
|
|
|
[$this->equalTo(LogLevel::ALERT), $this->anything()],
|
|
|
|
[$this->equalTo(LogLevel::WARNING), $this->anything()]
|
|
|
|
);
|
|
|
|
|
|
|
|
Injector::inst()->registerService($logger, LoggerInterface::class);
|
|
|
|
|
|
|
|
(new EnvironmentChecker('test suite', 'test'))->index();
|
2015-11-21 07:18:35 +01:00
|
|
|
}
|
|
|
|
}
|