[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Noisy warnings and notices in the PHP unit test output

"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69fdbc4ce3a0a_381906b8318d2@gitlab-sidekiq-low-urgency-cpu-bound-v2-6746cb7cfd-4gt5g.mail>

ushindi bienvenu pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
fec020ae by ushindi bienvenu at 2026-05-08T10:19:24+00:00
[FIX] Noisy warnings and notices in the PHP unit test output
---
* [FIX] Fix warnings and notices in the PHP unit test output

* [FIX] Avoid notices when indexing invalid tracker items and Trying to access array offset on value of type null

* [FIX] Fix noisy-output when unit test failing

See merge request tikiwiki/tiki!8822

- - - - -


16 changed files:

- .gitlab-ci.yml
- lib/calendar/calrecurrence.php
- lib/core/Search/ContentSource/TrackerItemSource.php
- lib/core/Tiki/Profile/Installer.php
- lib/core/Tiki/Smarty/SmartyTiki.php
- lib/core/TikiFilter/Alnum.php
- lib/core/Tracker/Field/Math.php
- lib/crypt/cryptlib.php
- lib/test/Core/Search/Manticore/WildcardTest.php
- lib/test/Core/Tracker/Field/ItemLinkTest.php
- lib/test/Core/Tracker/Field/MathTest.php
- lib/test/Core/Tracker/Field/UrlTest.php
- lib/test/Importer/BlogWordpressTest.php
- lib/test/IntegrationTests/MLModelTest.php
- lib/test/IntegrationTests/TrackerDatesTimezoneTest.php
- lib/test/TikiTestCase.php


Changes:

=====================================
.gitlab-ci.yml
=====================================
@@ -667,6 +667,10 @@ tiki-package:
     - echo "=> Optimize language files ..."
     - find lang/ -name language.php -exec php doc/devtools/stripcomments.php {} \;
     # set Permissions
+    - echo "=> Fix permissions ..."
+    - find . -type f -exec chmod 0664 {} \;
+    - chmod 0775 setup.sh
+    - find . -type d -exec chmod 0755 {} \;
     - echo "=> Generate changelog ..."
     - 'TARGET_BRANCH="${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-$CI_DEFAULT_BRANCH}"'
     - git fetch origin "$TARGET_BRANCH" --tags --depth=1000


=====================================
lib/calendar/calrecurrence.php
=====================================
@@ -998,14 +998,17 @@ class CalRecurrence extends TikiLib
             $data['DESCRIPTION'] = $this->getDescription();
         }
         $locations = TikiLib::lib('calendar')->list_locations($this->getCalendarId());
