]> git.mxchange.org Git - core.git/blob - tests/framework/bootstrap/class_FrameworkBootstrapTest.php
ff22b9a9082615be2c4ab40abd2690ca3437fba2
[core.git] / tests / framework / bootstrap / class_FrameworkBootstrapTest.php
1 <?php
2 // Same namespace as target class
3 namespace Org\Mxchange\CoreFramework\Bootstrap;
4
5 // Inport framework stuff
6 use Org\Mxchange\CoreFramework\Console\Tools\ConsoleTools;
7 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
8 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
9
10 // Import PHPUnit stuff
11 use PHPUnit\Framework\Error\Notice;
12 use PHPUnit\Framework\TestCase;
13
14 // Import SPL stuff
15 use \InvalidArgumentException;
16
17 /*
18  * Copyright (C) 2017 - 2020 Core Developer Team
19  *
20  * This program is free software: you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation, either version 3 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
32  */
33 class FrameworkBootstrapTest extends TestCase {
34
35         /**
36          * Own IP address
37          */
38         private static $ipAddress = FALSE;
39
40         /**
41          * Setup test case
42          */
43         public function setUp() {
44                 // Trace message
45                 //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
46
47                 // Call parent method
48                 parent::setUp();
49
50                 // Trace message
51                 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
52
53         }
54
55         /**
56          * Setup test case
57          */
58         public static function setUpBeforeClass() {
59                 // Trace message
60                 //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
61
62                 // Call parent method
63                 parent::setUpBeforeClass();
64
65                 // Lookup own IP address
66                 self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
67
68                 // Trace message
69                 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
70         }
71
72         /**
73          * Tests setting an empty default timezone
74          */
75         public function testSettingEmptyDefaultTimezone () {
76                 // Will throw this exception
77                 $this->expectException(InvalidArgumentException::class);
78
79                 // Test it
80                 FrameworkBootstrap::setDefaultTimezone('');
81         }
82
83         /**
84          * Tests setting invalid timezone
85          */
86         public function testSettingInvalidDefaultTimezone () {
87                 // Expect Notice
88                 $this->expectException(Notice::class);
89
90                 // Try to set it
91                 FrameworkBootstrap::setDefaultTimezone('!invalid!');
92         }
93
94         /**
95          * Tests setting valid timezone
96          */
97         public function testSettingValidDefaultTimezone () {
98                 // Will be true
99                 $this->assertTrue(FrameworkBootstrap::setDefaultTimezone('Europe/Berlin'));
100         }
101
102         /**
103          * Tests if detectServerAddress() is returning what it should for tests.
104          * This will always be 127.0.0.1.
105          */
106         public function testConfigDetectServerAddress () {
107                 // Call it
108                 $serverAddress = FrameworkBootstrap::detectServerAddress();
109
110                 // Should be the same
111                 $this->assertEquals(self::$ipAddress, $serverAddress);
112         }
113
114         /**
115          * Re-tests if detectServerAddress() is returning what it should for tests.
116          * This will always be 127.0.0.1. This method should not invoke
117          * ConsoleTools's method as the configuration entry is already cached.
118          */
119         public function testConfigDetectServerAddressCached () {
120                 // Call it
121                 $serverAddress = FrameworkBootstrap::detectServerAddress();
122
123                 // Should be the same
124                 $this->assertEquals(self::$ipAddress, $serverAddress);
125         }
126
127 }