Merge pull request #48 from robbieaverill/pulls/2.0/ss4-updates

NEW Remove Phockito test dependency, update config API use, update Travis config
This commit is contained in:
Daniel Hensby 2017-09-13 09:11:40 +01:00 committed by GitHub
commit 1fe68e7d4a
10 changed files with 154 additions and 129 deletions

View File

@ -1,24 +1,31 @@
# See https://github.com/silverstripe/silverstripe-travis-support for setup details
sudo: false
language: php
env:
global:
- COMPOSER_ROOT_VERSION="4.0.x-dev"
matrix:
include:
- php: 5.6
env: DB=MYSQL CORE_RELEASE=4
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0
env: DB=PGSQL CORE_RELEASE=4
env: DB=PGSQL PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL CORE_RELEASE=4
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
before_script:
- composer self-update || true
- git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- composer install
- phpenv rehash
- phpenv config-rm xdebug.ini
- composer install --prefer-dist
- composer require --prefer-dist --no-update silverstripe/framework:4.0.x-dev
- if [[ $DB == PGSQL ]]; then composer require --no-update --prefer-dist silverstripe/postgresql:2.0.x-dev; fi
- composer update
script:
- vendor/bin/phpunit environmentcheck/tests
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=framework/phpcs.xml.dist src/ tests/ ; fi
after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi

1
codecov.yml Normal file
View File

@ -0,0 +1 @@
comment: false

View File

@ -18,8 +18,9 @@
"silverstripe/framework": "^4.0@dev"
},
"require-dev": {
"hafriedlander/phockito": "dev-master",
"silverstripe/versioned": "^1.0@dev"
"silverstripe/versioned": "^1.0@dev",
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0"
},
"extra": {
"branch-alias": {
@ -28,12 +29,10 @@
},
"autoload": {
"psr-4": {
"SilverStripe\\EnvironmentCheck\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"SilverStripe\\EnvironmentCheck\\": "src/",
"SilverStripe\\EnvironmentCheck\\Tests\\": "tests/"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

16
phpunit.xml.dist Normal file
View File

@ -0,0 +1,16 @@
<phpunit bootstrap="framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/.</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View File

@ -1,8 +1,8 @@
# SilverStripe Environment Checker Module
[![Build Status](http://img.shields.io/travis/silverstripe/silverstripe-environmentcheck.svg?style=flat-square)](https://travis-ci.org/silverstripe/silverstripe-environmentcheck)
[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe-labs/silverstripe-environmentcheck.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-environmentcheck)
[![Code Coverage](http://img.shields.io/scrutinizer/coverage/g/silverstripe-labs/silverstripe-environmentcheck.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-environmentcheck)
[![Build Status](https://travis-ci.org/silverstripe/silverstripe-environmentcheck.svg?branch=master)](https://travis-ci.org/silverstripe/silverstripe-environmentcheck)
[![Code Quality](https://scrutinizer-ci.com/g/silverstripe/silverstripe-environmentcheck/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-environmentcheck/?branch=master)
[![Code Coverage](https://codecov.io/gh/silverstripe/silverstripe-environmentcheck/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/silverstripe-environmentcheck)
[![Version](http://img.shields.io/packagist/v/silverstripe/environmentcheck.svg?style=flat-square)](https://packagist.org/packages/silverstripe/environmentcheck)
[![License](http://img.shields.io/packagist/l/silverstripe/environmentcheck.svg?style=flat-square)](LICENSE.md)

View File

@ -193,10 +193,10 @@ class EnvironmentChecker extends RequestHandler
'ErrorCode' => $this->errorCode,
])->renderWith(__CLASS__);
if ($this->config()->email_results && !$result->ShouldPass()) {
if ($this->config()->get('email_results') && !$result->ShouldPass()) {
$email = new Email(
$this->config()->from_email_address,
$this->config()->to_email_address,
$this->config()->get('from_email_address'),
$this->config()->get('to_email_address'),
$this->title,
$resultText
);
@ -205,15 +205,15 @@ class EnvironmentChecker extends RequestHandler
// Optionally log errors and warnings individually
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(
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(
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)
{
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()
{
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)
{
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()
{
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)
{
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()
{
Deprecation::notice('2.0', 'Use config API instead');
return Config::inst()->get(__CLASS__, 'email_results');
return static::config()->get('email_results');
}
}

View File

@ -2,13 +2,12 @@
namespace SilverStripe\EnvironmentCheck\Tests;
use Phockito;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
use SilverStripe\EnvironmentCheck\EnvironmentChecker;
use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
@ -19,43 +18,11 @@ use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
*/
class EnvironmentCheckerTest extends SapphireTest
{
/**
* {@inheritDoc}
* @var bool
*/
protected $usesDatabase = true;
/**
* {@inheritDoc}
*/
public static function setUpBeforeClass()
protected function tearDown()
{
parent::setUpBeforeClass();
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();
EnvironmentCheckSuite::reset();
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_error', true);
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckNoErrors());
$checker = Phockito::spy(
EnvironmentChecker::class,
'test suite',
'test'
);
$response = $checker->index();
Phockito::verify($checker, 0)->log(\anything(), \anything());
EnvironmentCheckSuite::reset();
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();
}
public function testLogsWithWarnings()
{
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
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();
Phockito::verify($checker, 1)->log(containsString('warning'), \anything());
Phockito::verify($checker, 0)->log(containsString('error'), \anything());
EnvironmentCheckSuite::reset();
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();
}
public function testLogsWithErrors()
{
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
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();
Phockito::verify($checker, 0)->log(containsString('warning'), \anything());
Phockito::verify($checker, 1)->log(containsString('error'), \anything());
EnvironmentCheckSuite::reset();
}
}
class EnvironmentCheckerTest_CheckNoErrors implements EnvironmentCheck, TestOnly
{
public function check()
{
return [EnvironmentCheck::OK, ''];
}
}
class EnvironmentCheckerTest_CheckWarnings implements EnvironmentCheck, TestOnly
{
public function check()
{
return [EnvironmentCheck::WARNING, 'test warning'];
}
}
class EnvironmentCheckerTest_CheckErrors implements EnvironmentCheck, TestOnly
{
public function check()
{
return [EnvironmentCheck::ERROR, 'test error'];
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::ALERT), $this->anything()],
[$this->equalTo(LogLevel::WARNING), $this->anything()]
);
Injector::inst()->registerService($logger, LoggerInterface::class);
(new EnvironmentChecker('test suite', 'test'))->index();
}
}

View 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'];
}
}

View 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, ''];
}
}

View 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'];
}
}