Merge pull request #2962 from Icinga/travis

Enable PHP CodeSniffer in travis testing
This commit is contained in:
lippserd 2017-11-08 12:25:45 +01:00 committed by GitHub
commit 99297a20da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 127 additions and 53 deletions

View File

@ -1,6 +1,6 @@
language: php
dist: trusty
sudo: required
sudo: false
php:
- '5.4'
@ -13,7 +13,10 @@ matrix:
include:
- php: '5.3'
dist: precise
sudo: required
env:
- PHPCS_VERSION=2.9.1
- LOCALE_GEN=1
- ENABLE_LDAP=1
services:
@ -35,13 +38,12 @@ notifications:
# also see: test/setup_vendor.sh
before_script:
- php -m
- sudo locale-gen en_US.UTF-8 de_DE.UTF-8 fr_FR.UTF-8
- sh -c '[ -z $LOCALE_GEN ] || sudo locale-gen en_US.UTF-8 de_DE.UTF-8 fr_FR.UTF-8'
- sh -c '[ -z $ENABLE_LDAP ] || phpenv config-add test/travis-ldap.ini'
- test/travis_database.sh
- test/setup_vendor.sh
script:
# also see: modules/test/application/clicommands/PhpCommand.php
# phpcs is disabled until fixed...
# - php phpcs.phar -p --standard=icingaweb2.ruleset.xml --extensions=php --encoding=utf-8 application/ library/Icinga modules/ test/
- php phpcs.phar
- php phpunit.phar -c modules/test/phpunit.xml --verbose

View File

@ -3,8 +3,27 @@
<ruleset name="icingaweb2">
<description>The default PSR-2 standard with specifically excluded non-critical sniffs</description>
<!-- Include the whole PSR-2 standard -->
<rule ref="PSR2" />
<rule ref="PSR2"/>
<!-- Exclude patterns for PSR-2 Sniffs -->
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<severity>0</severity>
</rule>
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
<severity>0</severity>
</rule>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<severity>0</severity>
</rule>
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>library/Icinga/Application/Cli.php</exclude-pattern>
<exclude-pattern>library/Icinga/Application/EmbeddedWeb.php</exclude-pattern>
<exclude-pattern>library/Icinga/Application/functions.php</exclude-pattern>
<exclude-pattern>library/Icinga/Application/LegacyWeb.php</exclude-pattern>
<exclude-pattern>library/Icinga/Application/Web.php</exclude-pattern>
<exclude-pattern>library/Icinga/File/Pdf.php</exclude-pattern>
<exclude-pattern>modules/doc/library/Doc/Renderer/DocSectionRenderer.php</exclude-pattern>
<exclude-pattern>modules/monitoring/library/Monitoring/Plugin.php</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>*/test/php/*</exclude-pattern>
</rule>
@ -25,5 +44,6 @@
</rule>
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>*/modules/monitoring/library/Monitoring/Backend/Ido/Query/*</exclude-pattern>
<exclude-pattern>*/modules/monitoring/library/Monitoring/Backend/Livestatus/Query/*</exclude-pattern>
</rule>
</ruleset>

View File

@ -5,7 +5,6 @@ namespace Icinga\Exception\Http;
use Icinga\Exception\IcingaException;
/**
* Base class for HTTP exceptions
*/

View File

