/** * Constructor * * @param string $baseDir Icinga Web 2 base directory * @param string $configDir Path to Icinga Web 2's configuration files */ protected function __construct($baseDir = null, $configDir = null) { if ($baseDir === null) { $baseDir = dirname($this->getBootstrapDirectory()); } $this->baseDir = $baseDir; $this->appDir = $baseDir . '/application'; $this->vendorDir = $baseDir . '/library/vendor'; $this->libDir = realpath(__DIR__ . '/../..'); $this->setupAutoloader(); if ($configDir === null) { $configDir = getenv('ICINGAWEB_CONFIGDIR'); if ($configDir === false) { $configDir = Platform::isWindows() ? $baseDir . '/config' : '/etc/icingaweb2'; } } $canonical = realpath($configDir); $this->configDir = $canonical ? $canonical : $configDir; set_include_path(implode(PATH_SEPARATOR, array($this->vendorDir, get_include_path()))); Benchmark::measure('Bootstrap, autoloader registered'); Icinga::setApp($this); require_once dirname(__FILE__) . '/functions.php'; }
/** * Setup mock object for the application's bootstrap * * @param Zend_Controller_Request_Abstract $request The request to be returned by * Icinga::app()->getFrontController()->getRequest() */ protected function setupIcingaMock(Zend_Controller_Request_Abstract $request) { $bootstrapMock = Mockery::mock('Icinga\\Application\\ApplicationBootstrap')->shouldDeferMissing(); $bootstrapMock->shouldReceive('getFrontController->getRequest')->andReturnUsing(function () use($request) { return $request; })->shouldReceive('getApplicationDir')->andReturn(self::$appDir); Icinga::setApp($bootstrapMock, true); }
/** * Setup mock object for the application's bootstrap * * @return Mockery\Mock */ protected function setupIcingaMock() { $requestMock = Mockery::mock('Icinga\\Web\\Request')->shouldDeferMissing(); $requestMock->shouldReceive('getPathInfo')->andReturn('')->byDefault()->shouldReceive('getBaseUrl')->andReturn('/')->byDefault()->shouldReceive('getQuery')->andReturn(array())->byDefault()->shouldReceive('getParam')->with(Mockery::type('string'), Mockery::type('string'))->andReturnUsing(function ($name, $default) { return $default; })->byDefault(); $responseMock = Mockery::mock('Icinga\\Web\\Response')->shouldDeferMissing(); // Can't express this as demeter chains. See: https://github.com/padraic/mockery/issues/59 $bootstrapMock = Mockery::mock('Icinga\\Application\\ApplicationBootstrap')->shouldDeferMissing(); $libDir = dirname(self::$libDir); $bootstrapMock->shouldReceive('getFrontController')->andReturn($bootstrapMock)->shouldReceive('getApplicationDir')->andReturn(self::$appDir)->shouldReceive('getLibraryDir')->andReturnUsing(function ($subdir = null) use($libDir) { if ($subdir !== null) { $libDir .= '/' . ltrim($subdir, '/'); } return $libDir; })->shouldReceive('getRequest')->andReturn($requestMock)->shouldReceive('getResponse')->andReturn($responseMock); Icinga::setApp($bootstrapMock, true); return $bootstrapMock; }
/** * Constructor */ protected function __construct($configDir = null) { $this->libDir = realpath(__DIR__ . '/../..'); if (!defined('ICINGA_LIBDIR')) { define('ICINGA_LIBDIR', $this->libDir); } if (defined('ICINGAWEB_APPDIR')) { $this->appDir = ICINGAWEB_APPDIR; } elseif (array_key_exists('ICINGAWEB_APPDIR', $_SERVER)) { $this->appDir = $_SERVER['ICINGAWEB_APPDIR']; } else { $this->appDir = realpath($this->libDir . '/../application'); } if (!defined('ICINGAWEB_APPDIR')) { define('ICINGAWEB_APPDIR', $this->appDir); } if ($configDir === null) { if (array_key_exists('ICINGAWEB_CONFIGDIR', $_SERVER)) { $configDir = $_SERVER['ICINGAWEB_CONFIGDIR']; } else { $configDir = '/etc/icingaweb'; } } $this->configDir = realpath($configDir); $this->setupAutoloader(); $this->setupZendAutoloader(); Benchmark::measure('Bootstrap, autoloader registered'); Icinga::setApp($this); require_once dirname(__FILE__) . '/functions.php'; }