Merge 14f23eb21a
into 64b0f60368
This commit is contained in:
commit
b30726a057
|
@ -50,21 +50,21 @@ class BuildStatusController extends \PHPCI\Controller
|
|||
$branch = $this->getParam('branch', 'master');
|
||||
try {
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
$status = 'passing';
|
||||
$status = Build::STATUS_NEW;
|
||||
|
||||
if (!$project->getAllowPublicStatus()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($project) && $project instanceof Project) {
|
||||
$build = $project->getLatestBuild($branch, array(2,3));
|
||||
$build = $project->getLatestBuild($branch);
|
||||
|
||||
if (isset($build) && $build instanceof Build && $build->getStatus() != 2) {
|
||||
$status = 'failed';
|
||||
if (isset($build) && $build instanceof Build) {
|
||||
return $build->getStatus();
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$status = 'error';
|
||||
$status = Build::STATUS_FAILED;
|
||||
}
|
||||
|
||||
return $status;
|
||||
|
@ -141,11 +141,12 @@ class BuildStatusController extends \PHPCI\Controller
|
|||
return $response;
|
||||
}
|
||||
|
||||
$color = ($status == 'passing') ? 'green' : 'red';
|
||||
list($text, $color) = $this->getImageTextAndColorFromStatus($status);
|
||||
|
||||
$image = file_get_contents(sprintf(
|
||||
'http://img.shields.io/badge/%s-%s-%s.svg?style=%s',
|
||||
$label,
|
||||
$status,
|
||||
$text,
|
||||
$color,
|
||||
$style
|
||||
));
|
||||
|
@ -201,4 +202,25 @@ class BuildStatusController extends \PHPCI\Controller
|
|||
|
||||
return $builds['items'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the image text and color based on the build
|
||||
* status.
|
||||
*
|
||||
* @param $status
|
||||
* @return array
|
||||
*/
|
||||
protected function getImageTextAndColorFromStatus($status)
|
||||
{
|
||||
switch ($status) {
|
||||
case Build::STATUS_NEW:
|
||||
return array('pending', 'blue');
|
||||
case Build::STATUS_RUNNING:
|
||||
return array('running', 'yellow');
|
||||
case Build::STATUS_SUCCESS:
|
||||
return array('success', 'green');
|
||||
case Build::STATUS_FAILED:
|
||||
return array('failed', 'red');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
60
Tests/PHPCI/Controller/BuildStatusControllerTest.php
Normal file
60
Tests/PHPCI/Controller/BuildStatusControllerTest.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace Tests\PHPCI\Controller;
|
||||
|
||||
use PHPCI\Model\Build;
|
||||
|
||||
class BuildStatusControllerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getImageTextAndColorFromStatusDataProvider
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $expectedText
|
||||
* @param string $expectedColor
|
||||
*/
|
||||
public function testGetImageTextAndColorFromStatusReturnsTheCorrectTextAndColorForEachStatus(
|
||||
$status,
|
||||
$expectedText,
|
||||
$expectedColor
|
||||
) {
|
||||
$buildStatusControllerMock =
|
||||
$this->getMockBuilder('PHPCI\Controller\BuildStatusController')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(null)
|
||||
->getMock();
|
||||
|
||||
$buildStatusControllerReflection =
|
||||
new \ReflectionClass('PHPCI\Controller\BuildStatusController');
|
||||
|
||||
$getImageColorFromStatusReflection =
|
||||
$buildStatusControllerReflection->getMethod('getImageTextAndColorFromStatus');
|
||||
$getImageColorFromStatusReflection->setAccessible(true);
|
||||
|
||||
list($text, $color) = $getImageColorFromStatusReflection->invoke($buildStatusControllerMock, $status);
|
||||
|
||||
$this->assertEquals($expectedText, $text);
|
||||
$this->assertEquals($expectedColor, $color);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getImageTextAndColorFromStatusDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(Build::STATUS_NEW, 'pending', 'blue'),
|
||||
array(Build::STATUS_RUNNING, 'running', 'yellow'),
|
||||
array(Build::STATUS_SUCCESS, 'success', 'green'),
|
||||
array(Build::STATUS_FAILED, 'failed', 'red'),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue