3 // Same namespace as target class
4 namespace Org\Mxchange\CoreFramework\Bootstrap;
6 // Inport framework stuff
7 use Org\Mxchange\CoreFramework\Console\Tools\ConsoleTools;
8 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
9 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
10 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
12 // Import PHPUnit stuff
13 use PHPUnit\Framework\Error\Notice;
14 use PHPUnit\Framework\TestCase;
17 use \InvalidArgumentException;
20 * Copyright (C) 2017 Roland Haeder<roland@mxchange.org>
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class FrameworkBootstrapTest extends TestCase {
40 private static $ipAddress = FALSE;
45 public function setUp() {
47 //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
53 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
60 public static function setUpBeforeClass() {
62 //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
65 parent::setUpBeforeClass();
68 * Disable strict naming-convention check in own class loader, because
69 * PHP_Invoker doesn't have namespaces.
71 ClassLoader::enableStrictNamingConventionCheck(FALSE);
73 // Lookup own IP address
74 self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
77 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
81 * Tests setting a NULL default timezone
83 public function testSettingNullDefaultTimezone () {
84 // Will throw this exception
85 $this->expectException(NullPointerException::class);
88 FrameworkBootstrap::setDefaultTimezone(NULL);
92 * Tests setting a boolean default timezone
94 public function testSettingBooleanDefaultTimezone () {
95 // Will throw this exception
96 $this->expectException(InvalidArgumentException::class);
99 FrameworkBootstrap::setDefaultTimezone(FALSE);
103 * Tests setting a decimal default timezone
105 public function testSettingDecimalDefaultTimezone () {
106 // Will throw this exception
107 $this->expectException(InvalidArgumentException::class);
110 FrameworkBootstrap::setDefaultTimezone(12345);
114 * Tests setting a float default timezone
116 public function testSettingFloatDefaultTimezone () {
117 // Will throw this exception
118 $this->expectException(InvalidArgumentException::class);
121 FrameworkBootstrap::setDefaultTimezone(123.45);
125 * Tests setting an array default timezone
127 public function testSettingArrayDefaultTimezone () {
128 // Will throw this exception
129 $this->expectException(InvalidArgumentException::class);
132 FrameworkBootstrap::setDefaultTimezone(array());
136 * Tests setting an object default timezone
138 public function testSettingObjectDefaultTimezone () {
139 // Will throw this exception
140 $this->expectException(InvalidArgumentException::class);
143 FrameworkBootstrap::setDefaultTimezone($this);
147 * Tests setting a resource default timezone
149 public function testSettingResourceDefaultTimezone () {
150 // Will throw this exception
151 $this->expectException(InvalidArgumentException::class);
153 // Init some resource
154 $resource = fopen(__FILE__, 'r');
157 FrameworkBootstrap::setDefaultTimezone($resource);
161 * Tests setting an empty default timezone
163 public function testSettingEmptyDefaultTimezone () {
164 // Will throw this exception
165 $this->expectException(InvalidArgumentException::class);
168 FrameworkBootstrap::setDefaultTimezone('');
172 * Tests setting invalid timezone
174 public function testSettingInvalidDefaultTimezone () {
176 $this->expectException(Notice::class);
179 FrameworkBootstrap::setDefaultTimezone('!invalid!');
183 * Tests setting valid timezone
185 public function testSettingValidDefaultTimezone () {
187 $this->assertTrue(FrameworkBootstrap::setDefaultTimezone('Europe/Berlin'));
191 * Tests if detectServerAddress() is returning what it should for tests.
192 * This will always be 127.0.0.1.
194 public function testConfigDetectServerAddress () {
196 $serverAddress = FrameworkBootstrap::detectServerAddress();
198 // Should be the same
199 $this->assertEquals(self::$ipAddress, $serverAddress);
203 * Re-tests if detectServerAddress() is returning what it should for tests.
204 * This will always be 127.0.0.1. This method should not invoke
205 * ConsoleTools's method as the configuration entry is already cached.
207 public function testConfigDetectServerAddressCached () {
209 $serverAddress = FrameworkBootstrap::detectServerAddress();
211 // Should be the same
212 $this->assertEquals(self::$ipAddress, $serverAddress);