X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fframework%2Fconfig%2FFrameworkConfigurationTest.php;h=12d8e551e7d8ef3d1d07d232b0ac4e7dbbfa6e46;hb=ef7a7e55c59c9e887e6bb09c8c02b8126309f716;hp=324a8fe0ad52c49e21e1736dc6ff19d29db4a114;hpb=d368d588ce51693181e74a6bee9f96e8e78b96d4;p=core.git diff --git a/tests/framework/config/FrameworkConfigurationTest.php b/tests/framework/config/FrameworkConfigurationTest.php index 324a8fe0..12d8e551 100644 --- a/tests/framework/config/FrameworkConfigurationTest.php +++ b/tests/framework/config/FrameworkConfigurationTest.php @@ -1,12 +1,14 @@ + * Copyright (C) 2017 - 2020 - Core Developer Team * * 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 @@ -31,7 +33,6 @@ use \InvalidArgumentException; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - class FrameworkConfigurationTest extends TestCase { /** @@ -39,11 +40,6 @@ class FrameworkConfigurationTest extends TestCase { */ private static $configInstance = NULL; - /** - * Own IP address - */ - private static $ipAddress = FALSE; - /** * Setup test case */ @@ -70,7 +66,7 @@ class FrameworkConfigurationTest extends TestCase { parent::setUpBeforeClass(); // Init instance - self::$configInstance = FrameworkConfiguration::getSelfInstance(); + self::$configInstance = FrameworkBootstrap::getConfigurationInstance(); /* * Disable strict naming-convention check in own class loader, because @@ -78,12 +74,6 @@ class FrameworkConfigurationTest extends TestCase { */ ClassLoader::enableStrictNamingConventionCheck(FALSE); - // Quiet DNS resolver as this is not wanted here - self::$configInstance->setConfigEntry('quiet_dns_resolver', TRUE); - - // Lookup own IP address - self::$ipAddress = ConsoleTools::acquireSelfIpAddress(); - // Trace message //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } @@ -96,7 +86,7 @@ class FrameworkConfigurationTest extends TestCase { $className = self::$configInstance->__toString(); // Should be equal - $this->assertEquals('CoreFramework\Configuration\FrameworkConfiguration', $className); + $this->assertEquals('Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration', $className); } /** @@ -104,7 +94,7 @@ class FrameworkConfigurationTest extends TestCase { */ public function testGettingSelfConfigInstance () { // Get instance - $dummyInstance = FrameworkConfiguration::getSelfInstance(); + $dummyInstance = FrameworkBootstrap::getConfigurationInstance(); // Should be equal to own instance $this->assertEquals(self::$configInstance, $dummyInstance); @@ -115,7 +105,7 @@ class FrameworkConfigurationTest extends TestCase { */ public function testEqualsConfigInstance () { // Get instance - $dummyInstance = FrameworkConfiguration::getSelfInstance(); + $dummyInstance = new FrameworkConfiguration(); // Should return TRUE $this->assertTrue(self::$configInstance->equals($dummyInstance)); @@ -126,7 +116,7 @@ class FrameworkConfigurationTest extends TestCase { */ public function testHashCodeConfigInstance () { // Get instance - $dummyInstance = FrameworkConfiguration::getSelfInstance(); + $dummyInstance = FrameworkBootstrap::getConfigurationInstance(); // Get hash code from both $hashCodeExpected = self::$configInstance->hashCode(); @@ -164,7 +154,7 @@ class FrameworkConfigurationTest extends TestCase { */ public function testSameConfigurationArrayGetter () { // Get instance - $dummyInstance = FrameworkConfiguration::getSelfInstance(); + $dummyInstance = FrameworkBootstrap::getConfigurationInstance(); // Get it from both instances $config1 = self::$configInstance->getConfigurationArray(); @@ -174,28 +164,6 @@ class FrameworkConfigurationTest extends TestCase { $this->assertEquals($config1, $config2); } - /** - * Tests if a proper exception is thrown when check for a NULL key - */ - public function testCheckingNullConfigKey () { - // Will throw this exception - $this->expectException(NullPointerException::class); - - // Test it - $dummy = self::$configInstance->isConfigurationEntrySet(NULL); - } - - /** - * Tests if a proper exception is thrown when checking a boolean key - */ - public function testCheckingBooleanConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->isConfigurationEntrySet(FALSE); - } - /** * Tests if a proper exception is thrown when checking an empty key */ @@ -207,64 +175,6 @@ class FrameworkConfigurationTest extends TestCase { $dummy = self::$configInstance->isConfigurationEntrySet(''); } - /** - * Tests if a proper exception is thrown when checking an array key - */ - public function testCheckingArrayConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->isConfigurationEntrySet(array()); - } - - /** - * Tests if a proper exception is thrown when checking a decimal key - */ - public function testCheckingDecimalConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->isConfigurationEntrySet(12345); - } - - /** - * Tests if a proper exception is thrown when checking a float key - */ - public function testCheckingFloatConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->isConfigurationEntrySet(123.45); - } - - /** - * Tests if a proper exception is thrown when checking an object key - */ - public function testCheckingObjectConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->isConfigurationEntrySet($this); - } - - /** - * Tests if a proper exception is thrown when checking a resource key - */ - public function testCheckingResourceConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Init some resource - $resource = fopen(__FILE__, 'r'); - - // Test it - $dummy = self::$configInstance->isConfigurationEntrySet($resource); - } - /** * Tests if checking an existing (well-known) key can be found and returns * TRUE. @@ -282,28 +192,6 @@ class FrameworkConfigurationTest extends TestCase { $this->assertFalse(self::$configInstance->isConfigurationEntrySet('__non_existing_key__')); } - /** - * Tests if a proper exception is thrown when getting a NULL key - */ - public function testGettingNullConfigKey () { - // Will throw this exception - $this->expectException(NullPointerException::class); - - // Test it - $dummy = self::$configInstance->getConfigEntry(NULL); - } - - /** - * Tests if a proper exception is thrown when getting a boolean key - */ - public function testGettingBooleanConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->getConfigEntry(FALSE); - } - /** * Tests if a proper exception is thrown when getting an empty key */ @@ -315,64 +203,6 @@ class FrameworkConfigurationTest extends TestCase { $dummy = self::$configInstance->getConfigEntry(''); } - /** - * Tests if a proper exception is thrown when getting a decimal key - */ - public function testGettingDecimalConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->getConfigEntry(12345); - } - - /** - * Tests if a proper exception is thrown when getting a float key - */ - public function testGettingFloatConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->getConfigEntry(123.45); - } - - /** - * Tests if a proper exception is thrown when getting an array key - */ - public function testGettingArrayConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->getConfigEntry(array()); - } - - /** - * Tests if a proper exception is thrown when getting an object key - */ - public function testGettingObjectConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - $dummy = self::$configInstance->getConfigEntry($this); - } - - /** - * Tests if a proper exception is thrown when getting a resource key - */ - public function testGettingResourceConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Init some resource - $resource = fopen(__FILE__, 'r'); - - // Test it - $dummy = self::$configInstance->getConfigEntry($resource); - } - /** * Tests if getting a non-existing key will cause a proper exception been * thrown. @@ -396,28 +226,6 @@ class FrameworkConfigurationTest extends TestCase { $this->assertDirectoryIsReadable($value); } - /** - * Tests setting a NULL key (value doesn't matter) - */ - public function testSettingNullConfigKey () { - // Will throw this exception - $this->expectException(NullPointerException::class); - - // Test it - self::$configInstance->setConfigEntry(NULL, 'foo'); - } - - /** - * Tests setting a boolean key (value doesn't matter) - */ - public function testSettingBooleanConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setConfigEntry(FALSE, 'foo'); - } - /** * Tests setting an empty key (value doesn't matter) */ @@ -429,64 +237,6 @@ class FrameworkConfigurationTest extends TestCase { self::$configInstance->setConfigEntry('', 'foo'); } - /** - * Tests setting a decimal key (value doesn't matter) - */ - public function testSettingDecimalConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setConfigEntry(12345, 'foo'); - } - - /** - * Tests setting a float key (value doesn't matter) - */ - public function testSettingFloatConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setConfigEntry(123.45, 'foo'); - } - - /** - * Tests setting an array key (value doesn't matter) - */ - public function testSettingArrayConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setConfigEntry(array(), 'foo'); - } - - /** - * Tests setting an object key (value doesn't matter) - */ - public function testSettingObjectConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setConfigEntry($this, 'foo'); - } - - /** - * Tests setting a resource key (value doesn't matter) - */ - public function testSettingResourceConfigKey () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Init some resource - $resource = fopen(__FILE__, 'r'); - - // Test it - self::$configInstance->setConfigEntry($resource, 'foo'); - } - /** * Tests setting a valid key but array for value */ @@ -523,17 +273,6 @@ class FrameworkConfigurationTest extends TestCase { self::$configInstance->setConfigEntry('foo', $resource); } - /** - * Tests unsetting NULL key - */ - public function testUnsettingNullConfigKey () { - // Will throw this exception - $this->expectException(NullPointerException::class); - - // Test it - self::$configInstance->unsetConfigEntry(NULL); - } - /** * Tests unsetting an empty key */ @@ -593,177 +332,29 @@ class FrameworkConfigurationTest extends TestCase { } /** - * Tests setting a NULL default timezone - */ - public function testSettingNullDefaultTimezone () { - // Will throw this exception - $this->expectException(NullPointerException::class); - - // Test it - self::$configInstance->setDefaultTimezone(NULL); - } - - /** - * Tests setting an empty default timezone - */ - public function testSettingEmptyDefaultTimezone () { - // Will throw this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setDefaultTimezone(''); - } - - /** - * Tests setting invalid timezone - */ - public function testSettingInvalidDefaultTimezone () { - // Expect Notice - $this->expectException(Notice::class); - - // Try to set it - self::$configInstance->setDefaultTimezone('!invalid!'); - } - - /** - * Tests setting valid timezone - */ - public function testSettingValidDefaultTimezone () { - // Will be true - $this->assertTrue(self::$configInstance->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 = self::$configInstance->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 = self::$configInstance->detectServerAddress(); - - // Should be the same - $this->assertEquals(self::$ipAddress, $serverAddress); - } - - /** - * Tests setting a NULL server address - */ - public function testConfigSettingNullServerAddress () { - // Expect this exception - $this->expectException(NullPointerException::class); - - // Test it - self::$configInstance->setServerAddress(NULL); - } - - /** - * Tests setting a boolean server address - */ - public function testConfigSettingBooleanServerAddress () { - // Expect this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setServerAddress(FALSE); - } - - /** - * Tests setting a decimal server address - */ - public function testConfigSettingDecimalServerAddress () { - // Expect this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setServerAddress(12345); - } - - /** - * Tests setting a float server address + * Tests if the method getField() is still unsupported in this class. Please + * note, that this and isFieldSet() may get removed in the future. So also + * these test methods will be gone. */ - public function testConfigSettingFloatServerAddress () { + public function testConfigGetFieldUnsupported () { // Expect this exception - $this->expectException(InvalidArgumentException::class); + $this->expectException(UnsupportedOperationException::class); // Test it - self::$configInstance->setServerAddress(123.45); + $dummy = self::$configInstance->getField('foo'); } /** - * Tests setting an array server address + * Tests if the method isFieldSet() is still unsupported in this class. Please + * note, that this and getField() may get removed in the future. So also + * these test methods will be gone. */ - public function testConfigSettingArrayServerAddress () { + public function testConfigIsFieldSetUnsupported () { // Expect this exception - $this->expectException(InvalidArgumentException::class); + $this->expectException(UnsupportedOperationException::class); // Test it - self::$configInstance->setServerAddress(array()); - } - - /** - * Tests setting an object server address - */ - public function testConfigSettingObjectServerAddress () { - // Expect this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setServerAddress($this); - } - - /** - * Tests setting a resource server address - */ - public function testConfigSettingResourceServerAddress () { - // Expect this exception - $this->expectException(InvalidArgumentException::class); - - // Init some resource - $resource = fopen(__FILE__, 'r'); - - // Test it - self::$configInstance->setServerAddress($resource); - } - - /** - * Tests setting an empty server address - */ - public function testConfigSettingEmptyServerAddress () { - // Expect this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setServerAddress(''); - } - - /** - * Tests setting a valid server address and getting it back - */ - public function testConfigGettingValidServerAddress () { - // Test it - self::$configInstance->setServerAddress('127.0.0.1'); - - // Get it back - $serverAddress = self::$configInstance->getServerAddress(); - - // Should be equal - $this->assertEquals('127.0.0.1', $serverAddress); - - // Set old back - self::$configInstance->setServerAddress(self::$ipAddress); + $dummy = self::$configInstance->isFieldSet('foo'); } }