Merge branch 'feature-improvements'

This commit is contained in:
Dmitry Khomutov 2016-12-24 17:40:28 +07:00
commit e7673fcd65
14 changed files with 208 additions and 167 deletions

View file

@ -46,6 +46,7 @@ Plugins
* [Package Build](plugins/package_build.md) - `package_build`
* [PDepend](plugins/pdepend.md) - `pdepend`
* [PostgreSQL](plugins/pgsql.md) - `pgsql`
* [SQLite](plugins/sqlite.md) - `sqlite`
* [Phar](plugins/phar.md) - `phar`
* [Phing](plugins/phing.md) - `phing`
* [PHP Code Sniffer](plugins/php_code_sniffer.md) - `php_code_sniffer`

View file

@ -13,14 +13,14 @@ The only step required to activate logging is to create a file in the root direc
```php
<?php
return array(
return [
/** Loggers attached to every command */
"_" => function () {
return array(
return [
new \Monolog\Handler\StreamHandler('path/to/log', \Monolog\Logger::ERROR),
);
];
}
);
];
```
This file should return an array of key value pairs. Each key tells PHP Censor which command to attach the logger to (the underscore is a special value which matches all commands). For each command an array of [Monolog](https://github.com/Seldaek/monolog) handlers should be returned. In the example above we've used one that simply writes to the file system but in practise this could be any handler written for monolog.

23
docs/en/plugins/sqlite.md Normal file
View file

@ -0,0 +1,23 @@
Plugin SQLite
-------------
Connects to a given SQLite DB and runs a list of queries.
Configuration
=============
### Examples
```yaml
build_settings:
sqlite:
path: '/path/to/sqlite.sqlite'
setup:
sqlite:
- "CREATE DATABASE my_app_test;"
complete:
sqlite:
- "DROP DATABASE my_app_test;"
```

View file

@ -9,10 +9,20 @@ Most Continuous Integration systems provide a simple image URL that you can use
You can find the status image at the following location: `http://{PHP_CENSOR_URL}/build-status/image/{PROJECT ID}`
So for example, our instance of PHP Censor is at `php-censor.local`, and our PHP Censor project ID is `2`, so the image URL is: `http://php-censor.local/build-status/image/2`.
You can use additional parameters:
* style: plastic | flat (default) | flat-squared | social
* label: build (default)
* logo
* logoWidth
* link
* maxAge
[See more on shields.io site](http://shields.io)
Example:
![](http://php-censor.local/build-status/image/2)
![](http://php-censor.local/build-status/image/2?style=flat-squared&maxAge=3600)
Status Page
===========
@ -25,10 +35,12 @@ Example:
http://php-censor.local/build-status/view/2
### Where do I find my project ID?
Go to your instance of PHP Censor, and open the project you are interested in. The project ID is the number in the last part of the URL in your browser.
Example:
http://php-censor.local/project/view/2 ~> PROJECT ID: `2`
### Enable/disable status image and page
You can enable or disable access to the public status image and page in your project's settings.

View file

@ -127,12 +127,20 @@ class BuildStatusController extends Controller
}
/**
* Returns the appropriate build status image in SVG format for a given project.
*/
* Returns the appropriate build status image in SVG format for a given project.
*/
public function image($projectId)
{
$style = $this->getParam('style', 'plastic');
$label = $this->getParam('label', 'build');
// plastic|flat|flat-squared|social
$style = $this->getParam('style', 'flat');
$label = $this->getParam('label', 'build');
$optionalParams = [
'logo' => $this->getParam('logo'),
'logoWidth' => $this->getParam('logoWidth'),
'link' => $this->getParam('link'),
'maxAge' => $this->getParam('maxAge'),
];
$status = $this->getStatus($projectId);
@ -150,6 +158,12 @@ class BuildStatusController extends Controller
$color,
$style
));
foreach ($optionalParams as $paramName => $param) {
if ($param) {
$image .= '&' . $paramName . '=' . $param;
}
}
$this->response->disableLayout();
$this->response->setHeader('Content-Type', 'image/svg+xml');

View file

@ -113,8 +113,8 @@ class WebhookController extends Controller
*/
protected function bitbucketWebhook($payload, $project)
{
$results = array();
$status = 'failed';
$results = [];
$status = 'failed';
foreach ($payload['push']['changes'] as $commit) {
try {
$email = $commit['new']['target']['author']['raw'];
@ -130,11 +130,11 @@ class WebhookController extends Controller
);
$status = 'ok';
} catch (Exception $ex) {
$results[$commit['new']['target']['hash']] = array('status' => 'failed', 'error' => $ex->getMessage());
$results[$commit['new']['target']['hash']] = ['status' => 'failed', 'error' => $ex->getMessage()];
}
}
return array('status' => $status, 'commits' => $results);
return ['status' => $status, 'commits' => $results];
}
/**

View file

@ -8,11 +8,10 @@ class ProjectTableDefaults extends AbstractMigration
public function change()
{
$this->table('project')
->changeColumn('build_config', MysqlAdapter::PHINX_TYPE_TEXT, array('null' => true))
->changeColumn('archived', MysqlAdapter::PHINX_TYPE_INTEGER, array(
'length' => MysqlAdapter::INT_TINY,
->changeColumn('build_config', MysqlAdapter::PHINX_TYPE_TEXT, ['null' => true])
->changeColumn('archived', MysqlAdapter::PHINX_TYPE_INTEGER, [
'length' => MysqlAdapter::INT_TINY,
'default' => 0,
))
->save();
])->save();
}
}

View file

@ -95,7 +95,7 @@ class Project extends ProjectBase
$info = $this->data['access_information'];
// Handle old-format (serialized) access information first:
if (!empty($info) && !in_array(substr($info, 0, 1), array('{', '['))) {
if (!empty($info) && !in_array(substr($info, 0, 1), ['{', '['])) {
$data = unserialize($info);
} else {
$data = json_decode($info, true);

View file

@ -32,10 +32,10 @@ class PhpCsFixer implements Plugin
protected $build;
protected $workingDir = '';
protected $level = ' --level=psr2';
protected $verbose = '';
protected $diff = '';
protected $levels = ['psr0', 'psr1', 'psr2', 'symfony'];
protected $level = ' --level=psr2';
protected $verbose = '';
protected $diff = '';
protected $levels = array('psr0', 'psr1', 'psr2', 'symfony');
/**
* Standard Constructor

View file

@ -74,7 +74,7 @@ class BuildErrorStore extends BuildErrorStoreBase
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
return $res['total'];
} else {
return array();
return [];
}
}
}

View file

@ -27,10 +27,10 @@ TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals(array(
array('pass' => true, 'severity' => 'success', 'message' => 'SomeTest::testAnother'),
array('pass' => false, 'severity' => 'fail', 'message' => ''),
), $result);
$this->assertEquals([
['pass' => true, 'severity' => 'success', 'message' => 'SomeTest::testAnother'],
['pass' => false, 'severity' => 'fail', 'message' => ''],
], $result);
$this->assertEquals(1, $parser->getTotalFailures());
}
@ -49,10 +49,10 @@ TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals(array(
array('pass' => true, 'severity' => 'success', 'message' => 'SomeTest::testAnother'),
array('pass' => false, 'severity' => 'fail', 'message' => ''),
), $result);
$this->assertEquals([
['pass' => true, 'severity' => 'success', 'message' => 'SomeTest::testAnother'],
['pass' => false, 'severity' => 'fail', 'message' => ''],
], $result);
$this->assertEquals(1, $parser->getTotalFailures());
}
@ -134,11 +134,11 @@ TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals(array(
array('pass' => true, 'severity' => 'success', 'message' => 'SomeTest::testAnother',),
array('pass' => false, 'severity' => 'fail', 'message' => 'Failure: SomeTest::testAnother'),
array('pass' => false, 'severity' => 'error', 'message' => 'Error: SomeTest::testAnother'),
), $result);
$this->assertEquals([
['pass' => true, 'severity' => 'success', 'message' => 'SomeTest::testAnother',],
['pass' => false, 'severity' => 'fail', 'message' => 'Failure: SomeTest::testAnother'],
['pass' => false, 'severity' => 'error', 'message' => 'Error: SomeTest::testAnother'],
], $result);
$this->assertEquals(2, $parser->getTotalFailures());
}
@ -156,11 +156,11 @@ TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals(array(
array('pass' => true, 'severity' => 'skipped', 'message' => ''),
array('pass' => true, 'severity' => 'skipped', 'message' => 'foobar'),
array('pass' => true, 'severity' => 'skipped', 'message' => 'foo, skipped: bar'),
), $result);
$this->assertEquals([
['pass' => true, 'severity' => 'skipped', 'message' => ''],
['pass' => true, 'severity' => 'skipped', 'message' => 'foobar'],
['pass' => true, 'severity' => 'skipped', 'message' => 'foo, skipped: bar'],
], $result);
$this->assertEquals(0, $parser->getTotalFailures());
}
@ -178,12 +178,12 @@ TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals(array(
array('pass' => true, 'severity' => 'todo', 'message' => 'SomeTest::testAnother, todo: really implement this test'),
array('pass' => true, 'severity' => 'todo', 'message' => 'really implement this test'),
array('pass' => true, 'severity' => 'todo', 'message' => 'this is a message, todo: really implement this test'),
array('pass' => true, 'severity' => 'todo', 'message' => ''),
), $result);
$this->assertEquals([
['pass' => true, 'severity' => 'todo', 'message' => 'SomeTest::testAnother, todo: really implement this test'],
['pass' => true, 'severity' => 'todo', 'message' => 'really implement this test'],
['pass' => true, 'severity' => 'todo', 'message' => 'this is a message, todo: really implement this test'],
['pass' => true, 'severity' => 'todo', 'message' => ''],
], $result);
$this->assertEquals(0, $parser->getTotalFailures());
}
@ -202,13 +202,11 @@ TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals(array(
array(
'pass' => false,
'severity' => 'fail',
'message' => 'FOO' . PHP_EOL . 'BAR',
),
), $result);
$this->assertEquals([[
'pass' => false,
'severity' => 'fail',
'message' => 'FOO' . PHP_EOL . 'BAR',
]], $result);
$this->assertEquals(1, $parser->getTotalFailures());
}
@ -225,18 +223,15 @@ TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals(array(
array(
'pass' => false,
'severity' => 'fail',
'message' => 'Failure: testFailure::FailureErrorTest',
),
array(
'pass' => false,
'severity' => 'error',
'message' => 'Error: testError::FailureErrorTest',
)
), $result);
$this->assertEquals([[
'pass' => false,
'severity' => 'fail',
'message' => 'Failure: testFailure::FailureErrorTest',
], [
'pass' => false,
'severity' => 'error',
'message' => 'Error: testError::FailureErrorTest',
]], $result);
$this->assertEquals(2, $parser->getTotalFailures());
}
@ -300,17 +295,14 @@ TAP;
$parser = new TapParser($content);
$result = $parser->parse();
$this->assertEquals(
array(
array('pass' => true, 'severity' => 'success', 'message' => 'try to access the dashboard as a guest (Auth/GuestAccessDashboardAndRedirectCept)'),
array('pass' => true, 'severity' => 'success', 'message' => 'see the login page (Auth/SeeLoginCept)'),
array('pass' => true, 'severity' => 'success', 'message' => 'click forgot password and see the email form (Auth/SeeLoginForgotPasswordCept)'),
array('pass' => true, 'severity' => 'success', 'message' => 'see powered by runmybusiness branding (Auth/ShouldSeePoweredByBrandingCept)'),
array('pass' => true, 'severity' => 'success', 'message' => 'submit invalid credentials (Auth/SubmitLoginAndFailCept)'),
array('pass' => true, 'severity' => 'success', 'message' => 'submit valid credentials and see the dashboard (Auth/SubmitLoginAndSucceedCept)'),
),
$result
);
$this->assertEquals([
['pass' => true, 'severity' => 'success', 'message' => 'try to access the dashboard as a guest (Auth/GuestAccessDashboardAndRedirectCept)'],
['pass' => true, 'severity' => 'success', 'message' => 'see the login page (Auth/SeeLoginCept)'],
['pass' => true, 'severity' => 'success', 'message' => 'click forgot password and see the email form (Auth/SeeLoginForgotPasswordCept)'],
['pass' => true, 'severity' => 'success', 'message' => 'see powered by runmybusiness branding (Auth/ShouldSeePoweredByBrandingCept)'],
['pass' => true, 'severity' => 'success', 'message' => 'submit invalid credentials (Auth/SubmitLoginAndFailCept)'],
['pass' => true, 'severity' => 'success', 'message' => 'submit valid credentials and see the dashboard (Auth/SubmitLoginAndSucceedCept)'],
], $result);
$this->assertEquals(0, $parser->getTotalFailures());

View file

@ -27,7 +27,7 @@ abstract class ProcessControlTest extends \PHPUnit_Framework_TestCase
*/
protected function startProcess()
{
$desc = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w"));
$desc = [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]];
$this->pipes = [];
$this->process = proc_open($this->getTestCommand(), $desc, $this->pipes);

View file

@ -51,41 +51,41 @@ class BuildStatusServiceTest extends \PHPUnit_Framework_TestCase
*/
protected function getBuild($configId, $setProject = true)
{
$config = array(
'1' => array(
'status' => Build::STATUS_RUNNING,
'id' => 77,
$config = [
'1' => [
'status' => Build::STATUS_RUNNING,
'id' => 77,
'finishDateTime' => null,
'startedDate' => '2014-10-25 21:20:02',
'previousBuild' => null,
),
'2' => array(
'status' => Build::STATUS_RUNNING,
'id' => 78,
'startedDate' => '2014-10-25 21:20:02',
'previousBuild' => null,
],
'2' => [
'status' => Build::STATUS_RUNNING,
'id' => 78,
'finishDateTime' => null,
'startedDate' => '2014-10-25 21:20:02',
'previousBuild' => 4,
),
'3' => array(
'status' => Build::STATUS_SUCCESS,
'id' => 7,
'startedDate' => '2014-10-25 21:20:02',
'previousBuild' => 4,
],
'3' => [
'status' => Build::STATUS_SUCCESS,
'id' => 7,
'finishDateTime' => '2014-10-25 21:50:02',
'startedDate' => '2014-10-25 21:20:02',
'previousBuild' => null,
),
'4' => array(
'status' => Build::STATUS_FAILED,
'id' => 13,
'startedDate' => '2014-10-25 21:20:02',
'previousBuild' => null,
],
'4' => [
'status' => Build::STATUS_FAILED,
'id' => 13,
'finishDateTime' => '2014-10-13 13:13:13',
'previousBuild' => null,
),
'5' => array(
'status' => Build::STATUS_NEW,
'id' => 1000,
'previousBuild' => null,
],
'5' => [
'status' => Build::STATUS_NEW,
'id' => 1000,
'finishDateTime' => '2014-12-25 21:12:21',
'previousBuild' => 3,
)
);
'previousBuild' => 3,
]
];
$build = new Build();
$build->setId($config[$configId]['id']);
@ -112,7 +112,7 @@ class BuildStatusServiceTest extends \PHPUnit_Framework_TestCase
*/
protected function getProjectMock($prevBuildId = null, $setProject = true) {
$project = $this->getMock('PHPCensor\Model\Project', array('getLatestBuild'));
$project = $this->getMock('PHPCensor\Model\Project', ['getLatestBuild']);
$prevBuild = ($prevBuildId) ? $this->getBuild($prevBuildId, false) : null;
@ -150,62 +150,62 @@ class BuildStatusServiceTest extends \PHPUnit_Framework_TestCase
public function finishedProvider()
{
return array(
'buildingStatus' => array(
return [
'buildingStatus' => [
1,
array(
'name' => 'Test / master',
'activity' => 'Building',
'lastBuildLabel' => '',
[
'name' => 'Test / master',
'activity' => 'Building',
'lastBuildLabel' => '',
'lastBuildStatus' => '',
'lastBuildTime' => '',
'webUrl' => 'http://php-censor.local/build/view/77',
)
),
'buildingStatusWithPrev' => array(
'lastBuildTime' => '',
'webUrl' => 'http://php-censor.local/build/view/77',
]
],
'buildingStatusWithPrev' => [
2,
array(
'name' => 'Test / master',
'activity' => 'Building',
'lastBuildLabel' => 13,
[
'name' => 'Test / master',
'activity' => 'Building',
'lastBuildLabel' => 13,
'lastBuildStatus' => 'Failure',
'lastBuildTime' => '2014-10-13T13:13:13+0000',
'webUrl' => 'http://php-censor.local/build/view/78',
)
),
'successStatus' => array(
'lastBuildTime' => '2014-10-13T13:13:13+0000',
'webUrl' => 'http://php-censor.local/build/view/78',
]
],
'successStatus' => [
3,
array(
'name' => 'Test / master',
'activity' => 'Sleeping',
'lastBuildLabel' => 7,
[
'name' => 'Test / master',
'activity' => 'Sleeping',
'lastBuildLabel' => 7,
'lastBuildStatus' => 'Success',
'lastBuildTime' => '2014-10-25T21:50:02+0000',
'webUrl' => 'http://php-censor.local/build/view/7',
)
),
'failureStatus' => array(
'lastBuildTime' => '2014-10-25T21:50:02+0000',
'webUrl' => 'http://php-censor.local/build/view/7',
]
],
'failureStatus' => [
4,
array(
'name' => 'Test / master',
'activity' => 'Sleeping',
'lastBuildLabel' => 13,
[
'name' => 'Test / master',
'activity' => 'Sleeping',
'lastBuildLabel' => 13,
'lastBuildStatus' => 'Failure',
'lastBuildTime' => '2014-10-13T13:13:13+0000',
'webUrl' => 'http://php-censor.local/build/view/13',
)
),
'pending' => array(
'lastBuildTime' => '2014-10-13T13:13:13+0000',
'webUrl' => 'http://php-censor.local/build/view/13',
]
],
'pending' => [
5,
array(
'name' => 'Test / master',
'activity' => 'Pending',
'lastBuildLabel' => 7,
[
'name' => 'Test / master',
'activity' => 'Pending',
'lastBuildLabel' => 7,
'lastBuildStatus' => 'Success',
'lastBuildTime' => '2014-10-25T21:50:02+0000',
'webUrl' => 'http://php-censor.local/build/view/1000',
)
),
);
'lastBuildTime' => '2014-10-25T21:50:02+0000',
'webUrl' => 'http://php-censor.local/build/view/1000',
]
],
];
}
}

View file

@ -53,13 +53,13 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase
public function testExecute_CreateProjectWithOptions()
{
$options = array(
'ssh_private_key' => 'private',
'ssh_public_key' => 'public',
$options = [
'ssh_private_key' => 'private',
'ssh_public_key' => 'public',
'allow_public_status' => 1,
'build_config' => 'config',
'branch' => 'testbranch',
);
'build_config' => 'config',
'branch' => 'testbranch',
];
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', $options);
@ -102,11 +102,11 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase
$project = new Project();
$project->setAllowPublicStatus(1);
$options = array(
$options = [
'ssh_private_key' => 'private',
'ssh_public_key' => 'public',
'build_config' => 'config',
);
'ssh_public_key' => 'public',
'build_config' => 'config',
];
$returnValue = $this->testedService->updateProject($project, 'Test Project', 'github', 'block8/phpci', $options);