<?php
-
// Same namespace as target class
-namespace CoreFramework\Configuration;
+namespace Org\Mxchange\CoreFramework\Configuration;
// Inport framework stuff
-use CoreFramework\Loader\ClassLoader;
-use CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration;
+use Org\Mxchange\CoreFramework\Configuration\NoConfigEntryException;
+use Org\Mxchange\CoreFramework\Loader\ClassLoader;
+use Org\Mxchange\CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
// Import PHPUnit stuff
use PHPUnit\Framework\Error\Notice;
use \InvalidArgumentException;
/*
- * Copyright (C) 2017 Roland Haeder<roland@mxchange.org>
+ * 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
* 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 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
$className = self::$configInstance->__toString();
// Should be equal
- $this->assertEquals('CoreFramework\Configuration\FrameworkConfiguration', $className);
+ $this->assertEquals('Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration', $className);
}
/**
*/
public function testGettingSelfConfigInstance () {
// Get instance
- $dummyInstance = FrameworkConfiguration::getSelfInstance();
+ $dummyInstance = FrameworkBootstrap::getConfigurationInstance();
// Should be equal to own instance
$this->assertEquals(self::$configInstance, $dummyInstance);
*/
public function testEqualsConfigInstance () {
// Get instance
- $dummyInstance = FrameworkConfiguration::getSelfInstance();
+ $dummyInstance = new FrameworkConfiguration();
// Should return TRUE
$this->assertTrue(self::$configInstance->equals($dummyInstance));
*/
public function testHashCodeConfigInstance () {
// Get instance
- $dummyInstance = FrameworkConfiguration::getSelfInstance();
+ $dummyInstance = FrameworkBootstrap::getConfigurationInstance();
// Get hash code from both
$hashCodeExpected = self::$configInstance->hashCode();
*/
public function testSameConfigurationArrayGetter () {
// Get instance
- $dummyInstance = FrameworkConfiguration::getSelfInstance();
+ $dummyInstance = FrameworkBootstrap::getConfigurationInstance();
// Get it from both instances
$config1 = self::$configInstance->getConfigurationArray();
$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
*/
$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.
$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
*/
$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.
$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)
*/
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
*/
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
*/
}
/**
- * 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');
}
}