@ -3,7 +3,6 @@
namespace Icinga\Exception\Http;
interface HttpExceptionInterface
{
/**

View File

@ -25,7 +25,7 @@ class Json
{
if (version_compare(phpversion(), '5.4.0', '<')) {
$encoded = json_encode($value);
} else if (version_compare(phpversion(), '5.5.0', '<')) {
} elseif (version_compare(phpversion(), '5.5.0', '<')) {
$encoded = json_encode($value, $options);
} else {
$encoded = json_encode($value, $options, $depth);

View File

@ -772,7 +772,8 @@ class Form extends Zend_Form
$action = $action->without(array_keys($this->getElements()));
}
// TODO(el): Re-evalute this necessity. JavaScript could use the container's URL if there's no action set.
// TODO(el): Re-evalute this necessity.
// JavaScript could use the container'sURL if there's no action set.
// We MUST set an action as JS gets confused otherwise, if
// this form is being displayed in an additional column
$this->setAction($action);

View File

@ -176,8 +176,10 @@ class JsonResponse extends Response
'status' => $this->status
);
switch ($this->status) {
/** @noinspection PhpMissingBreakStatementInspection */
case static::STATUS_ERROR:
$body['message'] = $this->getErrorMessage();
// Fallthrough
case static::STATUS_FAIL:
$failData = $this->getFailData();
if ($failData !== null || $this->status === static::STATUS_FAIL) {

View File

@ -74,14 +74,15 @@ class InlinePie extends AbstractWidget
* @var string
*/
private $template =<<<'EOD'
<span sparkType="pie" class="sparkline {class}" title="{title}" role="img" aria-label="{title}" sparkSliceColors="[{colors}]" values="{data}">
</span>
<span sparkType="pie" class="sparkline {class}" title="{title}" role="img" aria-label="{title}"
sparkSliceColors="[{colors}]" values="{data}"></span>
{noscript}
EOD;
private $noscript =<<<'EOD'
<noscript>
<img width={size} height={size} class="inlinepie {class}" title="{title}" role="img" aria-label="{title}" src="{url}" data-icinga-colors="{colors}" data-icinga-values="{data}"/>
<img width={size} height={size} class="inlinepie {class}" title="{title}" role="img" aria-label="{title}"
src="{url}" data-icinga-colors="{colors}" data-icinga-values="{data}"/>
</noscript>
EOD;

View File

@ -36,7 +36,9 @@ EOT;
*/
private $dropdownTpl = <<< 'EOT'
<li class="dropdown-nav-item">
<a href="#" class="dropdown-toggle" title="{TITLE}" aria-label="{TITLE}"><i aria-hidden="true" class="icon-down-open"></i></a>
<a href="#" class="dropdown-toggle" title="{TITLE}" aria-label="{TITLE}">
<i aria-hidden="true" class="icon-down-open"></i>
</a>
<ul class="nav">
{TABS}
</ul>

View File

@ -127,7 +127,6 @@ class UserDomainMigration
rename($from, $to);
}
}
}
protected function migrateNavigation()

View File

