Merge remote-tracking branch 'origin/master' into feature/pluginfactoryconfig

Conflicts:
	PHPCI/Builder.php
	PHPCI/Plugin/Util/Factory.php
This commit is contained in:
steve.brazier 2014-03-25 14:13:45 +00:00
commit 060a786303
79 changed files with 1857 additions and 761 deletions

View file

@ -0,0 +1,49 @@
<?php
namespace PHPCI\Plugin\Tests\Helper;
use PHPCI\Helper\BuildInterpolator;
use Prophecy\PhpUnit\ProphecyTestCase;
class BuildInterpolatorTest extends ProphecyTestCase
{
/**
* @var BuildInterpolator
*/
protected $testedInterpolator;
protected function setUp()
{
parent::setup();
$this->testedInterpolator = new BuildInterpolator();
}
public function testInterpolate_LeavesStringsUnchangedByDefault()
{
$string = "Hello World";
$expectedOutput = "Hello World";
$actualOutput = $this->testedInterpolator->interpolate($string);
$this->assertEquals($expectedOutput, $actualOutput);
}
public function testInterpolate_LeavesStringsUnchangedWhenBuildIsSet()
{
$build = $this->prophesize('PHPCI\\Model\\Build')->reveal();
$string = "Hello World";
$expectedOutput = "Hello World";
$this->testedInterpolator->setupInterpolationVars(
$build,
"/buildpath/",
"phpci.com"
);
$actualOutput = $this->testedInterpolator->interpolate($string);
$this->assertEquals($expectedOutput, $actualOutput);
}
}

View file

@ -15,7 +15,7 @@ class CommandExecutorTest extends ProphecyTestCase
protected function setUp()
{
parent::setUp();
$mockBuildLogger = $this->prophesize('\PHPCI\BuildLogger');
$mockBuildLogger = $this->prophesize('PHPCI\Logging\BuildLogger');
$this->testedExecutor = new CommandExecutor($mockBuildLogger->reveal(), __DIR__ . "/");
}

View file

@ -0,0 +1,107 @@
<?php
namespace PHPCI\Plugin\Tests\Helper;
use PHPCI\Logging\BuildLogger;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTestCase;
use Psr\Log\LogLevel;
class BuildLoggerTest extends ProphecyTestCase
{
/**
* @var BuildLogger
*/
protected $testedBuildLogger;
protected $mockLogger;
protected $mockBuild;
protected function setUp()
{
parent::setUp();
$this->mockLogger = $this->prophesize('\Psr\Log\LoggerInterface');
$this->mockBuild = $this->prophesize('\PHPCI\Model\Build');
$this->testedBuildLogger = new BuildLogger(
$this->mockLogger->reveal(),
$this->mockBuild->reveal()
);
}
public function testLog_CallsWrappedLogger()
{
$level = LogLevel::NOTICE;
$message = "Testing";
$contextIn = array();
$this->mockLogger->log($level, $message, Argument::type('array'))
->shouldBeCalledTimes(1);
$this->testedBuildLogger->log($message, $level, $contextIn);
}
public function testLog_CallsWrappedLoggerForEachMessage()
{
$level = LogLevel::NOTICE;
$message = array("One", "Two", "Three");
$contextIn = array();
$this->mockLogger->log($level, "One", Argument::type('array'))
->shouldBeCalledTimes(1);
$this->mockLogger->log($level, "Two", Argument::type('array'))
->shouldBeCalledTimes(1);
$this->mockLogger->log($level, "Three", Argument::type('array'))
->shouldBeCalledTimes(1);
$this->testedBuildLogger->log($message, $level, $contextIn);
}
public function testLog_AddsBuildToContext()
{
$level = LogLevel::NOTICE;
$message = "Testing";
$contextIn = array();
$expectedContext = array(
'build' => $this->mockBuild->reveal()
);
$this->mockLogger->log($level, $message, $expectedContext)
->shouldBeCalledTimes(1);
$this->testedBuildLogger->log($message, $level, $contextIn);
}
public function testLogFailure_LogsAsErrorLevel()
{
$message = "Testing";
$expectedLevel = LogLevel::ERROR;
$this->mockLogger->log($expectedLevel,
Argument::type('string'),
Argument::type('array'))
->shouldBeCalledTimes(1);
$this->testedBuildLogger->logFailure($message);
}
public function testLogFailure_AddsExceptionContext()
{
$message = "Testing";
$exception = new \Exception("Expected Exception");
$this->mockLogger->log(Argument::type('string'),
Argument::type('string'),
Argument::withEntry('exception', $exception))
->shouldBeCalledTimes(1);
$this->testedBuildLogger->logFailure($message, $exception);
}
}

