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
2296e807
Commit
2296e807
authored
May 26, 2016
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
again fixs and tests
parent
845f90cf
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
114 additions
and
16 deletions
+114
-16
TelegramLog.php
src/TelegramLog.php
+14
-3
MessageTest.php
tests/Unit/Entities/MessageTest.php
+8
-12
TelegramLogExternalTest.php
tests/Unit/TelegramLogExternalTest.php
+52
-0
TelegramLogTest.php
tests/Unit/TelegramLogTest.php
+40
-1
No files found.
src/TelegramLog.php
View file @
2296e807
...
@@ -70,6 +70,15 @@ class TelegramLog
...
@@ -70,6 +70,15 @@ class TelegramLog
if
(
self
::
$monolog
===
null
)
{
if
(
self
::
$monolog
===
null
)
{
if
(
$external_monolog
!==
null
)
{
if
(
$external_monolog
!==
null
)
{
self
::
$monolog
=
$external_monolog
;
self
::
$monolog
=
$external_monolog
;
foreach
(
self
::
$monolog
->
getHandlers
()
as
$handler
)
{
if
(
$handler
->
getLevel
()
==
400
)
{
self
::
$error_log_path
=
true
;
}
if
(
$handler
->
getLevel
()
==
100
)
{
self
::
$debug_log_path
=
true
;
}
}
}
else
{
}
else
{
self
::
$monolog
=
new
Logger
(
'bot_log'
);
self
::
$monolog
=
new
Logger
(
'bot_log'
);
}
}
...
@@ -86,7 +95,7 @@ class TelegramLog
...
@@ -86,7 +95,7 @@ class TelegramLog
*/
*/
public
static
function
initErrorLog
(
$path
)
public
static
function
initErrorLog
(
$path
)
{
{
if
(
$path
!
==
''
)
{
if
(
$path
===
null
||
$path
=
==
''
)
{
throw
new
TelegramLogException
(
'Empty path for error log'
);
throw
new
TelegramLogException
(
'Empty path for error log'
);
}
}
self
::
initialize
();
self
::
initialize
();
...
@@ -103,7 +112,7 @@ class TelegramLog
...
@@ -103,7 +112,7 @@ class TelegramLog
*/
*/
public
static
function
initDebugLog
(
$path
)
public
static
function
initDebugLog
(
$path
)
{
{
if
(
$path
!
==
''
)
{
if
(
$path
===
null
||
$path
=
==
''
)
{
throw
new
TelegramLogException
(
'Empty path for debug log'
);
throw
new
TelegramLogException
(
'Empty path for debug log'
);
}
}
self
::
initialize
();
self
::
initialize
();
...
@@ -117,11 +126,13 @@ class TelegramLog
...
@@ -117,11 +126,13 @@ class TelegramLog
* Initilize monolog instance. Singleton
* Initilize monolog instance. Singleton
* Is possbile provide an external monolog instance
* Is possbile provide an external monolog instance
*
*
* @param string $path
*
* @return \Monolog\Logger
* @return \Monolog\Logger
*/
*/
public
static
function
initUpdateLog
(
$path
)
public
static
function
initUpdateLog
(
$path
)
{
{
if
(
$path
!
==
''
)
{
if
(
$path
===
null
||
$path
=
==
''
)
{
throw
new
TelegramLogException
(
'Empty path for update log'
);
throw
new
TelegramLogException
(
'Empty path for update log'
);
}
}
self
::
$update_log_path
=
$path
;
self
::
$update_log_path
=
$path
;
...
...
tests/Unit/Entities/MessageTest.php
View file @
2296e807
...
@@ -33,12 +33,8 @@ class MessageTest extends TestCase
...
@@ -33,12 +33,8 @@ class MessageTest extends TestCase
{
{
}
}
protected
function
generateMessage
(
$string
)
{
protected
function
generateMessage
(
$string
)
{
//$string = addslashes($string);
$string
=
str_replace
(
"
\n
"
,
"
\\
n"
,
$string
);
$string
=
str_replace
(
"
\n
"
,
"
\\
n"
,
$string
);
$json
=
'{"message_id":961,"from":{"id":123,"first_name":"john","username":"john"},"chat":{"id":123,"title":null,"first_name":"john","last_name":null,"username":"null"},"date":1435920612,"text":"'
.
$string
.
'"}'
;
$json
=
'{"message_id":961,"from":{"id":123,"first_name":"john","username":"john"},"chat":{"id":123,"title":null,"first_name":"john","last_name":null,"username":"null"},"date":1435920612,"text":"'
.
$string
.
'"}'
;
//$json = utf8_encode($json);
//$json = utf8_encode($json);
...
...
tests/Unit/TelegramLogExternalTest.php
0 → 100644
View file @
2296e807
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Tests\Unit
;
use
Longman\TelegramBot\TelegramLog
;
use
Longman\TelegramBot\Exception\TelegramLogException
;
/**
* @package TelegramTest
* @author Avtandil Kikabidze <akalongman@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class
TelegramLogExternalTest
extends
TestCase
{
/**
* setUp
*/
protected
function
setUp
()
{
}
/**
* @test
*/
public
function
testExtenalStream
()
{
$file
=
'/tmp/externallog.log'
;
$this
->
assertFalse
(
file_exists
(
$file
));
$external_monolog
=
new
\Monolog\Logger
(
'bot_update_log'
);
$update_handler
=
new
\Monolog\Handler\StreamHandler
(
$file
,
\Monolog\Logger
::
ERROR
);
$info_handler
=
new
\Monolog\Handler\StreamHandler
(
$file
,
\Monolog\Logger
::
INFO
);
$external_monolog
->
pushHandler
(
$update_handler
);
$external_monolog
->
pushHandler
(
$info_handler
);
TelegramLog
::
initialize
(
$external_monolog
);
TelegramLog
::
error
(
'my error'
);
$this
->
assertTrue
(
file_exists
(
$file
));
unlink
(
$file
);
}
}
tests/Unit/TelegramLogTest.php
View file @
2296e807
...
@@ -11,8 +11,8 @@
...
@@ -11,8 +11,8 @@
namespace
Tests\Unit
;
namespace
Tests\Unit
;
use
Longman\TelegramBot\TelegramLog
;
use
Longman\TelegramBot\TelegramLog
;
use
Longman\TelegramBot\Exception\TelegramLogException
;
use
Longman\TelegramBot\Exception\TelegramLogException
;
/**
/**
* @package TelegramTest
* @package TelegramTest
* @author Avtandil Kikabidze <akalongman@gmail.com>
* @author Avtandil Kikabidze <akalongman@gmail.com>
...
@@ -56,4 +56,43 @@ class TelegramLogTest extends TestCase
...
@@ -56,4 +56,43 @@ class TelegramLogTest extends TestCase
{
{
TelegramLog
::
initUpdateLog
(
''
);
TelegramLog
::
initUpdateLog
(
''
);
}
}
/**
* @test
*/
public
function
testErrorStream
()
{
$file
=
'/tmp/errorlog.log'
;
$this
->
assertFalse
(
file_exists
(
$file
));
TelegramLog
::
initErrorLog
(
$file
);
TelegramLog
::
error
(
'my error'
);
$this
->
assertTrue
(
file_exists
(
$file
));
unlink
(
$file
);
}
/**
* @test
*/
public
function
testDebugStream
()
{
$file
=
'/tmp/debuglog.log'
;
$this
->
assertFalse
(
file_exists
(
$file
));
TelegramLog
::
initDebugLog
(
$file
);
TelegramLog
::
debug
(
'my debug'
);
$this
->
assertTrue
(
file_exists
(
$file
));
unlink
(
$file
);
}
/**
* @test
*/
public
function
testUpdateStream
()
{
$file
=
'/tmp/updatelog.log'
;
$this
->
assertFalse
(
file_exists
(
$file
));
TelegramLog
::
initUpdateLog
(
$file
);
TelegramLog
::
update
(
'my update'
);
$this
->
assertTrue
(
file_exists
(
$file
));
unlink
(
$file
);
}
}
}
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