|
| 1 | +<?php |
| 2 | +/* |
| 3 | + +-------------------------------------------------------------------------+ |
| 4 | + | Copyright (C) 2004-2026 The Cacti Group | |
| 5 | + +-------------------------------------------------------------------------+ |
| 6 | + | Cacti: The Complete RRDtool-based Graphing Solution | |
| 7 | + +-------------------------------------------------------------------------+ |
| 8 | +*/ |
| 9 | + |
| 10 | +/* |
| 11 | + * Verify plugin source files do not use PHP 8.0+ syntax. |
| 12 | + * Cacti 1.2.x plugins must remain compatible with PHP 7.4. |
| 13 | + */ |
| 14 | + |
| 15 | +describe('PHP 7.4 compatibility in mactrack', function () { |
| 16 | + $files = array( |
| 17 | + 'mactrack_devices.php', |
| 18 | + 'mactrack_device_types.php', |
| 19 | + 'mactrack_interfaces.php', |
| 20 | + 'mactrack_sites.php', |
| 21 | + 'mactrack_snmp.php', |
| 22 | + 'mactrack_utilities.php', |
| 23 | + 'mactrack_view_arp.php', |
| 24 | + 'mactrack_view_macs.php', |
| 25 | + 'mactrack_view_sites.php', |
| 26 | + 'setup.php', |
| 27 | + ); |
| 28 | + |
| 29 | + it('does not use str_contains (PHP 8.0)', function () use ($files) { |
| 30 | + foreach ($files as $relativeFile) { |
| 31 | + $path = realpath(__DIR__ . '/../../' . $relativeFile); |
| 32 | + |
| 33 | + if ($path === false) { |
| 34 | + continue; |
| 35 | + } |
| 36 | + |
| 37 | + $contents = file_get_contents($path); |
| 38 | + |
| 39 | + if ($contents === false) { |
| 40 | + continue; |
| 41 | + } |
| 42 | + |
| 43 | + expect(preg_match('/\bstr_contains\s*\(/', $contents))->toBe(0, |
| 44 | + "{$relativeFile} uses str_contains() which requires PHP 8.0" |
| 45 | + ); |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + it('does not use str_starts_with (PHP 8.0)', function () use ($files) { |
| 50 | + foreach ($files as $relativeFile) { |
| 51 | + $path = realpath(__DIR__ . '/../../' . $relativeFile); |
| 52 | + |
| 53 | + if ($path === false) { |
| 54 | + continue; |
| 55 | + } |
| 56 | + |
| 57 | + $contents = file_get_contents($path); |
| 58 | + |
| 59 | + if ($contents === false) { |
| 60 | + continue; |
| 61 | + } |
| 62 | + |
| 63 | + expect(preg_match('/\bstr_starts_with\s*\(/', $contents))->toBe(0, |
| 64 | + "{$relativeFile} uses str_starts_with() which requires PHP 8.0" |
| 65 | + ); |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + it('does not use str_ends_with (PHP 8.0)', function () use ($files) { |
| 70 | + foreach ($files as $relativeFile) { |
| 71 | + $path = realpath(__DIR__ . '/../../' . $relativeFile); |
| 72 | + |
| 73 | + if ($path === false) { |
| 74 | + continue; |
| 75 | + } |
| 76 | + |
| 77 | + $contents = file_get_contents($path); |
| 78 | + |
| 79 | + if ($contents === false) { |
| 80 | + continue; |
| 81 | + } |
| 82 | + |
| 83 | + expect(preg_match('/\bstr_ends_with\s*\(/', $contents))->toBe(0, |
| 84 | + "{$relativeFile} uses str_ends_with() which requires PHP 8.0" |
| 85 | + ); |
| 86 | + } |
| 87 | + }); |
| 88 | + |
| 89 | + it('does not use nullsafe operator (PHP 8.0)', function () use ($files) { |
| 90 | + foreach ($files as $relativeFile) { |
| 91 | + $path = realpath(__DIR__ . '/../../' . $relativeFile); |
| 92 | + |
| 93 | + if ($path === false) { |
| 94 | + continue; |
| 95 | + } |
| 96 | + |
| 97 | + $contents = file_get_contents($path); |
| 98 | + |
| 99 | + if ($contents === false) { |
| 100 | + continue; |
| 101 | + } |
| 102 | + |
| 103 | + expect(preg_match('/\?->/', $contents))->toBe(0, |
| 104 | + "{$relativeFile} uses nullsafe operator which requires PHP 8.0" |
| 105 | + ); |
| 106 | + } |
| 107 | + }); |
| 108 | +}); |
0 commit comments