From 9393d11c0b1b698c89e3291d4801bb249de7cc4a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 22 Apr 2015 16:44:00 +0200 Subject: [PATCH 01/18] Display an error message when enabled modules cannot be read because /etc/icingaweb2 is not readable resolves #9141 --- library/Icinga/Application/Modules/Manager.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 90e55f0b4..84ee5e650 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -101,6 +101,16 @@ class Manager */ private function detectEnabledModules() { + if (false === file_exists($parent = dirname($this->enableDir))) { + return; + } + if (false === is_readable($parent)) { + throw new NotReadableError( + 'Cannot read enabled modules. Module directory\'s parent directory "%s" is not readable', + $parent + ); + } + if (! file_exists($this->enableDir)) { return; } From 1daecbbca0cd5d3251e81a9702f87ca60f6781f7 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 22 Apr 2015 17:04:31 +0200 Subject: [PATCH 02/18] Don't use `false === ...' when `! ...' is enough --- library/Icinga/Application/Modules/Manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 84ee5e650..e3e5ec6f2 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -101,10 +101,10 @@ class Manager */ private function detectEnabledModules() { - if (false === file_exists($parent = dirname($this->enableDir))) { + if (! file_exists($parent = dirname($this->enableDir))) { return; } - if (false === is_readable($parent)) { + if (! is_readable($parent)) { throw new NotReadableError( 'Cannot read enabled modules. Module directory\'s parent directory "%s" is not readable', $parent From 9cd7765d9ed57aa9e0ebf110604d90aaed4645d2 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 22 Apr 2015 17:25:51 +0200 Subject: [PATCH 03/18] If session_save_path() returns '', use sys_get_temp_dir() resolves #8994 --- library/Icinga/Web/Session/PhpSession.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Icinga/Web/Session/PhpSession.php b/library/Icinga/Web/Session/PhpSession.php index f4aa72fa3..7f47763c0 100644 --- a/library/Icinga/Web/Session/PhpSession.php +++ b/library/Icinga/Web/Session/PhpSession.php @@ -77,7 +77,7 @@ class PhpSession extends Session } } - $sessionSavePath = session_save_path(); + $sessionSavePath = session_save_path() ?: sys_get_temp_dir(); if (session_module_name() === 'files' && !is_writable($sessionSavePath)) { throw new ConfigurationError("Can't save session, path '$sessionSavePath' is not writable."); } From 6ba6cb79404c02dc95648604148bfd0e1a89a66d Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 23 Apr 2015 11:58:54 +0200 Subject: [PATCH 04/18] Improve layout of dictionaries in the host and service detail views resolves #8474 --- modules/monitoring/application/views/helpers/Customvar.php | 2 +- modules/monitoring/public/css/module.less | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/views/helpers/Customvar.php b/modules/monitoring/application/views/helpers/Customvar.php index 32391b6ce..87bde6b77 100644 --- a/modules/monitoring/application/views/helpers/Customvar.php +++ b/modules/monitoring/application/views/helpers/Customvar.php @@ -38,7 +38,7 @@ class Zend_View_Helper_Customvar extends Zend_View_Helper_Abstract protected function renderObject($object) { - if (empty($object)) { + if (0 === count((array) $object)) { return '{}'; } $out = "{
    \n"; diff --git a/modules/monitoring/public/css/module.less b/modules/monitoring/public/css/module.less index f121bb66f..549328ef8 100644 --- a/modules/monitoring/public/css/module.less +++ b/modules/monitoring/public/css/module.less @@ -177,11 +177,14 @@ table.avp form.object-features div.header h4 { margin: 0; } -table.avp .customvar ul { +table.avp .customvar ul, +table.avp .customvar ul li { list-style-type: none; margin: 0; + margin-top: -0.5em; + margin-bottom: -0.5em; padding: 0; - padding-left: 1.5em; + padding-left: 0.5em; } div.selection-info { From e4a98430216b14218418fb16b6e15b6bfad929b6 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 23 Apr 2015 12:38:29 +0200 Subject: [PATCH 05/18] Show Icinga 2 boolean variables in the host and service detail views resolves #8747 --- .../monitoring/application/views/helpers/Customvar.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/helpers/Customvar.php b/modules/monitoring/application/views/helpers/Customvar.php index 87bde6b77..bb9f70a7e 100644 --- a/modules/monitoring/application/views/helpers/Customvar.php +++ b/modules/monitoring/application/views/helpers/Customvar.php @@ -15,8 +15,12 @@ class Zend_View_Helper_Customvar extends Zend_View_Helper_Abstract public function customvar($struct) { - if (is_string($struct) || is_int($struct) || is_float($struct)) { - return $this->view->escape((string) $struct); + if (is_scalar($struct)) { + return $this->view->escape( + is_string($struct) + ? $struct + : var_export($struct, true) + ); } elseif (is_array($struct)) { return $this->renderArray($struct); } elseif (is_object($struct)) { From a976d777b349421bde3e15ba0569dc9fbbbceb21 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 23 Apr 2015 13:31:02 +0200 Subject: [PATCH 06/18] Show custom variables visually separated in the host and service detail views resolves #8966 --- .../views/scripts/show/components/customvars.phtml | 5 +++++ modules/monitoring/public/css/module.less | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/show/components/customvars.phtml b/modules/monitoring/application/views/scripts/show/components/customvars.phtml index aa2e479e4..50b82dbef 100644 --- a/modules/monitoring/application/views/scripts/show/components/customvars.phtml +++ b/modules/monitoring/application/views/scripts/show/components/customvars.phtml @@ -1,3 +1,8 @@ + + +

    translate('Custom variables') ?>

    + + customvars as $name => $value) { diff --git a/modules/monitoring/public/css/module.less b/modules/monitoring/public/css/module.less index 549328ef8..4cc68e18e 100644 --- a/modules/monitoring/public/css/module.less +++ b/modules/monitoring/public/css/module.less @@ -173,7 +173,8 @@ form.instance-features span.description, form.object-features span.description { } } -table.avp form.object-features div.header h4 { +table.avp form.object-features div.header h4, +table.avp h4.customvar { margin: 0; } From 39042ab306c85af0b5320987e959c9f2b4135718 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 23 Apr 2015 17:44:00 +0200 Subject: [PATCH 07/18] Log each line of a multiline log message separatly resolves #9000 --- library/Icinga/Application/Logger.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Application/Logger.php b/library/Icinga/Application/Logger.php index 925695dad..61d5f4329 100644 --- a/library/Icinga/Application/Logger.php +++ b/library/Icinga/Application/Logger.php @@ -199,7 +199,9 @@ class Logger $this->writer->log(static::ERROR, $error_message); } - $this->writer->log($level, $message); + foreach (explode("\n", $message) as $msg) { + $this->writer->log($level, $msg); + } } } From a429617a9523afb270a6b9393855a48232653d5a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 24 Apr 2015 10:17:35 +0200 Subject: [PATCH 08/18] Revert "Log each line of a multiline log message separatly" This reverts commit 39042ab306c85af0b5320987e959c9f2b4135718. --- library/Icinga/Application/Logger.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/Icinga/Application/Logger.php b/library/Icinga/Application/Logger.php index 61d5f4329..925695dad 100644 --- a/library/Icinga/Application/Logger.php +++ b/library/Icinga/Application/Logger.php @@ -199,9 +199,7 @@ class Logger $this->writer->log(static::ERROR, $error_message); } - foreach (explode("\n", $message) as $msg) { - $this->writer->log($level, $msg); - } + $this->writer->log($level, $message); } } From 5ba539b7c11407f751b33eb6a441180112e2ecdb Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 24 Apr 2015 10:28:45 +0200 Subject: [PATCH 09/18] SyslogWriter: replace \n w/ 4 spaces in multiline log messages --- library/Icinga/Application/Logger/Writer/SyslogWriter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Icinga/Application/Logger/Writer/SyslogWriter.php b/library/Icinga/Application/Logger/Writer/SyslogWriter.php index e18c5eeec..4494c9971 100644 --- a/library/Icinga/Application/Logger/Writer/SyslogWriter.php +++ b/library/Icinga/Application/Logger/Writer/SyslogWriter.php @@ -67,6 +67,6 @@ class SyslogWriter extends LogWriter public function log($level, $message) { openlog($this->ident, LOG_PID, $this->facility); - syslog(static::$severityMap[$level], $message); + syslog(static::$severityMap[$level], str_replace("\n", ' ', $message)); } } From 3d53e6f9b58654577ce7cecc9a3863f37864d614 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 24 Apr 2015 11:10:40 +0200 Subject: [PATCH 10/18] Icinga\Protocol\File\FileReader::count(): call iterator_count() only once per instance and cache the returned value --- library/Icinga/Protocol/File/FileReader.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Protocol/File/FileReader.php b/library/Icinga/Protocol/File/FileReader.php index aaef31840..8fb1ed4cb 100644 --- a/library/Icinga/Protocol/File/FileReader.php +++ b/library/Icinga/Protocol/File/FileReader.php @@ -26,6 +26,13 @@ class FileReader implements Selectable, Countable */ protected $filename; + /** + * Cache for static::count() + * + * @var int + */ + protected $count = null; + /** * Create a new reader * @@ -71,7 +78,10 @@ class FileReader implements Selectable, Countable */ public function count() { - return iterator_count($this->iterate()); + if ($this->count === null) { + $this->count = iterator_count($this->iterate()); + } + return $this->count; } /** From ec82b3bc0902c347feec2ddef7eb008cd0ad2f15 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 24 Apr 2015 15:04:19 +0200 Subject: [PATCH 11/18] Implement Icinga\Protocol\File\LogFileIterator --- .../Icinga/Protocol/File/LogFileIterator.php | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 library/Icinga/Protocol/File/LogFileIterator.php diff --git a/library/Icinga/Protocol/File/LogFileIterator.php b/library/Icinga/Protocol/File/LogFileIterator.php new file mode 100644 index 000000000..4b587b58e --- /dev/null +++ b/library/Icinga/Protocol/File/LogFileIterator.php @@ -0,0 +1,154 @@ +file = new SplFileObject($filename); + $this->file->setFlags( + SplFileObject::DROP_NEW_LINE | + SplFileObject::READ_AHEAD + ); + $this->fields = $fields; + } + + public function rewind() + { + $this->file->rewind(); + $this->index = 0; + $this->nextMessage(); + } + + public function next() + { + $this->file->next(); + ++$this->index; + $this->nextMessage(); + } + + /** + * @return string + */ + public function current() + { + return $this->current; + } + + /** + * @return int + */ + public function key() + { + return $this->index; + } + + /** + * @return boolean + */ + public function valid() + { + return $this->valid; + } + + protected function nextMessage() + { + $message = $this->next === null ? array() : array($this->next); + $this->valid = null; + while ($this->file->valid()) { + if (false === ($res = preg_match( + $this->fields, $current = $this->file->current() + ))) { + throw new IcingaException('Failed at preg_match()'); + } + if (empty($message)) { + if ($res === 1) { + $message[] = $current; + } + } else if ($res === 1) { + $this->next = $current; + $this->valid = true; + break; + } else { + $message[] = $current; + } + + $this->file->next(); + } + if ($this->valid === null) { + $this->next = null; + $this->valid = ! empty($message); + } + + if ($this->valid) { + while (! empty($message)) { + $matches = array(); + if (false === ($res = preg_match( + $this->fields, implode(PHP_EOL, $message), $matches + ))) { + throw new IcingaException('Failed at preg_match()'); + } + if ($res === 1) { + $this->current = $matches; + return; + } + array_pop($message); + } + $this->valid = false; + } + } From 7c0be30def6ab64edc800a5c503da7ca5b2dd364 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 24 Apr 2015 16:30:29 +0200 Subject: [PATCH 12/18] Handle and display multiline log messages correctly --- application/controllers/ListController.php | 8 +++----- application/views/scripts/list/applicationlog.phtml | 2 +- library/Icinga/Protocol/File/FileReader.php | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 972573dc1..ca7265f0e 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -44,14 +44,12 @@ class ListController extends Controller } $this->addTitleTab('application log'); - $pattern = '/^(?[0-9]{4}(-[0-9]{2}){2}' // date - . 'T[0-9]{2}(:[0-9]{2}){2}([\\+\\-][0-9]{2}:[0-9]{2})?)' // time - . ' - (?[A-Za-z]+)' // loglevel - . ' - (?.*)$/'; $resource = new FileReader(new ConfigObject(array( 'filename' => Config::app()->get('logging', 'file'), - 'fields' => $pattern + 'fields' => '/(?[0-9]{4}(?:-[0-9]{2}){2}' // date + . 'T[0-9]{2}(?::[0-9]{2}){2}(?:[\+\-][0-9]{2}:[0-9]{2})?)' // time + . ' - (?[A-Za-z]+) - (?.*)(?!.)/msS' // loglevel, message ))); $this->view->logData = $resource->select()->order('DESC')->paginate(); diff --git a/application/views/scripts/list/applicationlog.phtml b/application/views/scripts/list/applicationlog.phtml index cc412eb9c..00102e855 100644 --- a/application/views/scripts/list/applicationlog.phtml +++ b/application/views/scripts/list/applicationlog.phtml @@ -19,7 +19,7 @@ escape($value->loglevel) ?> - escape($value->message) ?> + escape($value->message), false) ?> diff --git a/library/Icinga/Protocol/File/FileReader.php b/library/Icinga/Protocol/File/FileReader.php index 8fb1ed4cb..2c43d390a 100644 --- a/library/Icinga/Protocol/File/FileReader.php +++ b/library/Icinga/Protocol/File/FileReader.php @@ -58,7 +58,7 @@ class FileReader implements Selectable, Countable */ public function iterate() { - return new FileIterator($this->filename, $this->fields); + return new LogFileIterator($this->filename, $this->fields); } /** From 6f0fd7d44de11efb4631ccb5730c0b337c570560 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 27 Apr 2015 13:06:55 +0200 Subject: [PATCH 13/18] Remove right petrol border from plugin output in the host and service detail views resolves #8967 --- modules/monitoring/public/css/module.less | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/monitoring/public/css/module.less b/modules/monitoring/public/css/module.less index 4cc68e18e..97d236966 100644 --- a/modules/monitoring/public/css/module.less +++ b/modules/monitoring/public/css/module.less @@ -32,7 +32,6 @@ p.pluginoutput { } div.pluginoutput { - border-right: solid 5px @colorPetrol; overflow: auto; color: black; margin-bottom: 1em; From c839cc0b0884fa33fa0cf95c5af84c60af6f3a61 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 27 Apr 2015 13:16:54 +0200 Subject: [PATCH 14/18] Remove exclamation mark from the notification "Authentication order updated!" resolves #8960 --- application/forms/Config/AuthenticationBackendReorderForm.php | 2 +- application/locale/it_IT/LC_MESSAGES/icinga.po | 2 +- application/locale/pt_BR/LC_MESSAGES/icinga.po | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/application/forms/Config/AuthenticationBackendReorderForm.php b/application/forms/Config/AuthenticationBackendReorderForm.php index e4ac90c12..34f20d851 100644 --- a/application/forms/Config/AuthenticationBackendReorderForm.php +++ b/application/forms/Config/AuthenticationBackendReorderForm.php @@ -51,7 +51,7 @@ class AuthenticationBackendReorderForm extends ConfigForm try { if ($configForm->move($backendName, $position)->save()) { - Notification::success($this->translate('Authentication order updated!')); + Notification::success($this->translate('Authentication order updated')); } else { return false; } diff --git a/application/locale/it_IT/LC_MESSAGES/icinga.po b/application/locale/it_IT/LC_MESSAGES/icinga.po index 2b867ca14..c61195216 100644 --- a/application/locale/it_IT/LC_MESSAGES/icinga.po +++ b/application/locale/it_IT/LC_MESSAGES/icinga.po @@ -199,7 +199,7 @@ msgid "Authentication backend name missing" msgstr "Nome del Backend di autenticazione non specificato" #: /usr/share/icingaweb2/application/forms/Config/AuthenticationBackendReorderForm.php:54 -msgid "Authentication order updated!" +msgid "Authentication order updated" msgstr "Ordine di autenticazione aggiornato!" #: /usr/share/icingaweb2/application/forms/AutoRefreshForm.php:44 diff --git a/application/locale/pt_BR/LC_MESSAGES/icinga.po b/application/locale/pt_BR/LC_MESSAGES/icinga.po index 01dc18a9f..ba35c265e 100644 --- a/application/locale/pt_BR/LC_MESSAGES/icinga.po +++ b/application/locale/pt_BR/LC_MESSAGES/icinga.po @@ -130,7 +130,7 @@ msgid "Authentication backend name missing" msgstr "Falta o nome do backend de autenticação" #: /usr/local/icingaweb/application/forms/Config/AuthenticationBackendReorderForm.php:55 -msgid "Authentication order updated!" +msgid "Authentication order updated" msgstr "Ordem da autenticação atualizada!" #: /usr/local/icingaweb/application/forms/Config/AuthenticationBackendConfigForm.php:307 From 9917e63e020991bfc3895fb954968efc610a0f31 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 27 Apr 2015 13:16:54 +0200 Subject: [PATCH 15/18] Remove exclamation mark from the notification "Authentication order updated!"'s translations --- application/locale/it_IT/LC_MESSAGES/icinga.po | 2 +- application/locale/pt_BR/LC_MESSAGES/icinga.po | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/locale/it_IT/LC_MESSAGES/icinga.po b/application/locale/it_IT/LC_MESSAGES/icinga.po index c61195216..73d616bfa 100644 --- a/application/locale/it_IT/LC_MESSAGES/icinga.po +++ b/application/locale/it_IT/LC_MESSAGES/icinga.po @@ -200,7 +200,7 @@ msgstr "Nome del Backend di autenticazione non specificato" #: /usr/share/icingaweb2/application/forms/Config/AuthenticationBackendReorderForm.php:54 msgid "Authentication order updated" -msgstr "Ordine di autenticazione aggiornato!" +msgstr "Ordine di autenticazione aggiornato" #: /usr/share/icingaweb2/application/forms/AutoRefreshForm.php:44 msgid "Auto refresh successfully disabled" diff --git a/application/locale/pt_BR/LC_MESSAGES/icinga.po b/application/locale/pt_BR/LC_MESSAGES/icinga.po index ba35c265e..16aba2378 100644 --- a/application/locale/pt_BR/LC_MESSAGES/icinga.po +++ b/application/locale/pt_BR/LC_MESSAGES/icinga.po @@ -131,7 +131,7 @@ msgstr "Falta o nome do backend de autenticação" #: /usr/local/icingaweb/application/forms/Config/AuthenticationBackendReorderForm.php:55 msgid "Authentication order updated" -msgstr "Ordem da autenticação atualizada!" +msgstr "Ordem da autenticação atualizada" #: /usr/local/icingaweb/application/forms/Config/AuthenticationBackendConfigForm.php:307 msgid "Autologin" From f3ca80ffced18497322a74b8b49e94e88bb31cdc Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 27 Apr 2015 14:44:19 +0200 Subject: [PATCH 16/18] Don't fetchAll() and loop afterwards in the alert summary report refs #8340 --- .../application/controllers/AlertsummaryController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index dcc805286..5b4e2e3fa 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -274,7 +274,6 @@ class Monitoring_AlertsummaryController extends Controller ); $defects = array(); - $records = $query->getQuery()->fetchAll(); $period = $this->createPeriod($interval); foreach ($period as $entry) { @@ -282,7 +281,7 @@ class Monitoring_AlertsummaryController extends Controller $defects[$id] = array($id, 0); } - foreach ($records as $item) { + foreach ($query as $item) { $id = $this->getPeriodFormat($interval, $item->timestamp); if (empty($defects[$id])) { $defects[$id] = array($id, 0); From d27b94dcecdd18b59912c851234b80fdd5d93cec Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 28 Apr 2015 12:52:59 +0200 Subject: [PATCH 17/18] Revert "Don't fetchAll() and loop afterwards in the alert summary report" This reverts commit f3ca80ffced18497322a74b8b49e94e88bb31cdc. --- .../application/controllers/AlertsummaryController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index 5b4e2e3fa..dcc805286 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -274,6 +274,7 @@ class Monitoring_AlertsummaryController extends Controller ); $defects = array(); + $records = $query->getQuery()->fetchAll(); $period = $this->createPeriod($interval); foreach ($period as $entry) { @@ -281,7 +282,7 @@ class Monitoring_AlertsummaryController extends Controller $defects[$id] = array($id, 0); } - foreach ($query as $item) { + foreach ($records as $item) { $id = $this->getPeriodFormat($interval, $item->timestamp); if (empty($defects[$id])) { $defects[$id] = array($id, 0); From 034421d0cba6fcf117445e04746663b8e50fc5ed Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 30 Apr 2015 15:20:19 +0200 Subject: [PATCH 18/18] Fix form tests utilizing Mockery's partial mock functionality Since an update of Mockery, partial mocks do not call the constructor of their mocked classes anymore without explicitly passing a non empty array. This is a regression of the following bug: https://github.com/padraic/mockery/issues/144 --- .../forms/Config/Authentication/DbBackendFormTest.php | 6 ++++-- .../forms/Config/Authentication/LdapBackendFormTest.php | 6 ++++-- .../forms/Config/Resource/LdapResourceFormTest.php | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/php/application/forms/Config/Authentication/DbBackendFormTest.php b/test/php/application/forms/Config/Authentication/DbBackendFormTest.php index b7d1ea3c1..fb93f6050 100644 --- a/test/php/application/forms/Config/Authentication/DbBackendFormTest.php +++ b/test/php/application/forms/Config/Authentication/DbBackendFormTest.php @@ -31,7 +31,8 @@ class DbBackendFormTest extends BaseTestCase ->shouldReceive('count') ->andReturn(2); - $form = Mockery::mock('Icinga\Forms\Config\Authentication\DbBackendForm[getView]'); + // Passing array(null) is required to make Mockery call the constructor... + $form = Mockery::mock('Icinga\Forms\Config\Authentication\DbBackendForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); @@ -56,7 +57,8 @@ class DbBackendFormTest extends BaseTestCase ->shouldReceive('count') ->andReturn(0); - $form = Mockery::mock('Icinga\Forms\Config\Authentication\DbBackendForm[getView]'); + // Passing array(null) is required to make Mockery call the constructor... + $form = Mockery::mock('Icinga\Forms\Config\Authentication\DbBackendForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); diff --git a/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php b/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php index d31033ba9..56ea08987 100644 --- a/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php +++ b/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php @@ -31,7 +31,8 @@ class LdapBackendFormTest extends BaseTestCase Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend') ->shouldReceive('assertAuthenticationPossible')->andReturnNull(); - $form = Mockery::mock('Icinga\Forms\Config\Authentication\LdapBackendForm[getView]'); + // Passing array(null) is required to make Mockery call the constructor... + $form = Mockery::mock('Icinga\Forms\Config\Authentication\LdapBackendForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); @@ -55,7 +56,8 @@ class LdapBackendFormTest extends BaseTestCase Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend') ->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException); - $form = Mockery::mock('Icinga\Forms\Config\Authentication\LdapBackendForm[getView]'); + // Passing array(null) is required to make Mockery call the constructor... + $form = Mockery::mock('Icinga\Forms\Config\Authentication\LdapBackendForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); diff --git a/test/php/application/forms/Config/Resource/LdapResourceFormTest.php b/test/php/application/forms/Config/Resource/LdapResourceFormTest.php index d074f1b3b..f382f8bb8 100644 --- a/test/php/application/forms/Config/Resource/LdapResourceFormTest.php +++ b/test/php/application/forms/Config/Resource/LdapResourceFormTest.php @@ -29,7 +29,8 @@ class LdapResourceFormTest extends BaseTestCase Mockery::mock()->shouldReceive('testCredentials')->once()->andReturn(true)->getMock() ); - $form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]'); + // Passing array(null) is required to make Mockery call the constructor... + $form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); @@ -51,7 +52,8 @@ class LdapResourceFormTest extends BaseTestCase Mockery::mock()->shouldReceive('testCredentials')->once()->andThrow('\Exception')->getMock() ); - $form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]'); + // Passing array(null) is required to make Mockery call the constructor... + $form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; });