]> git.mxchange.org Git - core.git/blobdiff - tests/framework/bootstrap/class_FrameworkBootstrapTest.php
Continued with unit tests:
[core.git] / tests / framework / bootstrap / class_FrameworkBootstrapTest.php
diff --git a/tests/framework/bootstrap/class_FrameworkBootstrapTest.php b/tests/framework/bootstrap/class_FrameworkBootstrapTest.php
new file mode 100644 (file)
index 0000000..95a847c
--- /dev/null
@@ -0,0 +1,215 @@
+<?php
+
+// Same namespace as target class
+namespace CoreFramework\Bootstrap;
+
+// Inport framework stuff
+use CoreFramework\Console\Tools\ConsoleTools;
+use CoreFramework\Loader\ClassLoader;
+use CoreFramework\Generic\NullPointerException;
+use CoreFramework\Generic\UnsupportedOperationException;
+
+// Import PHPUnit stuff
+use PHPUnit\Framework\Error\Notice;
+use PHPUnit\Framework\TestCase;
+
+// Import SPL stuff
+use \InvalidArgumentException;
+
+/*
+ * Copyright (C) 2017 Roland Haeder<roland@mxchange.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+class FrameworkBootstrapTest extends TestCase {
+
+       /**
+        * Own IP address
+        */
+       private static $ipAddress = FALSE;
+
+       /**
+        * Setup test case
+        */
+       public function setUp() {
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
+
+               // Call parent method
+               parent::setUp();
+
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
+
+       }
+
+       /**
+        * Setup test case
+        */
+       public static function setUpBeforeClass() {
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
+
+               // Call parent method
+               parent::setUpBeforeClass();
+
+               /*
+                * Disable strict naming-convention check in own class loader, because
+                * PHP_Invoker doesn't have namespaces.
+                */
+               ClassLoader::enableStrictNamingConventionCheck(FALSE);
+
+               // Lookup own IP address
+               self::$ipAddress = ConsoleTools::acquireSelfIpAddress();
+
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
+       }
+
+       /**
+        * Tests setting a NULL default timezone
+        */
+       public function testSettingNullDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(NullPointerException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(NULL);
+       }
+
+       /**
+        * Tests setting a boolean default timezone
+        */
+       public function testSettingBooleanDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(FALSE);
+       }
+
+       /**
+        * Tests setting a decimal default timezone
+        */
+       public function testSettingDecimalDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(12345);
+       }
+
+       /**
+        * Tests setting a float default timezone
+        */
+       public function testSettingFloatDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(123.45);
+       }
+
+       /**
+        * Tests setting an array default timezone
+        */
+       public function testSettingArrayDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone(array());
+       }
+
+       /**
+        * Tests setting an object default timezone
+        */
+       public function testSettingObjectDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone($this);
+       }
+
+       /**
+        * Tests setting a resource default timezone
+        */
+       public function testSettingResourceDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Init some resource
+               $resource = fopen(__FILE__, 'r');
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone($resource);
+       }
+
+       /**
+        * Tests setting an empty default timezone
+        */
+       public function testSettingEmptyDefaultTimezone () {
+               // Will throw this exception
+               $this->expectException(InvalidArgumentException::class);
+
+               // Test it
+               FrameworkBootstrap::setDefaultTimezone('');
+       }
+
+       /**
+        * Tests setting invalid timezone
+        */
+       public function testSettingInvalidDefaultTimezone () {
+               // Expect Notice
+               $this->expectException(Notice::class);
+
+               // Try to set it
+               FrameworkBootstrap::setDefaultTimezone('!invalid!');
+       }
+
+       /**
+        * Tests setting valid timezone
+        */
+       public function testSettingValidDefaultTimezone () {
+               // Will be true
+               $this->assertTrue(FrameworkBootstrap::setDefaultTimezone('Europe/Berlin'));
+       }
+
+       /**
+        * Tests if detectServerAddress() is returning what it should for tests.
+        * This will always be 127.0.0.1.
+        */
+       public function testConfigDetectServerAddress () {
+               // Call it
+               $serverAddress = FrameworkBootstrap::detectServerAddress();
+
+               // Should be the same
+               $this->assertEquals(self::$ipAddress, $serverAddress);
+       }
+
+       /**
+        * Re-tests if detectServerAddress() is returning what it should for tests.
+        * This will always be 127.0.0.1. This call should not invoke
+        * ConsoleTools's method as the configuration entry is already cached.
+        */
+       public function testConfigDetectServerAddressCached () {
+               // Call it
+               $serverAddress = FrameworkBootstrap::detectServerAddress();
+
+               // Should be the same
+               $this->assertEquals(self::$ipAddress, $serverAddress);
+       }
+
+}