View file

@ -1,8 +1,10 @@
<?php
use \PHPCI\Helper\LoggerConfig;
namespace PHPCI\Plugin\Tests\Helper;
class LoggerConfigTest extends PHPUnit_Framework_TestCase
use \PHPCI\Logging\LoggerConfig;
class LoggerConfigTest extends \PHPUnit_Framework_TestCase
{
public function testGetFor_ReturnsPSRLogger()
{
@ -20,9 +22,9 @@ class LoggerConfigTest extends PHPUnit_Framework_TestCase
public function testGetFor_AttachesAlwaysPresentHandlers()
{
$expectedHandler = new Monolog\Handler\NullHandler();
$expectedHandler = new \Monolog\Handler\NullHandler();
$config = new LoggerConfig(array(
LoggerConfig::KEY_AlwaysLoaded => function() use ($expectedHandler) {
LoggerConfig::KEY_ALWAYS_LOADED => function() use ($expectedHandler) {
return array($expectedHandler);
}
));
@ -36,7 +38,7 @@ class LoggerConfigTest extends PHPUnit_Framework_TestCase
public function testGetFor_AttachesSpecificHandlers()
{
$expectedHandler = new Monolog\Handler\NullHandler();
$expectedHandler = new \Monolog\Handler\NullHandler();
$config = new LoggerConfig(array(
"Specific" => function() use ($expectedHandler) {
return array($expectedHandler);
@ -52,8 +54,8 @@ class LoggerConfigTest extends PHPUnit_Framework_TestCase
public function testGetFor_IgnoresAlternativeHandlers()
{
$expectedHandler = new Monolog\Handler\NullHandler();
$alternativeHandler = new Monolog\Handler\NullHandler();
$expectedHandler = new \Monolog\Handler\NullHandler();
$alternativeHandler = new \Monolog\Handler\NullHandler();
$config = new LoggerConfig(array(
"Specific" => function() use ($expectedHandler) {

View file

@ -162,7 +162,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
{
$this->mockMailer->expects($this->once())
->method('send');
$this->testedEmailPlugin->sendEmail("test@email.com", "hello", "body");
$this->testedEmailPlugin->sendEmail("test@email.com", array(), "hello", "body");
}
/**
@ -177,7 +177,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
$this->mockMailer->expects($this->once())
->method('send')
->with($this->isInstanceOf('\Swift_Message'), $this->anything());
$this->testedEmailPlugin->sendEmail($toAddress, $subject, $body);
$this->testedEmailPlugin->sendEmail($toAddress, array(), $subject, $body);
}
/**
@ -197,7 +197,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
$actualMail = null;
$this->catchMailPassedToSend($actualMail);
$this->testedEmailPlugin->sendEmail($toAddress, $subject, $body);
$this->testedEmailPlugin->sendEmail($toAddress, array(), $subject, $body);
$this->assertSystemMail(
$toAddress,

View file

@ -0,0 +1,51 @@
<?php
namespace PHPCI\Plugin\Tests\Util;
use PHPCI\Plugin\Util\ComposerPluginInformation;
class ComposerPluginInformationTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ComposerPluginInformation
*/
protected $testedInformation;
protected function setUpFromFile($file)
{
$this->testedInformation = ComposerPluginInformation::buildFromYaml($file);
}
protected function phpciSetup()
{
$this->setUpFromFile(
__DIR__ . "/../../../../vendor/composer/installed.json"
);
}
public function testBuildFromYaml_ReturnsInstance()
{
$this->phpciSetup();
$this->assertInstanceOf(
'\PHPCI\Plugin\Util\ComposerPluginInformation',
$this->testedInformation
);
}
public function testGetInstalledPlugins_ReturnsStdClassArray()
{
$this->phpciSetup();
$plugins = $this->testedInformation->getInstalledPlugins();
$this->assertInternalType("array", $plugins);
$this->assertContainsOnly("stdClass", $plugins);
}
public function testGetPluginClasses_ReturnsStringArray()
{
$this->phpciSetup();
$classes = $this->testedInformation->getPluginClasses();
$this->assertInternalType("array", $classes);
$this->assertContainsOnly("string", $classes);
}
}

View file

@ -22,7 +22,7 @@ class ExecutorTest extends ProphecyTestCase
protected function setUp()
{
parent::setUp();
$this->mockBuildLogger = $this->prophesize('\PHPCI\BuildLogger');
$this->mockBuildLogger = $this->prophesize('\PHPCI\Logging\BuildLogger');
$this->mockFactory = $this->prophesize('\PHPCI\Plugin\Util\Factory');
$this->testedExecutor = new Executor($this->mockFactory->reveal(), $this->mockBuildLogger->reveal());
}

View file

@ -0,0 +1,26 @@
<?php
namespace PHPCI\Plugin\Tests\Util;
use PHPCI\Plugin\Util\FilesPluginInformation;
class FilesPluginInformationTest extends \PHPUnit_Framework_TestCase
{
public function testGetInstalledPlugins_returnsObjectes()
{
$pluginDirPath = realpath(__DIR__ . "/../../../../PHPCI/Plugin/");
$test = FilesPluginInformation::newFromDir($pluginDirPath);
$pluginInfos = $test->getInstalledPlugins();
$this->assertContainsOnlyInstancesOf('stdClass', $pluginInfos);
}
public function testGetPluginClasses_returnsStrings()
{
$pluginDirPath = realpath(__DIR__ . "/../../../../PHPCI/Plugin/");
$test = FilesPluginInformation::newFromDir($pluginDirPath);
$pluginInfos = $test->getPluginClasses();
$this->assertContainsOnly('string', $pluginInfos);
}
}

44
Tests/bootstrap.php Normal file
View file

@ -0,0 +1,44 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2013, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
*/
// Let PHP take a guess as to the default timezone, if the user hasn't set one:
date_default_timezone_set(@date_default_timezone_get());
// Set up a basic autoloader for PHPCI:
$autoload = function ($class) {
$file = str_replace(array('\\', '_'), '/', $class);
$file .= '.php';
if (substr($file, 0, 1) == '/') {
$file = substr($file, 1);
}
if (is_file(dirname(__DIR__) . '/' . $file)) {
include(dirname(__DIR__) . '/' . $file);
return;
}
};
spl_autoload_register($autoload, true, true);
// Load Composer autoloader:
require_once(dirname(__DIR__) . '/vendor/autoload.php');
// Load configuration if present:
$conf = array();
$conf['b8']['app']['namespace'] = 'PHPCI';
$conf['b8']['app']['default_controller'] = 'Home';
$conf['b8']['view']['path'] = dirname(__DIR__) . '/PHPCI/View/';
if (file_exists(dirname(__DIR__) . '/PHPCI/config.yml')) {
$config = new b8\Config($conf);
$config->loadYaml(dirname(__DIR__) . '/PHPCI/config.yml');
}
require_once(dirname(__DIR__) . '/vars.php');