Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
ae1d1b9d
Unverified
Commit
ae1d1b9d
authored
Jul 18, 2019
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new tests for external updates logger.
parent
5002857e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
21 deletions
+37
-21
TelegramLogTest.php
tests/unit/TelegramLogTest.php
+37
-21
No files found.
tests/unit/TelegramLogTest.php
View file @
ae1d1b9d
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
namespace
Longman\TelegramBot\Tests\Unit
;
namespace
Longman\TelegramBot\Tests\Unit
;
use
Longman\TelegramBot\Exception\TelegramLogException
;
use
Longman\TelegramBot\TelegramLog
;
use
Longman\TelegramBot\TelegramLog
;
use
Monolog\Handler\StreamHandler
;
use
Monolog\Handler\StreamHandler
;
use
Monolog\Logger
;
use
Monolog\Logger
;
...
@@ -27,17 +28,18 @@ class TelegramLogTest extends TestCase
...
@@ -27,17 +28,18 @@ class TelegramLogTest extends TestCase
* @var array Dummy logfile paths
* @var array Dummy logfile paths
*/
*/
private
static
$logfiles
=
[
private
static
$logfiles
=
[
'error'
=>
'/tmp/php-telegram-bot-errorlog.log'
,
'error'
=>
'/tmp/php-telegram-bot-error.log'
,
'debug'
=>
'/tmp/php-telegram-bot-debuglog.log'
,
'debug'
=>
'/tmp/php-telegram-bot-debug.log'
,
'update'
=>
'/tmp/php-telegram-bot-updatelog.log'
,
'update'
=>
'/tmp/php-telegram-bot-update.log'
,
'external'
=>
'/tmp/php-telegram-bot-externallog.log'
,
'external'
=>
'/tmp/php-telegram-bot-external.log'
,
'external_update'
=>
'/tmp/php-telegram-bot-external_update.log'
,
];
];
protected
function
setUp
()
protected
function
setUp
()
{
{
// Make sure no logger instance is set before each test.
// Make sure no logger instance is set before each test.
TestHelpers
::
setStaticProperty
(
'Longman\TelegramBot\TelegramLog'
,
'logger'
,
null
);
TestHelpers
::
setStaticProperty
(
TelegramLog
::
class
,
'logger'
,
null
);
TestHelpers
::
setStaticProperty
(
'Longman\TelegramBot\TelegramLog'
,
'update_logger'
,
null
);
TestHelpers
::
setStaticProperty
(
TelegramLog
::
class
,
'update_logger'
,
null
);
}
}
protected
function
tearDown
()
protected
function
tearDown
()
...
@@ -48,39 +50,35 @@ class TelegramLogTest extends TestCase
...
@@ -48,39 +50,35 @@ class TelegramLogTest extends TestCase
}
}
}
}
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramLogException
*/
public
function
testNewInstanceWithoutErrorPath
()
public
function
testNewInstanceWithoutErrorPath
()
{
{
$this
->
setExpectedException
(
TelegramLogException
::
class
);
TelegramLog
::
initErrorLog
(
''
);
TelegramLog
::
initErrorLog
(
''
);
}
}
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramLogException
*/
public
function
testNewInstanceWithoutDebugPath
()
public
function
testNewInstanceWithoutDebugPath
()
{
{
$this
->
setExpectedException
(
TelegramLogException
::
class
);
TelegramLog
::
initDebugLog
(
''
);
TelegramLog
::
initDebugLog
(
''
);
}
}
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramLogException
*/
public
function
testNewInstanceWithoutUpdatePath
()
public
function
testNewInstanceWithoutUpdatePath
()
{
{
$this
->
setExpectedException
(
TelegramLogException
::
class
);
TelegramLog
::
initUpdateLog
(
''
);
TelegramLog
::
initUpdateLog
(
''
);
}
}
public
function
testErrorStream
()
public
function
testErrorStream
()
{
{
$file
=
self
::
$logfiles
[
'error'
];
$file
=
self
::
$logfiles
[
'error'
];
$this
->
assertFileNotExists
(
$file
);
$this
->
assertFileNotExists
(
$file
);
TelegramLog
::
initErrorLog
(
$file
);
TelegramLog
::
initErrorLog
(
$file
);
TelegramLog
::
error
(
'my error'
);
TelegramLog
::
error
(
'my error'
);
TelegramLog
::
error
(
'my 50% error'
);
TelegramLog
::
error
(
'my 50% error'
);
TelegramLog
::
error
(
'my old %s %s error'
,
'custom'
,
'placeholder'
);
TelegramLog
::
error
(
'my old %s %s error'
,
'custom'
,
'placeholder'
);
TelegramLog
::
error
(
'my new {place} {holder} error'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
TelegramLog
::
error
(
'my new {place} {holder} error'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
$this
->
assertFileExists
(
$file
);
$this
->
assertFileExists
(
$file
);
$error_log
=
file_get_contents
(
$file
);
$error_log
=
file_get_contents
(
$file
);
$this
->
assertContains
(
'bot_log.ERROR: my error'
,
$error_log
);
$this
->
assertContains
(
'bot_log.ERROR: my error'
,
$error_log
);
...
@@ -92,12 +90,14 @@ class TelegramLogTest extends TestCase
...
@@ -92,12 +90,14 @@ class TelegramLogTest extends TestCase
public
function
testDebugStream
()
public
function
testDebugStream
()
{
{
$file
=
self
::
$logfiles
[
'debug'
];
$file
=
self
::
$logfiles
[
'debug'
];
$this
->
assertFileNotExists
(
$file
);
$this
->
assertFileNotExists
(
$file
);
TelegramLog
::
initDebugLog
(
$file
);
TelegramLog
::
initDebugLog
(
$file
);
TelegramLog
::
debug
(
'my debug'
);
TelegramLog
::
debug
(
'my debug'
);
TelegramLog
::
debug
(
'my 50% debug'
);
TelegramLog
::
debug
(
'my 50% debug'
);
TelegramLog
::
debug
(
'my old %s %s debug'
,
'custom'
,
'placeholder'
);
TelegramLog
::
debug
(
'my old %s %s debug'
,
'custom'
,
'placeholder'
);
TelegramLog
::
debug
(
'my new {place} {holder} debug'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
TelegramLog
::
debug
(
'my new {place} {holder} debug'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
$this
->
assertFileExists
(
$file
);
$this
->
assertFileExists
(
$file
);
$debug_log
=
file_get_contents
(
$file
);
$debug_log
=
file_get_contents
(
$file
);
$this
->
assertContains
(
'bot_log.DEBUG: my debug'
,
$debug_log
);
$this
->
assertContains
(
'bot_log.DEBUG: my debug'
,
$debug_log
);
...
@@ -109,12 +109,14 @@ class TelegramLogTest extends TestCase
...
@@ -109,12 +109,14 @@ class TelegramLogTest extends TestCase
public
function
testUpdateStream
()
public
function
testUpdateStream
()
{
{
$file
=
self
::
$logfiles
[
'update'
];
$file
=
self
::
$logfiles
[
'update'
];
$this
->
assertFileNotExists
(
$file
);
$this
->
assertFileNotExists
(
$file
);
TelegramLog
::
initUpdateLog
(
$file
);
TelegramLog
::
initUpdateLog
(
$file
);
TelegramLog
::
update
(
'my update'
);
TelegramLog
::
update
(
'my update'
);
TelegramLog
::
update
(
'my 50% update'
);
TelegramLog
::
update
(
'my 50% update'
);
TelegramLog
::
update
(
'my old %s %s update'
,
'custom'
,
'placeholder'
);
TelegramLog
::
update
(
'my old %s %s update'
,
'custom'
,
'placeholder'
);
TelegramLog
::
update
(
'my new {place} {holder} update'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
TelegramLog
::
update
(
'my new {place} {holder} update'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
$this
->
assertFileExists
(
$file
);
$this
->
assertFileExists
(
$file
);
$update_log
=
file_get_contents
(
$file
);
$update_log
=
file_get_contents
(
$file
);
$this
->
assertContains
(
'my update'
,
$update_log
);
$this
->
assertContains
(
'my update'
,
$update_log
);
...
@@ -126,13 +128,17 @@ class TelegramLogTest extends TestCase
...
@@ -126,13 +128,17 @@ class TelegramLogTest extends TestCase
public
function
testExternalStream
()
public
function
testExternalStream
()
{
{
$file
=
self
::
$logfiles
[
'external'
];
$file
=
self
::
$logfiles
[
'external'
];
$file_update
=
self
::
$logfiles
[
'external_update'
];
$this
->
assertFileNotExists
(
$file
);
$this
->
assertFileNotExists
(
$file
);
$this
->
assertFileNotExists
(
$file_update
);
$external_monolog
=
new
Logger
(
'bot_external_log'
);
$external_logger
=
new
Logger
(
'bot_external_log'
);
$external_monolog
->
pushHandler
(
new
StreamHandler
(
$file
,
Logger
::
ERROR
));
$external_logger
->
pushHandler
(
new
StreamHandler
(
$file
,
Logger
::
ERROR
));
$external_monolog
->
pushHandler
(
new
StreamHandler
(
$file
,
Logger
::
DEBUG
));
$external_logger
->
pushHandler
(
new
StreamHandler
(
$file
,
Logger
::
DEBUG
));
$external_update_logger
=
new
Logger
(
'bot_external_update_log'
);
$external_update_logger
->
pushHandler
(
new
StreamHandler
(
$file_update
,
Logger
::
INFO
));
TelegramLog
::
initialize
(
$external_
monolog
);
TelegramLog
::
initialize
(
$external_
logger
,
$external_update_logger
);
TelegramLog
::
error
(
'my error'
);
TelegramLog
::
error
(
'my error'
);
TelegramLog
::
error
(
'my 50% error'
);
TelegramLog
::
error
(
'my 50% error'
);
TelegramLog
::
error
(
'my old %s %s error'
,
'custom'
,
'placeholder'
);
TelegramLog
::
error
(
'my old %s %s error'
,
'custom'
,
'placeholder'
);
...
@@ -141,9 +147,15 @@ class TelegramLogTest extends TestCase
...
@@ -141,9 +147,15 @@ class TelegramLogTest extends TestCase
TelegramLog
::
debug
(
'my 50% debug'
);
TelegramLog
::
debug
(
'my 50% debug'
);
TelegramLog
::
debug
(
'my old %s %s debug'
,
'custom'
,
'placeholder'
);
TelegramLog
::
debug
(
'my old %s %s debug'
,
'custom'
,
'placeholder'
);
TelegramLog
::
debug
(
'my new {place} {holder} debug'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
TelegramLog
::
debug
(
'my new {place} {holder} debug'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
TelegramLog
::
update
(
'my update'
);
TelegramLog
::
update
(
'my 50% update'
);
TelegramLog
::
update
(
'my old %s %s update'
,
'custom'
,
'placeholder'
);
TelegramLog
::
update
(
'my new {place} {holder} update'
,
[
'place'
=>
'custom'
,
'holder'
=>
'placeholder'
]);
$this
->
assertFileExists
(
$file
);
$this
->
assertFileExists
(
$file
);
$this
->
assertFileExists
(
$file_update
);
$file_contents
=
file_get_contents
(
$file
);
$file_contents
=
file_get_contents
(
$file
);
$file_update_contents
=
file_get_contents
(
$file_update
);
$this
->
assertContains
(
'bot_external_log.ERROR: my error'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.ERROR: my error'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.ERROR: my 50% error'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.ERROR: my 50% error'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.ERROR: my old custom placeholder error'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.ERROR: my old custom placeholder error'
,
$file_contents
);
...
@@ -152,5 +164,9 @@ class TelegramLogTest extends TestCase
...
@@ -152,5 +164,9 @@ class TelegramLogTest extends TestCase
$this
->
assertContains
(
'bot_external_log.DEBUG: my 50% debug'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.DEBUG: my 50% debug'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.DEBUG: my old custom placeholder debug'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.DEBUG: my old custom placeholder debug'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.DEBUG: my new custom placeholder debug'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_log.DEBUG: my new custom placeholder debug'
,
$file_contents
);
$this
->
assertContains
(
'bot_external_update_log.INFO: my update'
,
$file_update_contents
);
$this
->
assertContains
(
'bot_external_update_log.INFO: my 50% update'
,
$file_update_contents
);
$this
->
assertContains
(
'bot_external_update_log.INFO: my old custom placeholder update'
,
$file_update_contents
);
$this
->
assertContains
(
'bot_external_update_log.INFO: my new custom placeholder update'
,
$file_update_contents
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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