Verified Commit 01391069 authored by Damien Calesse's avatar Damien Calesse
Browse files

Update unit tests

parent bf1787aa
Pipeline #24 passed with stages
in 4 minutes and 29 seconds
......@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Add unit tests
## [0.2.0] - 2020-10-29
### Added
......
......@@ -37,7 +37,7 @@ class Config
public function isEmpty() : bool
{
return $this->data === null || empty($this->data);
return $this->data === null || empty((array) $this->data);
}
public function isFormatValid() : bool
......
......@@ -20,6 +20,11 @@ trait Log
*/
private $config;
public function __construct(Config $config)
{
$this->config = $config;
}
/**
* @return boolean
*/
......
<?php
require_once(__DIR__ . '/../vendor/autoload.php');
use Mumble\Mumble;
use Mumble\Server;
$mumble = Mumble::init(dirname(__DIR__) . '/config/config.json');
//print_r($mumble->list());
foreach ($mumble->list() as $master) {
foreach ($master as $server) {
//print_r($server->getInfos());
if ($server->id() !== 1) {
//if (!$server->running()) $server->start();
//if ($server->running()) $server->stop();
//$server->delete();
print_r($server->getInfos());
$server->updateConf([ 'users' => '200' ]);
}
}
}
//$server = $mumble->create((object) [ 'users' => 10, 'port' => 30002 ]);
//$server->start();
//print_r($server->getConf());
\ No newline at end of file
<?php
namespace Mumble;
use PHPUnit\Framework\TestCase;
use org\bovigo\vfs\{ vfsStream, vfsStreamDirectory };
use Mumble\Exceptions\{ ConfigurationNotFound, ConfigurationNotValid };
class ConfigTest extends TestCase
{
public function setUp() : void
{
$this->dir = vfsStream::setup('config', null, [
'config.json' => '{ "servers": [
{
"name": "Default",
"ip": "127.0.0.1",
"port": 6502,
"secret": "xxxxxxxxx"
}
]}',
'empty-config.json' => '{}',
'invalid-config.json' => ''
]);
}
public function testFileExists() : void
{
$config = new Config\Config(vfsStream::url('config/config.json'));
$this->assertTrue($config->exists());
}
public function testFileNotExists() : void
{
$config = new Config\Config(vfsStream::url('config/config-not-exists.json'));
$this->assertFalse($config->exists());
}
public function testFileNotExistsException() : void
{
$this->expectException(ConfigurationNotFound::class);
$config = (new Config\Config(vfsStream::url('config/config-not-exists.json')))->open();
}
public function testFileNotEmpty() : void
{
$config = (new Config\Config(vfsStream::url('config/config.json')))->open();
$this->assertFalse($config->isEmpty());
}
public function testFileIsEmpty() : void
{
$this->expectException(ConfigurationNotValid::class);
(new Config\Config(vfsStream::url('config/empty-config.json')))->open();
}
public function testIsValid() : void
{
$config = (new Config\Config(vfsStream::url('config/config.json')))->open();
$this->assertTrue($config->validate());
}
public function testNotValid() : void
{
$config = (new Config\Config(vfsStream::url('config/invalid-config.json')));
$this->assertFalse($config->validate());
}
public function testNotValidException() : void
{
$this->expectException(ConfigurationNotValid::class);
(new Config\Config(vfsStream::url('config/invalid-config.json')))->open();
}
public function testIsUsingLog() : void
{
$config = (new Config\Config(vfsStream::url('config/config.json')))->open();
$this->assertFalse($config->isUsingLog());
}
public function testGetAttributes() : void
{
$config = (new Config\Config(vfsStream::url('config/config.json')))->open();
$this->assertNull($config->get('not-exists'));
$this->assertIsArray($config->get('servers'));
$this->assertNotEmpty($config->get('servers'));
}
}
\ No newline at end of file
<?php
namespace Mumble;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use org\bovigo\vfs\{ vfsStream, vfsStreamDirectory };
class LogTest extends TestCase
{
public function setUp() : void
{
$this->dir = vfsStream::setup('config', null, [
'config.json' => '{ "servers": [
{
"name": "Default",
"ip": "127.0.0.1",
"port": 6502,
"secret": "xxxxxxxxx"
}
]}',
'config-log-debug.json' => '{"log": { "active": true, "level": "debug" }}',
'config-log-info.json' => '{"log": { "active": true, "level": "info" }}',
'config-log-notice.json' => '{"log": { "active": true, "level": "notice" }}',
'config-log-warning.json' => '{"log": { "active": true, "level": "warning" }}',
'config-log-error.json' => '{"log": { "active": true, "level": "error" }}',
'config-log-critical.json' => '{"log": { "active": true, "level": "critical" }}',
'config-log-alert.json' => '{"log": { "active": true, "level": "alert" }}',
'config-log-emergency.json' => '{"log": { "active": true, "level": "emergency" }}'
]);
}
public function testConfigWithoutLog() : void
{
$log = $this->getObjectForTrait('\Mumble\Log', [ (new Config\Config(vfsStream::url('config/config.json')))->open() ]);
$this->assertFalse($log->isUsingLog());
$this->assertEquals(Logger::WARNING, $log->getLogLevel());
}
/**
* @dataProvider configWithLogProvider
*
* @param string $configPath
* @param integer $logLevelExpected
* @return void
*/
public function testConfigWithLog(string $configPath, int $logLevelExpected) : void
{
$log = $this->getObjectForTrait('\Mumble\Log', [ (new Config\Config(vfsStream::url($configPath)))->open() ]);
$this->assertTrue($log->isUsingLog());
$this->assertEquals($logLevelExpected, $log->getLogLevel());
}
public function configWithLogProvider() : array
{
return [
[ 'config/config-log-debug.json', Logger::DEBUG ],
[ 'config/config-log-info.json', Logger::INFO ],
[ 'config/config-log-notice.json', Logger::NOTICE ],
[ 'config/config-log-warning.json', Logger::WARNING ],
[ 'config/config-log-error.json', Logger::ERROR ],
[ 'config/config-log-critical.json', Logger::CRITICAL ],
[ 'config/config-log-alert.json', Logger::ALERT ],
[ 'config/config-log-emergency.json', Logger::EMERGENCY ]
];
}
}
\ No newline at end of file
......@@ -5,37 +5,29 @@ namespace Mumble;
use PHPUnit\Framework\TestCase;
use org\bovigo\vfs\{ vfsStream, vfsStreamDirectory };
class ConfigTest extends TestCase
class MumbleTest extends TestCase
{
public function setUp() : void
{
$this->dir = vfsStream::setup('config', null, [
'config.json' => '{ "servers": [
{
"name": "Default",
"ip": "127.0.0.1",
"port": 6502,
"secret": "xxxxxxxxx"
}
]}',
'empty-config.json' => '{}',
'invalid-config.json' => ''
'config.json' => '{ "servers": [] }',
]);
}
public function testFileExists() : void
public function testCreateInstance() : void
{
$config = new Config\Config(vfsStream::url('config/config.json'));
$mumble = new Mumble($config);
$this->assertTrue($config->exists());
$this->assertEmpty($mumble->list());
}
public function testFileNotEmpty() : void
public function testInit() : void
{
$config = (new Config\Config(vfsStream::url('config/config.json')))->open();
$mumble = Mumble::init(vfsStream::url('config/config.json'));
$this->assertFalse($config->isEmpty());
$this->assertEmpty($mumble->list());
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment