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
7cfd0b6b
Unverified
Commit
7cfd0b6b
authored
Apr 21, 2018
by
Avtandil Kikabidze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix failing tests
parent
4e84bce5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
19 deletions
+74
-19
ServerResponse.php
src/Http/ServerResponse.php
+61
-17
InlineKeyboardButtonTest.php
tests/unit/Entities/InlineKeyboardButtonTest.php
+2
-0
KeyboardButtonTest.php
tests/unit/Entities/KeyboardButtonTest.php
+2
-0
TelegramTest.php
tests/unit/TelegramTest.php
+9
-2
No files found.
src/Http/ServerResponse.php
View file @
7cfd0b6b
...
@@ -8,16 +8,20 @@
...
@@ -8,16 +8,20 @@
namespace
Longman\TelegramBot\Http
;
namespace
Longman\TelegramBot\Http
;
use
Longman\TelegramBot\Entities\Chat
;
use
Longman\TelegramBot\Entities\ChatMember
;
use
Longman\TelegramBot\Entities\File
;
use
Longman\TelegramBot\Entities\Message
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Entities\User
;
use
Longman\TelegramBot\Entities\UserProfilePhotos
;
use
Longman\TelegramBot\Entities\WebhookInfo
;
/**
/**
* Class ServerResponse
* Class ServerResponse
*
*
* @link https://core.telegram.org/bots/api#making-requests
* @link https://core.telegram.org/bots/api#making-requests
*
*
* @method bool getOk() If the request was successful
* @method mixed getResult() The result of the query
* @method int getErrorCode() Error code of the unsuccessful request
* @method string getDescription() Human-readable description of the result / unsuccessful request
*
* @todo method ResponseParameters getParameters() Field which can help to automatically handle the error
* @todo method ResponseParameters getParameters() Field which can help to automatically handle the error
*/
*/
class
ServerResponse
class
ServerResponse
...
@@ -25,7 +29,7 @@ class ServerResponse
...
@@ -25,7 +29,7 @@ class ServerResponse
/**
/**
* ServerResponse constructor.
* ServerResponse constructor.
*
*
* @param array
$data
* @param array $data
* @param string $bot_username
* @param string $bot_username
*
*
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
...
@@ -36,7 +40,7 @@ class ServerResponse
...
@@ -36,7 +40,7 @@ class ServerResponse
unset
(
$data
[
'raw_data'
]);
unset
(
$data
[
'raw_data'
]);
$data
[
'raw_data'
]
=
$data
;
$data
[
'raw_data'
]
=
$data
;
$is_ok
=
isset
(
$data
[
'ok'
])
?
(
bool
)
$data
[
'ok'
]
:
false
;
$is_ok
=
isset
(
$data
[
'ok'
])
?
(
bool
)
$data
[
'ok'
]
:
false
;
$result
=
isset
(
$data
[
'result'
])
?
$data
[
'result'
]
:
null
;
$result
=
isset
(
$data
[
'result'
])
?
$data
[
'result'
]
:
null
;
if
(
$is_ok
&&
is_array
(
$result
))
{
if
(
$is_ok
&&
is_array
(
$result
))
{
...
@@ -94,7 +98,47 @@ class ServerResponse
...
@@ -94,7 +98,47 @@ class ServerResponse
*/
*/
public
function
isOk
()
public
function
isOk
()
{
{
return
(
bool
)
$this
->
getOk
();
return
$this
->
getOk
();
}
/**
* If response is ok
*
* @return bool
*/
public
function
getOk
()
{
return
isset
(
$this
->
ok
)
?
(
bool
)
$this
->
ok
:
false
;
}
/**
* Return result
*
* @return mixed
*/
public
function
getResult
()
{
return
isset
(
$this
->
result
)
?
$this
->
result
:
null
;
}
/**
* Return error code
*
* @return int
*/
public
function
getErrorCode
()
{
return
isset
(
$this
->
error_code
)
?
$this
->
error_code
:
null
;
}
/**
* Return human-readable description of the result / unsuccessful request
*
* @return string
*/
public
function
getDescription
()
{
return
isset
(
$this
->
description
)
?
$this
->
description
:
null
;
}
}
/**
/**
...
@@ -122,7 +166,7 @@ class ServerResponse
...
@@ -122,7 +166,7 @@ class ServerResponse
/**
/**
* Create and return the object of the received result
* Create and return the object of the received result
*
*
* @param array
$result
* @param array $result
* @param string $bot_username
* @param string $bot_username
*
*
* @return \Longman\TelegramBot\Entities\Chat|\Longman\TelegramBot\Entities\ChatMember|\Longman\TelegramBot\Entities\File|\Longman\TelegramBot\Entities\Message|\Longman\TelegramBot\Entities\User|\Longman\TelegramBot\Entities\UserProfilePhotos|\Longman\TelegramBot\Entities\WebhookInfo
* @return \Longman\TelegramBot\Entities\Chat|\Longman\TelegramBot\Entities\ChatMember|\Longman\TelegramBot\Entities\File|\Longman\TelegramBot\Entities\Message|\Longman\TelegramBot\Entities\User|\Longman\TelegramBot\Entities\UserProfilePhotos|\Longman\TelegramBot\Entities\WebhookInfo
...
@@ -134,16 +178,15 @@ class ServerResponse
...
@@ -134,16 +178,15 @@ class ServerResponse
$result
[
'raw_data'
]
=
null
;
$result
[
'raw_data'
]
=
null
;
$result_object_types
=
[
$result_object_types
=
[
'total_count'
=>
'UserProfilePhotos'
,
//Response from getUserProfilePhotos
'total_count'
=>
UserProfilePhotos
::
class
,
//Response from getUserProfilePhotos
'file_id'
=>
'File'
,
//Response from getFile
'file_id'
=>
File
::
class
,
//Response from getFile
'title'
=>
'Chat'
,
//Response from getChat
'title'
=>
Chat
::
class
,
//Response from getChat
'username'
=>
'User'
,
//Response from getMe
'username'
=>
User
::
class
,
//Response from getMe
'user'
=>
'ChatMember'
,
//Response from getChatMember
'user'
=>
ChatMember
::
class
,
//Response from getChatMember
'url'
=>
'WebhookInfo'
,
//Response from getWebhookInfo
'url'
=>
WebhookInfo
::
class
,
//Response from getWebhookInfo
];
];
foreach
(
$result_object_types
as
$type
=>
$object_class
)
{
foreach
(
$result_object_types
as
$type
=>
$object_class
)
{
if
(
isset
(
$result
[
$type
]))
{
if
(
isset
(
$result
[
$type
]))
{
$object_class
=
__NAMESPACE__
.
'\\'
.
$object_class
;
return
new
$object_class
(
$result
);
return
new
$object_class
(
$result
);
}
}
...
@@ -156,7 +199,7 @@ class ServerResponse
...
@@ -156,7 +199,7 @@ class ServerResponse
/**
/**
* Create and return the objects array of the received result
* Create and return the objects array of the received result
*
*
* @param array
$result
* @param array $result
* @param string $bot_username
* @param string $bot_username
*
*
* @return null|\Longman\TelegramBot\Entities\ChatMember[]|\Longman\TelegramBot\Entities\Update[]
* @return null|\Longman\TelegramBot\Entities\ChatMember[]|\Longman\TelegramBot\Entities\Update[]
...
@@ -185,4 +228,5 @@ class ServerResponse
...
@@ -185,4 +228,5 @@ class ServerResponse
return
$results
;
return
$results
;
}
}
}
}
tests/unit/Entities/InlineKeyboardButtonTest.php
View file @
7cfd0b6b
...
@@ -95,6 +95,8 @@ class InlineKeyboardButtonTest extends TestCase
...
@@ -95,6 +95,8 @@ class InlineKeyboardButtonTest extends TestCase
new
InlineKeyboardButton
([
'text'
=>
'message'
,
'switch_inline_query_current_chat'
=>
'switch_inline_query_current_chat_value'
]);
new
InlineKeyboardButton
([
'text'
=>
'message'
,
'switch_inline_query_current_chat'
=>
'switch_inline_query_current_chat_value'
]);
new
InlineKeyboardButton
([
'text'
=>
'message'
,
'switch_inline_query_current_chat'
=>
''
]);
// Allow empty string.
new
InlineKeyboardButton
([
'text'
=>
'message'
,
'switch_inline_query_current_chat'
=>
''
]);
// Allow empty string.
new
InlineKeyboardButton
([
'text'
=>
'message'
,
'pay'
=>
true
]);
new
InlineKeyboardButton
([
'text'
=>
'message'
,
'pay'
=>
true
]);
$this
->
assertTrue
(
true
);
}
}
public
function
testInlineKeyboardButtonCouldBe
()
public
function
testInlineKeyboardButtonCouldBe
()
...
...
tests/unit/Entities/KeyboardButtonTest.php
View file @
7cfd0b6b
...
@@ -44,6 +44,8 @@ class KeyboardButtonTest extends TestCase
...
@@ -44,6 +44,8 @@ class KeyboardButtonTest extends TestCase
new
KeyboardButton
([
'text'
=>
'message'
]);
new
KeyboardButton
([
'text'
=>
'message'
]);
new
KeyboardButton
([
'text'
=>
'message'
,
'request_contact'
=>
true
]);
new
KeyboardButton
([
'text'
=>
'message'
,
'request_contact'
=>
true
]);
new
KeyboardButton
([
'text'
=>
'message'
,
'request_location'
=>
true
]);
new
KeyboardButton
([
'text'
=>
'message'
,
'request_location'
=>
true
]);
$this
->
assertTrue
(
true
);
}
}
public
function
testInlineKeyboardButtonCouldBe
()
public
function
testInlineKeyboardButtonCouldBe
()
...
...
tests/unit/TelegramTest.php
View file @
7cfd0b6b
...
@@ -41,7 +41,7 @@ class TelegramTest extends TestCase
...
@@ -41,7 +41,7 @@ class TelegramTest extends TestCase
// Create a few dummy custom commands paths.
// Create a few dummy custom commands paths.
foreach
(
$this
->
custom_commands_paths
as
$custom_path
)
{
foreach
(
$this
->
custom_commands_paths
as
$custom_path
)
{
mkdir
(
$custom_path
);
@
mkdir
(
$custom_path
);
}
}
}
}
...
@@ -49,7 +49,7 @@ class TelegramTest extends TestCase
...
@@ -49,7 +49,7 @@ class TelegramTest extends TestCase
{
{
// Clean up the custom commands paths.
// Clean up the custom commands paths.
foreach
(
$this
->
custom_commands_paths
as
$custom_path
)
{
foreach
(
$this
->
custom_commands_paths
as
$custom_path
)
{
rmdir
(
$custom_path
);
@
rmdir
(
$custom_path
);
}
}
}
}
...
@@ -144,4 +144,11 @@ class TelegramTest extends TestCase
...
@@ -144,4 +144,11 @@ class TelegramTest extends TestCase
$this
->
assertInternalType
(
'array'
,
$commands
);
$this
->
assertInternalType
(
'array'
,
$commands
);
$this
->
assertNotCount
(
0
,
$commands
);
$this
->
assertNotCount
(
0
,
$commands
);
}
}
public
function
testContainer
()
{
$telegram
=
new
Telegram
(
self
::
$dummy_api_key
,
'testbot'
);
$this
->
assertInstanceOf
(
\Illuminate\Container\Container
::
class
,
$telegram
);
}
}
}
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