X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fframework%2Fconfig%2FFrameworkConfigurationTest.php;h=12d8e551e7d8ef3d1d07d232b0ac4e7dbbfa6e46;hb=ef7a7e55c59c9e887e6bb09c8c02b8126309f716;hp=8e33a28acb65351244b01d33507bfb59c6711e51;hpb=e49824352d4ee089daaa8043f8463cc196d079ec;p=core.git diff --git a/tests/framework/config/FrameworkConfigurationTest.php b/tests/framework/config/FrameworkConfigurationTest.php index 8e33a28a..12d8e551 100644 --- a/tests/framework/config/FrameworkConfigurationTest.php +++ b/tests/framework/config/FrameworkConfigurationTest.php @@ -1,11 +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 @@ -30,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 { /** @@ -64,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 @@ -84,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); } /** @@ -92,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); @@ -103,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)); @@ -114,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(); @@ -152,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(); @@ -162,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 */ @@ -195,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. @@ -270,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 */ @@ -303,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. @@ -384,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) */ @@ -417,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 */ @@ -511,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 */ @@ -581,174 +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 + * 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 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('127.0.0.1', $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('127.0.0.1', $serverAddress); - } - - /** - * Tests setting a NULL server address - */ - public function testConfigSettingNullServerAddress () { + public function testConfigGetFieldUnsupported () { // Expect this exception - $this->expectException(NullPointerException::class); + $this->expectException(UnsupportedOperationException::class); // Test it - self::$configInstance->setServerAddress(NULL); + $dummy = self::$configInstance->getField('foo'); } /** - * Tests setting a boolean 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 testConfigSettingBooleanServerAddress () { + public function testConfigIsFieldSetUnsupported () { // 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); + $this->expectException(UnsupportedOperationException::class); // Test it - self::$configInstance->setServerAddress(12345); - } - - /** - * Tests setting a float server address - */ - public function testConfigSettingFloatServerAddress () { - // Expect this exception - $this->expectException(InvalidArgumentException::class); - - // Test it - self::$configInstance->setServerAddress(123.45); - } - - /** - * Tests setting an array server address - */ - public function testConfigSettingArrayServerAddress () { - // Expect this exception - $this->expectException(InvalidArgumentException::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); + $dummy = self::$configInstance->isFieldSet('foo'); } }