1 | <?php |
||
2 | /** |
||
3 | * AlertingTest.php |
||
4 | * |
||
5 | * Tests for alerting functionality. |
||
6 | * |
||
7 | * This program is free software: you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation, either version 3 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * This program is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License |
||
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
19 | * |
||
20 | * @link https://www.librenms.org |
||
21 | * |
||
22 | * @copyright 2016 Neil Lathwood |
||
23 | * @author Neil Lathwood <[email protected]> |
||
24 | */ |
||
25 | |||
26 | namespace LibreNMS\Tests; |
||
27 | |||
28 | use RecursiveDirectoryIterator; |
||
29 | use RecursiveIteratorIterator; |
||
30 | use RecursiveRegexIterator; |
||
31 | use RegexIterator; |
||
32 | |||
33 | class AlertingTest extends TestCase |
||
34 | { |
||
35 | public function testJsonAlertCollection() |
||
36 | { |
||
37 | $rules = get_rules_from_json(); |
||
38 | $this->assertIsArray($rules); |
||
39 | foreach ($rules as $rule) { |
||
40 | $this->assertIsArray($rule); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | public function testTransports() |
||
45 | { |
||
46 | foreach ($this->getTransportFiles() as $file => $_unused) { |
||
47 | $parts = explode('/', $file); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
48 | $transport = ucfirst(str_replace('.php', '', array_pop($parts))); |
||
49 | $class = 'LibreNMS\\Alert\\Transport\\' . $transport; |
||
50 | if (! class_exists($class)) { |
||
51 | $this->assertTrue(false, "The transport $transport does not exist"); |
||
52 | } else { |
||
53 | $methods = ['deliverAlert', 'configTemplate', 'contact' . $transport]; |
||
54 | foreach ($methods as $method) { |
||
55 | if (! method_exists($class, $method)) { |
||
56 | $this->assertTrue(false, "The transport $transport does not have the method $method"); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | |||
62 | $this->expectNotToPerformAssertions(); |
||
63 | } |
||
64 | |||
65 | private function getTransportFiles() |
||
66 | { |
||
67 | $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('LibreNMS/Alert/Transport')); |
||
68 | |||
69 | return new RegexIterator($iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH); |
||
70 | } |
||
71 | } |
||
72 |