-        if (! empty($locations[$this->getLocationId()])) {
-            $data['LOCATION'] = $locations[$this->getLocationId()];
+        $locationId = $this->getLocationId();
+
+        if ($locationId !== null && ! empty($locations[$locationId])) {
+            $data['LOCATION'] = $locations[$locationId];
         }
         if (! empty($this->getLocationId())) {
             $data['X-Tiki-LocationId'] = $this->getLocationId();
         }
         $categories = TikiLib::lib('calendar')->list_categories($this->getCategoryId());
-        if (! empty($categories[$this->getCategoryId()])) {
+        $categoryId = $this->getCategoryId();
+        if ($categoryId !== null && ! empty($categories[$categoryId])) {
             $data['CATEGORIES'] = $categories[$this->getCategoryId()];
         }
         if (! empty($this->getCategoryId())) {


=====================================
lib/core/Search/ContentSource/TrackerItemSource.php
=====================================
@@ -37,7 +37,6 @@ class Search_ContentSource_TrackerItemSource implements Search_ContentSource_Int
         $item = $this->trklib->get_tracker_item($objectId);
         // Check that the element is valid and contains a trackerId
         if (empty($item) || empty($item['trackerId'])) {
-            trigger_error("Invalid item data or missing trackerId for objectId: $objectId");
             return false;
         }
 


=====================================
lib/core/Tiki/Profile/Installer.php
=====================================
@@ -754,7 +754,7 @@ class Tiki_Profile_Installer
     {
         $userlib = TikiLib::lib('user');
 
-        foreach (['description', 'home', 'user_tracker', 'group_tracker', 'user_signup', 'default_category', 'theme', 'color', 'user_tracker_field', 'group_tracker_field', 'is_external', 'expire_after', 'email_pattern', 'anniversary', 'prorate_interval'] as $field) {
+        foreach (['description', 'home', 'user_tracker', 'group_tracker', 'user_signup', 'default_category', 'theme', 'color', 'user_tracker_field', 'group_tracker_field', 'is_external', 'expire_after', 'email_pattern', 'anniversary', 'prorate_interval', 'twoFactorAuthGracePeriod'] as $field) {
             if (! isset($info[$field])) {
                 $info[$field] = '';
             }


=====================================
lib/core/Tiki/Smarty/SmartyTiki.php
=====================================
@@ -746,7 +746,7 @@ class SmartyTiki extends Smarty
         $this->addTemplateDir($this->main_template_dir);
 
         // webservices create temporary templates
-        if ($prefs['feature_webservices'] === 'y') {
+        if (($prefs['feature_webservices'] ?? 'n') === 'y') {
             $this->addTemplateDir(realpath(TEMP_CACHE_PATH));
         }
 


=====================================
lib/core/TikiFilter/Alnum.php
=====================================
@@ -51,6 +51,6 @@ class TikiFilter_Alnum extends AbstractLocale
      */
     public function filter($value): string
     {
-        return preg_replace($this->pattern, '', $value);
+        return preg_replace($this->pattern, '', $value ?? '');
     }
 }


=====================================
lib/core/Tracker/Field/Math.php
=====================================
@@ -470,14 +470,14 @@ class Tracker_Field_Math extends \Tracker\Field\AbstractItemField implements \Tr
         global $url_host, $base_url;
 
         return [
-        'itemId' => $this->getItemId(),
-        'trackerId' => $this->getTrackerDefinition()->getConfiguration('trackerId'),
-        'creation_date' => $this->getData('created'),
-        'created_by' => $this->getData('createdBy'),
-        'modification_date' => $this->getData('lastModif'),
-        'last_modified_by' => $this->getData('lastModifBy'),
-        'domain' => $url_host,
-        'base_url' => $base_url . (substr($base_url, -1) == '/' ? '' : '/'),
+            'itemId' => $this->getItemId(),
+            'trackerId' => $this->getTrackerDefinition()->getConfiguration('trackerId'),
+            'creation_date' => $this->getData('created'),
+            'created_by' => $this->getData('createdBy'),
+            'modification_date' => $this->getData('lastModif'),
+            'last_modified_by' => $this->getData('lastModifBy'),
+            'domain' => $url_host,
+            'base_url' => $base_url . (str_ends_with($base_url ?? '', '/') ? '' : '/'),
         ];
     }
 }


=====================================
lib/crypt/cryptlib.php
=====================================
@@ -417,7 +417,7 @@ class CryptLib extends TikiLib
 
         // Due to appending spaces to short input data, short cleartext data cannot end with space
         $pwdLen = mb_strlen($cleartextData);
-        if ($pwdLen < 20 && $cleartextData[$pwdLen] == ' ') {
+        if ($pwdLen < 20 && str_ends_with($cleartextData, ' ')) {
             throw new Exception('Data to encrypt cannot end with a space');
         }
         // Make sure the data is at least 20 characters long


=====================================
lib/test/Core/Search/Manticore/WildcardTest.php
=====================================
@@ -111,8 +111,6 @@ class WildcardTest extends \PHPUnit\Framework\TestCase
     public function testWildcardToRe2EscapesMetacharacters()
     {
         $convert = new ReflectionMethod(QueryBuilder::class, 'wildcardToRe2');
-        $convert->setAccessible(true);
-
         $builder = new QueryBuilder($this->index);
 
         $cases = [
@@ -139,7 +137,6 @@ class WildcardTest extends \PHPUnit\Framework\TestCase
     public function testQuoteRegexBuildsExpectedPattern()
     {
         $quote = new ReflectionMethod(QueryBuilder::class, 'quoteRegex');
-        $quote->setAccessible(true);
 
         $builder = new QueryBuilder($this->index);
 


=====================================
lib/test/Core/Tracker/Field/ItemLinkTest.php
=====================================
@@ -7,6 +7,7 @@
 
 namespace TikiTests;
 
+use TikiTestCase;
 use Tracker_Definition,
 
 TikiLib, Tracker_Item;
@@ -14,22 +15,21 @@ TikiLib, Tracker_Item;
 /**
  * This is a smoke test for the ItemLink fields.  At least it shows how badly we need a better internal API... - benoitg - 2024-07-04
  */
-class TrackerItemLinkTest extends \PHPUnit\Framework\TestCase
+class TrackerItemLinkTest extends TikiTestCase
 {
     protected static $trklib;
     protected static $objectlib;
     protected static $unifiedlib;
     protected static $trackerId;
     protected static $linkedTrackerId;
-    protected static $old_pref;
+    protected static $old_prefs;
     protected static $old_user;
 
     public static function setUpBeforeClass(): void
     {
         global $prefs;
-        self::$old_pref = $prefs['feature_trackers'];
+        self::$old_prefs = $prefs;
         $prefs['feature_trackers'] = 'y';
-
         parent::setUpBeforeClass();
         self::$trklib = TikiLib::lib('trk');
         self::$objectlib = TikiLib::lib('object');
@@ -125,7 +125,7 @@ class TrackerItemLinkTest extends \PHPUnit\Framework\TestCase
     public static function tearDownAfterClass(): void
     {
         global $prefs, $tikilib;
-        $prefs['feature_trackers'] = self::$old_pref;
+        $prefs['feature_trackers'] = self::$old_prefs['feature_trackers'];
 
         parent::tearDownAfterClass();
         self::$trklib->remove_tracker(self::$trackerId);
@@ -176,12 +176,16 @@ class TrackerItemLinkTest extends \PHPUnit\Framework\TestCase
         $fields = $definition->getFields();
         $fields[0]['value'] = 'Test item';
         $fields[1]['value'] = 'nonexistent_id';
-
-        $itemId = self::$trklib->replace_item(self::$trackerId, 0, ['data' => $fields], 'o');
-        $item = Tracker_Item::fromId($itemId);
-        $itemLinkField = $item->getFieldFromPermName('test_link');
-        //We know there is a error raised, we supress it
-        $output = @$itemLinkField->renderOutput();
-        $this->assertStringContainsString('nonexistent_id', $output, "Error message must display the invalid or deleted id");
+        $this->assertTriggeredError(
+            "Data integrity error:",
+            function () use ($fields) {
+                $itemId = self::$trklib->replace_item(self::$trackerId, 0, ['data' => $fields], 'o');
+                $item = Tracker_Item::fromId($itemId);
+                $itemLinkField = $item->getFieldFromPermName('test_link');
+                //We know there is a error raised, we suppress it
+                $output = @$itemLinkField->renderOutput();
+                $this->assertStringContainsString('nonexistent_id', $output, "Error message must display the invalid or deleted id");
+            }
+        );
     }
 }


=====================================
lib/test/Core/Tracker/Field/MathTest.php
=====================================
@@ -7,6 +7,7 @@
 
 namespace TikiTests;
 
+use TikiTestCase;
 use Tracker_Definition,
 
 TikiLib, Tracker_Item;
@@ -14,20 +15,20 @@ TikiLib, Tracker_Item;
 /**
  * This is a smoke test for the Math field.  At least it shows how badly we need a better internal API... - benoitg - 2024-09-04
  */
-class TrackerFieldMathTest extends \PHPUnit\Framework\TestCase
+class TrackerFieldMathTest extends TikiTestCase
 {
     protected static $trklib;
     protected static $objectlib;
     protected static $unifiedlib;
     protected static $trackerId;
     protected static $linkedTrackerId;
-    protected static $old_pref;
+    protected static $old_prefs;
     protected static $old_user;
 
     public static function setUpBeforeClass(): void
     {
         global $prefs;
-        self::$old_pref = $prefs['feature_trackers'];
+        self::$old_prefs = $prefs;
         $prefs['feature_trackers'] = 'y';
         $prefs['short_date_format'] = '%Y-%m-%d';
         $prefs['short_time_format'] = '%H:%M';
@@ -129,14 +130,15 @@ class TrackerFieldMathTest extends \PHPUnit\Framework\TestCase
     public static function tearDownAfterClass(): void
     {
         global $prefs, $tikilib;
-        $prefs['feature_trackers'] = self::$old_pref;
+        $prefs['feature_trackers'] = self::$old_prefs['feature_trackers'];
 
         parent::tearDownAfterClass();
         self::$trklib->remove_tracker(self::$trackerId);
         self::$trklib->remove_tracker(self::$linkedTrackerId);
+        $prefs['unified_engine'] = self::$old_prefs['unified_engine'];
     }
 
-    public function testBasicFunctionnality(): void
+    public function testBasicFunctionality(): void
     {
         $birthDate = time() - (31536000); //Now - one year
         $dateChildWillBe18 = $birthDate + (31536000 * 18);


=====================================
lib/test/Core/Tracker/Field/UrlTest.php
=====================================
@@ -75,7 +75,6 @@ class TrackerFieldUrlTest extends \PHPUnit\Framework\TestCase
     private function invokeIsWikiSyntaxLink(string $value): bool
     {
         $method = new \ReflectionMethod(\Tracker_Field_Url::class, 'isWikiSyntaxLink');
-        $method->setAccessible(true);
 
         return (bool) $method->invoke(null, $value);
     }


=====================================
lib/test/Importer/BlogWordpressTest.php
=====================================
@@ -13,6 +13,7 @@ use Laminas\Http\Client\Adapter\Test as HttpClientAdapterTest;
 use Tiki\FileGallery\File;
 use TikiDb;
 use Tiki\Lib\Importer\BlogWordpress;
+use TikiLib;
 
 /**
  * @group importer


=====================================
lib/test/IntegrationTests/MLModelTest.php
=====================================
@@ -33,7 +33,6 @@ class MLModelTest extends TikiTestCase
         parent::setUpBeforeClass();
         self::$trklib = TikiLib::lib('trk');
         self::$mllib = TikiLib::lib('ml');
-
         // create a tracker and a field
         self::$trackerId = self::$trklib->replace_tracker(null, 'Test Tracker', '', [], 'n');
         self::assertNotEmpty(self::$trackerId, "Check the tracker was created properly");
@@ -66,13 +65,11 @@ class MLModelTest extends TikiTestCase
 
         $definition = Tracker_Definition::get(self::$trackerId);
         $fields = $definition->getFields();
-
         foreach (self::SAMPLES as $sample) {
             $fields[0]['value'] = $sample;
             $itemId = self::$trklib->replace_item(self::$trackerId, 0, ['data' => $fields], 'o');
             self::$labels[] = self::$trklib->get_isMain_value(self::$trackerId, $itemId);
         }
-
         $mlmId = self::$mllib->set_model(null, [
             'name' => 'MLT',
             'sourceTrackerId' => self::$trackerId,


=====================================
lib/test/IntegrationTests/TrackerDatesTimezoneTest.php
=====================================
@@ -33,7 +33,6 @@ class TrackerDatesTimezoneTest extends TikiTestCase
 
         parent::setUpBeforeClass();
         self::$trklib = TikiLib::lib('trk');
-
         // create tracker and couple of fields
         self::$trackerId = self::$trklib->replace_tracker(null, 'Test Tracker', '', [], 'n');
         self::assertNotEmpty(self::$trackerId);
@@ -94,7 +93,6 @@ class TrackerDatesTimezoneTest extends TikiTestCase
             );
             self::assertNotEmpty($fieldId);
         }
-
         TikiDb::get()->query("REPLACE INTO `users_grouppermissions` VALUES('Registered', 'tiki_p_admin_trackers', '')");
         TikiDb::get()->query("REPLACE INTO `users_grouppermissions` VALUES('Registered', 'tiki_p_view_trackers', '')");
         $builder = new Perms_Builder();


=====================================
lib/test/TikiTestCase.php
=====================================
@@ -86,7 +86,7 @@ abstract class TikiTestCase extends TestCase
         // This error handler is to convert E_USER_NOTICE into an exception.
         $errorHandler = function ($severity, $errMessage, $file, $line) use ($message) {
             if ($severity & (E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR | E_USER_DEPRECATED)) {
-                if ($errMessage !== $message) {
+                if (! str_contains($errMessage, $message)) {
                     throw new \PHPUnit\Framework\ExpectationFailedException(
                         sprintf(
                             'Failed asserting that error message "%s" matches expected "%s".',
@@ -100,7 +100,7 @@ abstract class TikiTestCase extends TestCase
         };
 
         // Temporarily set the custom error handler.
-        set_error_handler($errorHandler, E_USER_NOTICE);
+        set_error_handler($errorHandler);
 
         try {
             $callback(...$args);
@@ -111,7 +111,7 @@ abstract class TikiTestCase extends TestCase
             );
         } catch (\ErrorException $e) {
             // Assertion passes if we catch the expected ErrorException.
-            $this->assertEquals($message, $e->getMessage());
+            $this->assertStringContainsString($message, $e->getMessage());
         } finally {
             restore_error_handler();
         }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/fec020aea40ec9f9bb6b100fcf0dfe782c0a6bdf

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/fec020aea40ec9f9bb6b100fcf0dfe782c0a6bdf
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.