diff --git a/.gitignore b/.gitignore index 8d98f9de..cd5c2b0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -.* +## Editors +/.idea/ +.*.sw[op] + +## PHP / composer +/vendor/ +composer.lock \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..ac5be9f0 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "icingaweb2-director", + "require-dev": { + "phpunit/phpunit": ">= 5", + "icinga/icingaweb2": ">= 2.3", + "squizlabs/php_codesniffer": ">= 2" + }, + "autoload": { + "psr-4": { + "Icinga\\Module\\Director\\": "library/Director/" + } + }, + "repositories": [ + { + "type": "package", + "package": { + "name": "icinga/icingaweb2", + "version": "2.3.4", + "dist": { + "url": "https://github.com/Icinga/icingaweb2/archive/v2.3.4.zip", + "type": "zip" + } + } + } + ] +} diff --git a/library/Director/Test/BaseTestCase.php b/library/Director/Test/BaseTestCase.php index f0c7ab1b..b9987d22 100644 --- a/library/Director/Test/BaseTestCase.php +++ b/library/Director/Test/BaseTestCase.php @@ -6,6 +6,7 @@ use Icinga\Application\Icinga; use Icinga\Application\Config; use Icinga\Data\ResourceFactory; use Icinga\Exception\ConfigurationError; +use Icinga\Module\Director\Data\Db\DbConnection; use Icinga\Module\Director\Db; use Icinga\Module\Director\Db\Migrations; use Icinga\Module\Director\Objects\IcingaObject; @@ -47,6 +48,10 @@ class BaseTestCase extends PHPUnit_Framework_TestCase } } + /** + * @return DbConnection + * @throws ConfigurationError + */ protected function getDb() { if ($this->db === null) { diff --git a/test/bootstrap.php b/test/bootstrap.php index b8d12c7e..4f5bfb70 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -2,6 +2,22 @@ use Icinga\Application\Cli; +## Load Composer environment, if existing +call_user_func(function() { + $MODULE_HOME = dirname(dirname(__FILE__)); + $composer_load = $MODULE_HOME . '/vendor/autoload.php'; + if (file_exists($composer_load)) { + require_once $composer_load; + + # include Icinga Web + ini_set('include_path', + $MODULE_HOME . '/vendor/icinga/icingaweb2/library' + . PATH_SEPARATOR . $MODULE_HOME . '/vendor/icinga/icingaweb2/library/vendor' + . PATH_SEPARATOR . ini_get('include_path') + ); + } +}); + call_user_func(function() { error_reporting(E_ALL | E_STRICT);