Test: Using autoloader for tests

refs #4639
This commit is contained in:
Marius Hein 2014-02-14 15:56:19 +01:00 committed by Johannes Meyer
parent 139023571f
commit 0ca0eef311
6 changed files with 60 additions and 70 deletions

59
test/php/TestInit.php Normal file
View File

@ -0,0 +1,59 @@
<?php
class TestInit
{
public static function bootstrap()
{
$libaryPath = realpath(dirname(__FILE__) . '/../../library/');
$modulePath = realpath(dirname(__FILE__) . '/../../modules/');
$applicationPath = realpath(dirname(__FILE__) . '/../../application/');
set_include_path(
$libaryPath . ':' . get_include_path()
);
require_once('Icinga/Application/Loader.php');
$loader = new \Icinga\Application\Loader();
$loader->registerNamespace('Icinga', $libaryPath . '/Icinga');
$loader->registerNamespace('Icinga\\Form', $applicationPath . '/forms');
$modules = scandir($modulePath);
foreach ($modules as $module) {
if ($module === '.' || $module === '..') {
continue;
}
$baseNs = 'Icinga\\Module\\' . ucfirst($module);
$moduleLibraryPath = $modulePath . '/' . $module . '/library';
if (is_dir($moduleLibraryPath)) {
$loader->registerNamespace($baseNs, $moduleLibraryPath);
}
$moduleTestPath = $modulePath . '/' . $module . '/test';
if (is_dir($moduleTestPath)) {
$testNs = $baseNs .= '\\Test';
$loader->registerNamespace($testNs, $moduleTestPath);
}
$moduleFormPath = $modulePath . '/' . $module . '/application/forms';
if (is_dir($moduleFormPath)) {
$formNs = $baseNs .= '\\Form';
$loader->registerNamespace($formNs, $moduleFormPath);
}
}
$loader->register();
require_once 'Zend/Loader/Autoloader.php';
\Zend_Loader_Autoloader::getInstance();
}
}
TestInit::bootstrap();

View File

@ -2,20 +2,6 @@
namespace Tests\Application\Controller;
require 'Zend/Test/PHPUnit/ControllerTestCase.php';
require 'Zend/Config.php';
require 'Zend/Application.php';
require 'Zend/Config/Ini.php';
require 'Zend/Controller/Action.php';
require '../../library/Icinga/Exception/ProgrammingError.php';
require '../../library/Icinga/Application/Benchmark.php';
require '../../library/Icinga/Application/Config.php';
require '../../library/Icinga/Application/Icinga.php';
require '../../library/Icinga/Web/Controller/ActionController.php';
require '../../library/Icinga/Web/Notification.php';
require '../../library/Icinga/Application/Platform.php';
use Icinga\Application\Icinga;
class IndexControllerTest extends \Zend_Test_PHPUnit_ControllerTestCase {

View File

@ -29,28 +29,8 @@
namespace Test\Icinga\Form\Config;
// @codingStandardsIgnoreStart
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
// @codingStandardsIgnoreEnd
use Icinga\Test\BaseTestCase;
// @codingStandardsIgnoreStart
require_once 'Zend/Form.php';
require_once 'Zend/Config.php';
require_once 'Zend/Config/Ini.php';
require_once BaseTestCase::$testDir . '/library/Icinga/Web/RequestMock.php';
require_once BaseTestCase::$libDir . '/Web/Form.php';
require_once BaseTestCase::$libDir . '/Web/Url.php';
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/BaseBackendForm.php';
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/DbBackendForm.php';
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/LdapBackendForm.php';
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/ReorderForm.php';
// @codingStandardsIgnoreEnd
use \Zend_Config;
use \Icinga\Web\Url;
use \Tests\Icinga\Web\RequestMock;

View File

@ -2,46 +2,12 @@
namespace Tests\Icinga;
require_once __DIR__ . '/../../../../library/Icinga/User.php';
require_once __DIR__ . '/../../../../library/Icinga/User/Preferences.php';
use \DateTimeZone;
use Icinga\User as IcingaUser;
use Icinga\User\Preferences as UserPreferences;
class UserTest extends \PHPUnit_Framework_TestCase
{
public function testListGroups()
{
$this->markTestIncomplete('testListGroups is not implemented yet');
}
public function testIsMemberOf()
{
$this->markTestIncomplete('testIsMemberOf is not implemented yet');
}
public function testGetPermissionList()
{
$this->markTestIncomplete('testGetPermissionList is not implemented yet');
}
public function testHasPermission()
{
$this->markTestIncomplete('testHasPermission is not implemented yet');
}
public function testGrantPermission()
{
$this->markTestIncomplete('testGrantPermission is not implemented yet');
}
public function testRevokePermission()
{
$this->markTestIncomplete('testRevokePermission is not implemented yet');
}
public function testGetDefaultTimezoneIfTimezoneNotSet()
{
$defaultTz = 'UTC';

View File

@ -2,7 +2,6 @@
namespace Tests\Icinga\Util;
require_once("../../library/Icinga/Util/Dimension.php");
use Icinga\Util\Dimension;
/**

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit>
<phpunit bootstrap="TestInit.php">
<testsuites>
<!--
Unit testing