scanner/tests/ScannerTests.php

35 lines
1.1 KiB
PHP
Raw Normal View History

<?php
require_once 'PHPUnit/Framework.php';
class ScannerTests extends PHPUnit_Framework_TestCase {
private function run_scanner($options = array(), $files = array()) {
$modules = array_key_exists('modules', $options) ? (is_array($options['modules']) ? $options['modules'] : explode(',', $options['modules'])) : array();
$base = array_key_exists('base', $options) ? $options['base'] : false;
$files = is_array($files) ? $files : array($files);
$command = 'php ../scanner.php -q';
if (count($modules) > 0)
$command .= ' -m ' . implode(',', $modules);
if ($base)
$command .= ' -b ' . $base;
$command .= ' ' . implode(' ', $files);
return shell_exec($command);
}
public function testModuleLint() {
$result = $this->run_scanner(
array('modules' => 'lint'),
'samples/lint_failure.php'
);
$this->assertEquals(file_get_contents('samples/lint_failure.txt'), $result);
}
public function testModulePatterns() {
$result = $this->run_scanner(
array('modules' => 'pattern'),
'samples/patterns.php'
);
$this->assertEquals(file_get_contents('samples/patterns.txt'), $result);
}
}
?>