Test: add base test framework

This commit is contained in:
Thomas Gelf 2016-11-23 10:12:25 +01:00
parent 95d8696705
commit 9e17ff21ba
6 changed files with 102 additions and 0 deletions

View file

@ -0,0 +1,47 @@
<?php
namespace Icinga\Module\Businessprocess\Test;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Icinga;
use PHPUnit_Framework_TestCase;
abstract class BaseTestCase extends PHPUnit_Framework_TestCase
{
/** @var ApplicationBootstrap */
private static $app;
/**
* @inheritdoc
*/
public function setUp()
{
$this->app();
}
/**
* @param null $subDir
* @return string
*/
protected function getTestsBaseDir($subDir = null)
{
$dir = dirname(dirname(dirname(__DIR__))) . '/test';
if ($subDir === null) {
return $dir;
} else {
return $dir . '/' . ltrim($subDir, '/');
}
}
/**
* @return ApplicationBootstrap
*/
protected function app()
{
if (self::$app === null) {
self::$app = Icinga::app();
}
return self::$app;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Icinga\Module\Businessprocess\Test;
use Icinga\Application\Cli;
class Bootstrap
{
public static function cli($basedir = null)
{
error_reporting(E_ALL | E_STRICT);
if ($basedir === null) {
$basedir = dirname(dirname(dirname(__DIR__)));
}
$testsDir = $basedir . '/test';
require_once 'Icinga/Application/Cli.php';
if (array_key_exists('ICINGAWEB_CONFIGDIR', $_SERVER)) {
$configDir = $_SERVER['ICINGAWEB_CONFIGDIR'];
} else {
$configDir = $testsDir . '/config';
}
Cli::start($testsDir, $configDir)
->getModuleManager()
->loadModule('businessprocess', $basedir);
}
}

18
phpunit.xml Normal file
View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="test/bootstrap.php"
>
<testsuites>
<testsuite name="Businessprocess PHP Unit tests">
<directory suffix=".php">test/php</directory>
</testsuite>
</testsuites>
</phpunit>

9
test/bootstrap.php Normal file
View file

@ -0,0 +1,9 @@
<?php
use Icinga\Module\Businessprocess\Test\Bootstrap;
call_user_func(function() {
$basedir = dirname(__DIR__);
require_once $basedir . '/library/Businessprocess/Test/Bootstrap.php';
Bootstrap::cli($basedir);
});

View file

0
test/config/config.ini Normal file
View file