@ -148,7 +148,8 @@ class ListCommand extends Command
* icingacli monitoring list --problems
* icingacli monitoring list --problems --service_state_type 0
* icingacli monitoring list --host=local* --service=*disk*
* icingacli monitoring list --columns 'host,service,service_output' --format='$host$: $service$ ($service_output$)'
* icingacli monitoring list --columns 'host,service,service_output' \
--format='$host$: $service$ ($service_output$)'
*/
public function statusAction()
{

View File

@ -68,7 +68,8 @@ class CommentController extends Controller
$this->view->comment = $this->comment;
if ($this->hasPermission('monitoring/command/comment/delete')) {
$listUrl = Url::fromPath('monitoring/list/comments')->setQueryString('comment_type=comment|comment_type=ack');
$listUrl = Url::fromPath('monitoring/list/comments')
->setQueryString('comment_type=comment|comment_type=ack');
$form = new DeleteCommentCommandForm();
$form
->populate(array(

View File

@ -369,7 +369,9 @@ class TransportConfigForm extends ConfigForm
'order' => 0,
'ignore' => true,
'label' => $this->translate('Force Changes'),
'description' => $this->translate('Check this box to enforce changes without connectivity validation')
'description' => $this->translate(
'Check this box to enforce changes without connectivity validation'
)
)
);

View File

@ -204,7 +204,10 @@ class ApiCommandTransport implements CommandTransportInterface
->setPayload($command->getData())
->send();
} catch (JsonDecodeException $e) {
throw new CommandTransportException('Got invalid JSON response from the Icinga 2 API: %s', $e->getMessage());
throw new CommandTransportException(
'Got invalid JSON response from the Icinga 2 API: %s',
$e->getMessage()
);
}
if (isset($response['error'])) {
@ -256,9 +259,15 @@ class ApiCommandTransport implements CommandTransportInterface
try {
$response = $request->send();
} catch (CurlException $e) {
throw new CommandTransportException('Couldn\'t connect to the Icinga 2 API: %s', $e->getMessage());
throw new CommandTransportException(
'Couldn\'t connect to the Icinga 2 API: %s',
$e->getMessage()
);
} catch (JsonDecodeException $e) {
throw new CommandTransportException('Got invalid JSON response from the Icinga 2 API: %s', $e->getMessage());
throw new CommandTransportException(
'Got invalid JSON response from the Icinga 2 API: %s',
$e->getMessage()
);
}
if (isset($response['error'])) {

View File

@ -45,8 +45,7 @@ class Controller extends IcingaWebController
$query->limit(); // Resets any default limit and offset
}
switch ($desiredFormat)
{
switch ($desiredFormat) {
case 'sql':
echo '<pre>'
. htmlspecialchars(wordwrap($query->dump()))
@ -57,7 +56,10 @@ class Controller extends IcingaWebController
$response
->setHeader('Content-Type', 'application/json')
->setHeader('Cache-Control', 'no-store')
->setHeader('Content-Disposition', 'inline; filename=' . $this->getRequest()->getActionName() . '.json')
->setHeader(
'Content-Disposition',
'inline; filename=' . $this->getRequest()->getActionName() . '.json'
)
->appendBody(Json::encode($query->getQuery()->fetchAll()))
->sendResponse();
exit;
@ -66,7 +68,10 @@ class Controller extends IcingaWebController
$response
->setHeader('Content-Type', 'text/csv')
->setHeader('Cache-Control', 'no-store')
->setHeader('Content-Disposition', 'attachment; filename=' . $this->getRequest()->getActionName() . '.csv')
->setHeader(
'Content-Disposition',
'attachment; filename=' . $this->getRequest()->getActionName() . '.csv'
)
->appendBody((string) Csv::fromQuery($query))
->sendResponse();
exit;

View File

@ -290,16 +290,20 @@ class Perfdata
}
switch (count($parts)) {
/* @noinspection PhpMissingBreakStatementInspection */
case 5:
if ($parts[4] !== '') {
$this->maxValue = self::convert($parts[4], $this->unit);
}
/* @noinspection PhpMissingBreakStatementInspection */
case 4:
if ($parts[3] !== '') {
$this->minValue = self::convert($parts[3], $this->unit);
}
/* @noinspection PhpMissingBreakStatementInspection */
case 3:
$this->criticalThreshold = trim($parts[2]) ? trim($parts[2]) : null;
// Fallthrough
case 2:
$this->warningThreshold = trim($parts[1]) ? trim($parts[1]) : null;
}

View File

@ -96,7 +96,8 @@ class ConfigCommand extends Command
*
* --path=<urlpath> The URL path to Icinga Web 2 [/icingaweb2]
*
* --root|--document-root=<directory> The directory from which the webserver will serve files [/path/to/icingaweb2/public]
* --root|--document-root=<directory> The directory from which the webserver will serve files
* [/path/to/icingaweb2/public]
*
* --config=<directory> Path to Icinga Web 2's configuration files [/etc/icingaweb2]
*
@ -106,9 +107,13 @@ class ConfigCommand extends Command
*
* icingacli setup config webserver apache
*
* icingacli setup config webserver apache --path=/icingaweb2 --document-root=/usr/share/icingaweb2/public --config=/etc/icingaweb2
* icingacli setup config webserver apache \
* --path=/icingaweb2 \
* --document-root=/usr/share/icingaweb2/public \
* --config=/etc/icingaweb2
*
* icingacli setup config webserver apache --file=/etc/apache2/conf.d/icingaweb2.conf
* icingacli setup config webserver apache \
* --file=/etc/apache2/conf.d/icingaweb2.conf
*
* icingacli setup config webserver nginx
*/

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Test\Clicommands;
use Icinga\Application\Icinga;
use Icinga\Cli\Command;
/**
@ -10,18 +11,6 @@ use Icinga\Cli\Command;
*/
class PhpCommand extends Command
{
/**
* Default arguments and options for PHP_CodeSniffer
*
* @var array
*/
protected $phpcsDefaultParams = array(
'-p',
'--standard=PSR2',
'--extensions=php',
'--encoding=utf-8'
);
/**
* Run all unit-test suites
*
@ -42,6 +31,11 @@ class PhpCommand extends Command
* icingacli test php unit --verbose
* icingacli test php unit --build
* icingacli test php unit --include=*SpecialTest
*
* NOTES
*
* Default settings are defined via `modules/test/phpunit.xml` under icingaweb'
* installation directory.
*/
public function unitAction()
{
@ -69,11 +63,12 @@ class PhpCommand extends Command
$options[] = $include;
}
chdir(realpath(__DIR__ . '/../..'));
$command = $this->getEnvironmentVariables() . $phpUnit . ' ' . join(
' ',
array_merge($options, $this->params->getAllStandalone())
);
chdir(Icinga::app()->getBaseDir());
$command = $this->getEnvironmentVariables()
. $phpUnit
. ' -c modules/test/phpunit.xml'
. ' ' . join(' ', array_merge($options, $this->params->getAllStandalone()));
if ($this->isVerbose) {
$res = `$command`;
foreach (preg_split('/\n/', $res) as $line) {
@ -114,6 +109,11 @@ class PhpCommand extends Command
* icingacli test php style --build
* icingacli test php style --include=path/to/your/file
* icingacli test php style --exclude=*someFile* --exclude=someOtherFile*
*
* NOTES
*
* Default rules are defined via `phpcs.xml` and `icingaweb2.ruleset.xml` in icingaweb'
* installation directory.
*/
public function styleAction()
{
@ -141,20 +141,13 @@ class PhpCommand extends Command
$arguments = array_filter(array_map(function ($p) {
return realpath($p);
}, $include));
if (empty($arguments)) {
$arguments = array(
realpath(__DIR__ . '/../../../../application'),
realpath(__DIR__ . '/../../../../library/Icinga')
);
}
chdir(realpath(__DIR__ . '/../..'));
chdir(Icinga::app()->getBaseDir());
passthru(
$phpcs . ' ' . join(
' ',
array_merge(
$options,
$this->phpcsDefaultParams,
$arguments,
$this->params->getAllStandalone()
)

23
phpcs.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>Sniff our code a while</description>
<file>application/</file>
<file>library/Icinga</file>
<file>modules/</file>
<file>test/</file>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>application/fonts/fontello-ifont/*</exclude-pattern>
<arg value="wps"/>
<arg name="colors"/>
<arg name="report-width" value="auto"/>
<arg name="report-full"/>
<arg name="report-gitblame"/>
<arg name="report-summary"/>
<arg name="encoding" value="UTF-8"/>
<arg name="extensions" value="php"/>
<rule ref="icingaweb2.ruleset.xml" />
</ruleset>

View File

@ -4,7 +4,7 @@ set -ex
ICINGAWEB_HOME=${ICINGAWEB_HOME:="$(dirname "$(readlink -f $(dirname "$0"))")"}
PHP_VERSION="$(php -r 'echo phpversion();')"
PHPCS_VERSION=${PHPCS_VERSION:=2.9.1}
PHPCS_VERSION=${PHPCS_VERSION:=3.0.2}
MOCKERY_VERSION=${MOCKERY_VERSION:=0.9.9}
HAMCREST_VERSION=${HAMCREST_VERSION:=2.0.0}
@ -32,6 +32,12 @@ if [ ! -e "${phpcs_path}".phar ]; then
https://github.com/squizlabs/PHP_CodeSniffer/releases/download/${PHPCS_VERSION}/phpcs.phar
fi
ln -svf "${phpcs_path}".phar phpcs.phar
phpcbf_path="vendor/phpcbf-${PHPCS_VERSION}"
if [ ! -e "${phpcbf_path}".phar ]; then
wget -O "${phpcbf_path}".phar \
https://github.com/squizlabs/PHP_CodeSniffer/releases/download/${PHPCS_VERSION}/phpcbf.phar
fi
ln -svf "${phpcbf_path}".phar phpcbf.phar
# mockery
mockery_path="vendor/mockery-${MOCKERY_VERSION}"