. * * @package LibreNMS * @link http://librenms.org * @copyright 2016 Neil Lathwood * @author Neil Lathwood */ namespace LibreNMS\Tests; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use RecursiveRegexIterator; use RegexIterator; class AlertingTest extends TestCase { public function testJsonAlertCollection() { $rules = get_rules_from_json(); $this->assertIsArray($rules); foreach ($rules as $rule) { $this->assertIsArray($rule); } } public function testTransports() { foreach ($this->getTransportFiles() as $file => $_unused) { $parts = explode('/', $file); $transport = ucfirst(str_replace('.php', '', array_pop($parts))); $class = 'LibreNMS\\Alert\\Transport\\'.$transport; if (!class_exists($class)) { $this->assertTrue(false, "The transport $transport does not exist"); } else { $methods = ['deliverAlert', 'configTemplate', 'contact'.$transport]; foreach ($methods as $method) { if (!method_exists($class, $method)) { $this->assertTrue(false, "The transport $transport does not have the method $method"); } } } } $this->expectNotToPerformAssertions(); } private function getTransportFiles() { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('LibreNMS/Alert/Transport')); return new RegexIterator($iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH); } }