]> git.mxchange.org Git - core.git/blob - tests/framework/bootstrap/class_FrameworkBootstrapTest.php
Continued:
[core.git] / tests / framework / bootstrap / class_FrameworkBootstrapTest.php
1 <?php
2
3 // Same namespace as target class
4 namespace Org\Mxchange\CoreFramework\Bootstrap;
5
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;
11
12 // Import PHPUnit stuff
13 use PHPUnit\Framework\Error\Notice;
14 use PHPUnit\Framework\TestCase;
15
16 // Import SPL stuff
17 use \InvalidArgumentException;
18
19 /*
20  * Copyright (C) 2017 - 2020 Core Developer Team
21  *
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.
26  *
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.
31  *
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/>.
34  */
35 class FrameworkBootstrapTest extends TestCase {
36
37         /**
38          * Own IP address
39          */
40         private static $ipAddress = FALSE;
41
42         /**
43          * Setup test case
44          */
45         public function setUp() {
46                 // Trace message
47                 //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
48
49                 // Call parent method
50                 parent::setUp();
51
52                 // Trace message
53                 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
54
55         }
56
57         /**
58          * Setup test case
59          */
60         public static function setUpBeforeClass() {
61                 // Trace message
62                 //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
63
64                 // Call parent method
65                 parent::setUpBeforeClass();
66
67                 /*
68                  * Disable strict naming-convention check in own class loader, because
69                  * PHP_Invoker doesn't have namespaces.
70                  */
71                 ClassLoader::enableStrictNamingConventionCheck(FALSE);
72
73                 // Lookup own IP address
74                 self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
75
76                 // Trace message
77                 //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
78         }
79
80         /**
81          * Tests setting an empty default timezone
82          */
83         public function testSettingEmptyDefaultTimezone () {
84                 // Will throw this exception
85                 $this->expectException(InvalidArgumentException::class);
86
87                 // Test it
88                 FrameworkBootstrap::setDefaultTimezone('');
89         }
90
91         /**
92          * Tests setting invalid timezone
93          */
94         public function testSettingInvalidDefaultTimezone () {
95                 // Expect Notice
96                 $this->expectException(Notice::class);
97
98                 // Try to set it
99                 FrameworkBootstrap::setDefaultTimezone('!invalid!');
100         }
101
102         /**
103          * Tests setting valid timezone
104          */
105         public function testSettingValidDefaultTimezone () {
106                 // Will be true
107                 $this->assertTrue(FrameworkBootstrap::setDefaultTimezone('Europe/Berlin'));
108         }
109
110         /**
111          * Tests if detectServerAddress() is returning what it should for tests.
112          * This will always be 127.0.0.1.
113          */
114         public function testConfigDetectServerAddress () {
115                 // Call it
116                 $serverAddress = FrameworkBootstrap::detectServerAddress();
117
118                 // Should be the same
119                 $this->assertEquals(self::$ipAddress, $serverAddress);
120         }
121
122         /**
123          * Re-tests if detectServerAddress() is returning what it should for tests.
124          * This will always be 127.0.0.1. This method should not invoke
125          * ConsoleTools's method as the configuration entry is already cached.
126          */
127         public function testConfigDetectServerAddressCached () {
128                 // Call it
129                 $serverAddress = FrameworkBootstrap::detectServerAddress();
130
131                 // Should be the same
132                 $this->assertEquals(self::$ipAddress, $serverAddress);
133         }
134
135 }