Refactor ConfigLib and remove outdated tests
This commit is contained in:
parent
b405190389
commit
d44020aacf
5 changed files with 225 additions and 132 deletions
100
tests/ConfigLib/ConfigurationTest.php
Normal file
100
tests/ConfigLib/ConfigurationTest.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
namespace ConfigLib;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConfigurationTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
unlink($config->getPath());
|
||||
}
|
||||
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$config = new Configuration();
|
||||
$this->assertInstanceOf(Configuration::class, $config);
|
||||
}
|
||||
|
||||
public function testSetExists(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
|
||||
$this->assertTrue($config->set('key1.key2', 'value', true));
|
||||
$this->assertEquals('value', $config->get('key1.key2'));
|
||||
}
|
||||
|
||||
public function testSetNotExists(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
$this->assertFalse($config->set('key1.key3', 'value'));
|
||||
}
|
||||
|
||||
public function testSetInvalidKey(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
$this->assertFalse($config->set('invalid\key', 'value'));
|
||||
}
|
||||
|
||||
public function testGetExists(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
$config->set('key1.key2', 'value');
|
||||
$this->assertEquals('value', $config->get('key1.key2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* Test get method when provided with existing key
|
||||
*/
|
||||
public function testGetMethodWithValidKey(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
$config->set('key1.key2', 'value');
|
||||
$this->assertEquals('value', $config->get('key1.key2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* Test get method when provided with non-existing key
|
||||
*/
|
||||
public function testGetMethodWithInvalidKey(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
$this->assertNull($config->get('non.existing.key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* Test get method when key format is not valid
|
||||
*/
|
||||
public function testGetMethodWithIncorrectKeyFormat(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
$this->assertNull($config->get('incorrect\format'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* Test get method when provided with existing key and expecting the default value to be returned
|
||||
*/
|
||||
public function testGetMethodWithValidKeyExpectingDefaultValue(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
$config->set('key1.key2', null);
|
||||
$this->assertEquals('default', $config->get('key1.key2', 'default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* Test setDefault method when non-existing key is provided
|
||||
*/
|
||||
public function testSetDefaultWithNonExistingKey(): void
|
||||
{
|
||||
$config = new Configuration('test');
|
||||
$this->assertTrue($config->setDefault('non.existing.key', 'default'));
|
||||
$this->assertEquals('default', $config->get('non.existing.key'));
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
import('net.nosial.configlib');
|
||||
|
||||
$config = new \ConfigLib\Configuration('test');
|
||||
|
||||
$config->setDefault('database.host', '127.0.0.1');
|
||||
$config->setDefault('database.port', 3306);
|
||||
$config->setDefault('database.username', 'root');
|
||||
$config->setDefault('database.password', null);
|
||||
$config->setDefault('database.name', 'test');
|
||||
|
||||
$config->save();
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
import('net.nosial.configlib');
|
||||
|
||||
$config = new \ConfigLib\Configuration('test');
|
||||
|
||||
$config->set('database.host', '192.168.1.1');
|
||||
$config->set('database.username', 'super_root');
|
||||
|
||||
$config->save();
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
import('net.nosial.configlib');
|
||||
|
||||
$config = new \ConfigLib\Configuration('test');
|
||||
|
||||
var_dump($config->getConfiguration());
|
Loading…
Add table
Add a link
Reference in a new issue