From ca614b96cb9380f7f3d7223a9838c66aca974ff8 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 14 Apr 2015 08:29:42 -0500
Subject: [PATCH] lint: Squelch many of the strict errors from tests

---
 bootstrap.php                              |  2 +-
 include/class.draft.php                    |  2 +-
 include/class.list.php                     |  4 +++-
 include/class.orm.php                      |  2 +-
 include/class.sequence.php                 |  4 ++--
 include/class.task.php                     |  5 ++++-
 include/class.thread.php                   | 14 +++++++-------
 include/class.translation.php              |  5 ++++-
 setup/test/run-tests.php                   |  6 +-----
 setup/test/tests/mockdb.php                |  4 ++++
 setup/test/tests/test.header_functions.php |  2 --
 setup/test/tests/test.mail-parse.php       |  4 ++--
 12 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/bootstrap.php b/bootstrap.php
index b8971116f..47f617b62 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -57,7 +57,7 @@ class Bootstrap {
                 && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https');
     }
 
-    function defineTables($prefix) {
+    static function defineTables($prefix) {
         #Tables being used sytem wide
         define('SYSLOG_TABLE',$prefix.'syslog');
         define('SESSION_TABLE',$prefix.'session');
diff --git a/include/class.draft.php b/include/class.draft.php
index 8af88335e..5b2d8462b 100644
--- a/include/class.draft.php
+++ b/include/class.draft.php
@@ -137,7 +137,7 @@ class Draft extends VerySimpleModel {
         return parent::save($refetch);
     }
 
-    static function create($vars) {
+    static function create($vars=false) {
         $attachments = @$vars['attachments'];
         unset($vars['attachments']);
 
diff --git a/include/class.list.php b/include/class.list.php
index 782bfebaf..841ff3ea5 100644
--- a/include/class.list.php
+++ b/include/class.list.php
@@ -1299,7 +1299,9 @@ class TicketStatus  extends VerySimpleModel implements CustomListItem {
         return $this->getName();
     }
 
-    static function create($ht) {
+    static function create($ht=false) {
+        if (!is_array($ht))
+            return null;
 
         if (!isset($ht['mode']))
             $ht['mode'] = 1;
diff --git a/include/class.orm.php b/include/class.orm.php
index 43795a8e7..6a823273f 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -357,7 +357,7 @@ class VerySimpleModel {
         }
     }
 
-    function delete($pk=false) {
+    function delete() {
         $ex = DbEngine::delete($this);
         try {
             $ex->execute();
diff --git a/include/class.sequence.php b/include/class.sequence.php
index cc27801c5..cf75701fb 100644
--- a/include/class.sequence.php
+++ b/include/class.sequence.php
@@ -215,7 +215,7 @@ class RandomSequence extends Sequence {
     var $padding = '0';
 
     // Override the ORM constructor and do nothing
-    function __construct() {}
+    function __construct($ht=false) {}
 
     function __next($digits=6) {
         if ($digits < 6)
@@ -228,7 +228,7 @@ class RandomSequence extends Sequence {
         return $this->next($format);
     }
 
-    function save() {
+    function save($refetch=false) {
         throw new RuntimeException('RandomSequence is not database-backed');
     }
 }
diff --git a/include/class.task.php b/include/class.task.php
index eaf7ffcb9..a39c28a00 100644
--- a/include/class.task.php
+++ b/include/class.task.php
@@ -416,9 +416,12 @@ class Task extends TaskModel {
         return !self::lookupIdByNumber($number);
     }
 
-    static function create($vars) {
+    static function create($vars=false) {
         global $cfg;
 
+        if (!is_array($vars))
+            return null;
+
         $task = parent::create(array(
             'flags' => self::ISOPEN,
             'object_id' => $vars['object_id'],
diff --git a/include/class.thread.php b/include/class.thread.php
index 03fe49fb5..7e97f9fe2 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1035,7 +1035,7 @@ class ThreadEntry extends VerySimpleModel {
     }
 
     //new entry ... we're trusting the caller to check validity of the data.
-    static function create($vars) {
+    static function create($vars, &$errors=array()) {
         global $cfg;
 
         //Must have...
@@ -1159,7 +1159,7 @@ class ThreadEntry extends VerySimpleModel {
         return $entry;
     }
 
-    static function add($vars) {
+    static function add($vars, &$errors=array()) {
         return self::create($vars);
     }
 
@@ -1443,11 +1443,11 @@ class MessageThreadEntry extends ThreadEntry {
         return $this->getTitle();
     }
 
-    static function create($vars, &$errors) {
+    static function create($vars, &$errors=array()) {
         return static::add($vars, $errors);
     }
 
-    static function add($vars, &$errors) {
+    static function add($vars, &$errors=array()) {
 
         if (!$vars || !is_array($vars) || !$vars['threadId'])
             $errors['err'] = __('Missing or invalid data');
@@ -1481,11 +1481,11 @@ class ResponseThreadEntry extends ThreadEntry {
         return $this->getStaff();
     }
 
-    static function create($vars, &$errors) {
+    static function create($vars, &$errors=array()) {
         return static::add($vars, $errors);
     }
 
-    static function add($vars, &$errors) {
+    static function add($vars, &$errors=array()) {
 
         if (!$vars || !is_array($vars) || !$vars['threadId'])
             $errors['err'] = __('Missing or invalid data');
@@ -1520,7 +1520,7 @@ class NoteThreadEntry extends ThreadEntry {
         return self::add($vars, $errors);
     }
 
-    static function add($vars, &$errors) {
+    static function add($vars, &$errors=array()) {
 
         //Check required params.
         if (!$vars || !is_array($vars) || !$vars['threadId'])
diff --git a/include/class.translation.php b/include/class.translation.php
index cb8bcee9a..7bea8c466 100644
--- a/include/class.translation.php
+++ b/include/class.translation.php
@@ -1009,7 +1009,10 @@ class CustomDataTranslation extends VerySimpleModel {
         return parent::save($refetch);
     }
 
-    static function create(array $ht=array()) {
+    static function create($ht=false) {
+        if (!is_array($ht))
+            return null;
+
         if (is_array($ht['text'])) {
             // The parent constructor does not honor arrays
             $ht['text'] = static::encodeComplex($ht['text']);
diff --git a/setup/test/run-tests.php b/setup/test/run-tests.php
index 2cf780068..f42c121d7 100644
--- a/setup/test/run-tests.php
+++ b/setup/test/run-tests.php
@@ -5,13 +5,9 @@ if (php_sapi_name() != 'cli') exit();
 //Allow user to select suite
 $selected_test = (isset($argv[1])) ? $argv[1] : false;
 
+require_once 'bootstrap.php';
 require_once "tests/class.test.php";
 
-$root = get_osticket_root_path();
-define('INCLUDE_DIR', "$root/include/");
-define('PEAR_DIR', INCLUDE_DIR."pear/");
-ini_set('include_path', './'.PATH_SEPARATOR.INCLUDE_DIR.PATH_SEPARATOR.PEAR_DIR);
-
 $fails = array();
 
 require_once INCLUDE_DIR . 'class.i18n.php';
diff --git a/setup/test/tests/mockdb.php b/setup/test/tests/mockdb.php
index b6bc348cf..848ccd353 100644
--- a/setup/test/tests/mockdb.php
+++ b/setup/test/tests/mockdb.php
@@ -1,5 +1,9 @@
 <?php
 
+define('TABLE_PREFIX', '%');
+
+Bootstrap::defineTables(TABLE_PREFIX);
+
 function db_connect($source) {
     global $__db;
     $__db = $source;
diff --git a/setup/test/tests/test.header_functions.php b/setup/test/tests/test.header_functions.php
index 0b2328ce4..852241b1b 100644
--- a/setup/test/tests/test.header_functions.php
+++ b/setup/test/tests/test.header_functions.php
@@ -1,7 +1,5 @@
 <?php
 require_once "class.test.php";
-define('INCLUDE_DIR', realpath(dirname(__file__).'/../../../include').'/');
-define('PEAR_DIR', INCLUDE_DIR.'/pear/');
 require_once INCLUDE_DIR."class.mailparse.php";
 
 abstract class Priorities {
diff --git a/setup/test/tests/test.mail-parse.php b/setup/test/tests/test.mail-parse.php
index d1d80c225..8d1350f0f 100644
--- a/setup/test/tests/test.mail-parse.php
+++ b/setup/test/tests/test.mail-parse.php
@@ -1,5 +1,7 @@
 <?php
 
+require_once 'mockdb.php';
+
 require_once INCLUDE_DIR.'class.validator.php';
 require_once INCLUDE_DIR.'class.auth.php';
 require_once INCLUDE_DIR.'class.staff.php';
@@ -7,8 +9,6 @@ require_once INCLUDE_DIR.'class.email.php';
 require_once INCLUDE_DIR.'class.format.php';
 require_once INCLUDE_DIR.'class.thread.php';
 
-require_once 'mockdb.php';
-
 class TestMailParsing extends Test {
     var $name = "Mail parsing library tests";
 
-- 
GitLab