Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mumble
Mumble
Commits
01391069
Verified
Commit
01391069
authored
Oct 29, 2020
by
Damien Calesse
Browse files
Update unit tests
parent
bf1787aa
Pipeline
#24
passed with stages
in 4 minutes and 29 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
01391069
...
...
@@ -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
...
...
src/Config/Config.php
View file @
01391069
...
...
@@ -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
...
...
src/Log.php
View file @
01391069
...
...
@@ -20,6 +20,11 @@ trait Log
*/
private
$config
;
public
function
__construct
(
Config
$config
)
{
$this
->
config
=
$config
;
}
/**
* @return boolean
*/
...
...
test/test.php
deleted
100644 → 0
View file @
bf1787aa
<?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
test/unit/Config/ConfigTest.php
0 → 100644
View file @
01391069
<?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
test/unit/LogTest.php
0 → 100644
View file @
01391069
<?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
test/unit/
Config
Test.php
→
test/unit/
Mumble
Test.php
View file @
01391069
...
...
@@ -5,37 +5,29 @@ namespace Mumble;
use
PHPUnit\Framework\TestCase
;
use
org\bovigo\vfs\
{
vfsStream
,
vfsStreamDirectory
};
class
Config
Test
extends
TestCase
class
Mumble
Test
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
test
FileExists
()
:
void
public
function
test
CreateInstance
()
:
void
{
$config
=
new
Config\Config
(
vfsStream
::
url
(
'config/config.json'
));
$mumble
=
new
Mumble
(
$config
);
$this
->
assert
True
(
$config
->
ex
ist
s
());
$this
->
assert
Empty
(
$mumble
->
l
ist
());
}
public
function
test
FileNotEmpty
()
:
void
public
function
test
Init
()
:
void
{
$
config
=
(
new
Config\Config
(
vfsStream
::
url
(
'config/config.json'
))
)
->
open
()
;
$
mumble
=
Mumble
::
init
(
vfsStream
::
url
(
'config/config.json'
));
$this
->
assert
False
(
$config
->
is
Empty
());
$this
->
assert
Empty
(
$mumble
->
l
is
t
());
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment