diff --git a/docs/en/logging.md b/docs/en/logging.md index 48f6ff9a..0edbbb1d 100644 --- a/docs/en/logging.md +++ b/docs/en/logging.md @@ -13,14 +13,14 @@ The only step required to activate logging is to create a file in the root direc ```php 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. diff --git a/src/PHPCensor/Controller/WebhookController.php b/src/PHPCensor/Controller/WebhookController.php index 4810a8d4..4b29a35d 100644 --- a/src/PHPCensor/Controller/WebhookController.php +++ b/src/PHPCensor/Controller/WebhookController.php @@ -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]; } /** diff --git a/src/PHPCensor/Migrations/20160623100223_project_table_defaults.php b/src/PHPCensor/Migrations/20160623100223_project_table_defaults.php index 079db327..5b2f88d0 100644 --- a/src/PHPCensor/Migrations/20160623100223_project_table_defaults.php +++ b/src/PHPCensor/Migrations/20160623100223_project_table_defaults.php @@ -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(); } } diff --git a/src/PHPCensor/Model/Project.php b/src/PHPCensor/Model/Project.php index 5ccca74d..b0e9759f 100644 --- a/src/PHPCensor/Model/Project.php +++ b/src/PHPCensor/Model/Project.php @@ -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); diff --git a/src/PHPCensor/Store/BuildErrorStore.php b/src/PHPCensor/Store/BuildErrorStore.php index 13b83884..963b5e0b 100644 --- a/src/PHPCensor/Store/BuildErrorStore.php +++ b/src/PHPCensor/Store/BuildErrorStore.php @@ -74,7 +74,7 @@ class BuildErrorStore extends BuildErrorStoreBase $res = $stmt->fetch(\PDO::FETCH_ASSOC); return $res['total']; } else { - return array(); + return []; } } } diff --git a/tests/PHPCensor/Plugin/Util/TapParserTest.php b/tests/PHPCensor/Plugin/Util/TapParserTest.php index 244b2ea2..8c783d6f 100644 --- a/tests/PHPCensor/Plugin/Util/TapParserTest.php +++ b/tests/PHPCensor/Plugin/Util/TapParserTest.php @@ -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()); diff --git a/tests/PHPCensor/ProcessControl/ProcessControlTest.php b/tests/PHPCensor/ProcessControl/ProcessControlTest.php index 24fdd8a8..75a01a48 100644 --- a/tests/PHPCensor/ProcessControl/ProcessControlTest.php +++ b/tests/PHPCensor/ProcessControl/ProcessControlTest.php @@ -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); diff --git a/tests/PHPCensor/Service/BuiltStatusServiceTest.php b/tests/PHPCensor/Service/BuiltStatusServiceTest.php index 66f8c1c9..511bf4c8 100644 --- a/tests/PHPCensor/Service/BuiltStatusServiceTest.php +++ b/tests/PHPCensor/Service/BuiltStatusServiceTest.php @@ -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', + ] + ], + ]; } } \ No newline at end of file diff --git a/tests/PHPCensor/Service/ProjectServiceTest.php b/tests/PHPCensor/Service/ProjectServiceTest.php index 9899c059..314ff95b 100644 --- a/tests/PHPCensor/Service/ProjectServiceTest.php +++ b/tests/PHPCensor/Service/ProjectServiceTest.php @@ -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);