Fix failing tests

parent 4e84bce5
......@@ -8,16 +8,20 @@
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
*
* @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
*/
class ServerResponse
......@@ -94,7 +98,47 @@ class ServerResponse
*/
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;
}
/**
......@@ -134,16 +178,15 @@ class ServerResponse
$result['raw_data'] = null;
$result_object_types = [
'total_count' => 'UserProfilePhotos', //Response from getUserProfilePhotos
'file_id' => 'File', //Response from getFile
'title' => 'Chat', //Response from getChat
'username' => 'User', //Response from getMe
'user' => 'ChatMember', //Response from getChatMember
'url' => 'WebhookInfo', //Response from getWebhookInfo
'total_count' => UserProfilePhotos::class, //Response from getUserProfilePhotos
'file_id' => File::class, //Response from getFile
'title' => Chat::class, //Response from getChat
'username' => User::class, //Response from getMe
'user' => ChatMember::class, //Response from getChatMember
'url' => WebhookInfo::class, //Response from getWebhookInfo
];
foreach ($result_object_types as $type => $object_class) {
if (isset($result[$type])) {
$object_class = __NAMESPACE__ . '\\' . $object_class;
return new $object_class($result);
}
......@@ -185,4 +228,5 @@ class ServerResponse
return $results;
}
}
......@@ -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' => '']); // Allow empty string.
new InlineKeyboardButton(['text' => 'message', 'pay' => true]);
$this->assertTrue(true);
}
public function testInlineKeyboardButtonCouldBe()
......
......@@ -44,6 +44,8 @@ class KeyboardButtonTest extends TestCase
new KeyboardButton(['text' => 'message']);
new KeyboardButton(['text' => 'message', 'request_contact' => true]);
new KeyboardButton(['text' => 'message', 'request_location' => true]);
$this->assertTrue(true);
}
public function testInlineKeyboardButtonCouldBe()
......
......@@ -41,7 +41,7 @@ class TelegramTest extends TestCase
// Create a few dummy custom commands paths.
foreach ($this->custom_commands_paths as $custom_path) {
mkdir($custom_path);
@mkdir($custom_path);
}
}
......@@ -49,7 +49,7 @@ class TelegramTest extends TestCase
{
// Clean up the custom commands paths.
foreach ($this->custom_commands_paths as $custom_path) {
rmdir($custom_path);
@rmdir($custom_path);
}
}
......@@ -144,4 +144,11 @@ class TelegramTest extends TestCase
$this->assertInternalType('array', $commands);
$this->assertNotCount(0, $commands);
}
public function testContainer()
{
$telegram = new Telegram(self::$dummy_api_key, 'testbot');
$this->assertInstanceOf(\Illuminate\Container\Container::class, $telegram);
}
}
Markdown is supported
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