Smaller fixes like typos and code presentation inconsistencies.

Add some helper variables to tests, to cut down the amount of code a bit and make it more readable.
parent 68660025
......@@ -27,13 +27,6 @@ class ChatTest extends TestCase
*/
private $chat;
/**
* setUp
*/
protected function setUp()
{
}
public function testChatType()
{
$this->chat = TestHelpers::getFakeChatObject();
......
......@@ -26,13 +26,6 @@ class MessageTest extends TestCase
*/
private $message;
/**
* setUp
*/
protected function setUp()
{
}
public function testTextAndCommandRecognise() {
// /command
$this->message = TestHelpers::getFakeMessageObject(['text' => '/help']);
......
......@@ -39,7 +39,7 @@ class ReplyToMessageTest extends TestCase
"message":{"message_id":4479,"from":{"id":123,"first_name":"John","username":"MJohn"},"chat":{"id":-123,"title":"MyChat","type":"group"},"date":1449092987,"reply_to_message":{"message_id":11,"from":{"id":121,"first_name":"Myname","username":"mybot"},"chat":{"id":-123,"title":"MyChat","type":"group"},"date":1449092984,"text":"type some text"},"text":"some text"}}
';
$struct = json_decode($json, true);
$update = new Update($struct,'mybot');
$update = new Update($struct, 'mybot');
$this->message = $update->getMessage();
$this->reply_to_message = $this->message->getReplyToMessage();
......
......@@ -30,13 +30,6 @@ class ServerResponseTest extends TestCase
*/
private $server;
/**
* setUp
*/
protected function setUp()
{
}
public function sendMessageOk()
{
return '{
......@@ -52,26 +45,25 @@ class ServerResponseTest extends TestCase
}
public function testSendMessageOk() {
$result = $this->sendMessageOk();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server_result = $this->server->getResult();
$this->assertTrue($this->server->isOk());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\Message', $this->server->getResult());
$this->assertNull($this->server->getErrorCode());
$this->assertNull($this->server->getDescription());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result);
//Message
$this->assertEquals('1234', $this->server->getResult()->getMessageId());
$this->assertEquals('123456789', $this->server->getResult()->getFrom()->getId());
$this->assertEquals('botname', $this->server->getResult()->getFrom()->getFirstName());
$this->assertEquals('namebot', $this->server->getResult()->getFrom()->getUserName());
$this->assertEquals('123456789', $this->server->getResult()->getChat()->getId());
$this->assertEquals('john', $this->server->getResult()->getChat()->getFirstName());
$this->assertEquals('Mjohn', $this->server->getResult()->getChat()->getUserName());
$this->assertEquals('1441378360', $this->server->getResult()->getDate());
$this->assertEquals('hello', $this->server->getResult()->getText());
$this->assertEquals('1234', $server_result->getMessageId());
$this->assertEquals('123456789', $server_result->getFrom()->getId());
$this->assertEquals('botname', $server_result->getFrom()->getFirstName());
$this->assertEquals('namebot', $server_result->getFrom()->getUserName());
$this->assertEquals('123456789', $server_result->getChat()->getId());
$this->assertEquals('john', $server_result->getChat()->getFirstName());
$this->assertEquals('Mjohn', $server_result->getChat()->getUserName());
$this->assertEquals('1441378360', $server_result->getDate());
$this->assertEquals('hello', $server_result->getText());
//... they are not finished...
}
......@@ -86,9 +78,7 @@ class ServerResponseTest extends TestCase
}
public function testSendMessageFail() {
$result = $this->sendMessageFail();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertFalse($this->server->isOk());
......@@ -97,15 +87,13 @@ class ServerResponseTest extends TestCase
$this->assertEquals('Error: Bad Request: wrong chat id', $this->server->getDescription());
}
public function setWebHookOk()
public function setWebhookOk()
{
return '{"ok":true,"result":true,"description":"Webhook was set"}';
}
public function testSetWebhookOk() {
$result = $this->setWebhookOk();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertTrue($this->server->isOk());
......@@ -114,7 +102,7 @@ class ServerResponseTest extends TestCase
$this->assertEquals('Webhook was set', $this->server->getDescription());
}
public function setWebHookFail()
public function setWebhookFail()
{
return '{
"ok":false,
......@@ -123,11 +111,8 @@ class ServerResponseTest extends TestCase
}';
}
public function testSetWebhookFail() {
$result = $this->setWebHookFail();
$result = $this->setWebhookFail();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertFalse($this->server->isOk());
......@@ -141,31 +126,38 @@ class ServerResponseTest extends TestCase
return '{
"ok":true,
"result":[
{"update_id":123,
{
"update_id":123,
"message":{
"message_id":90,
"from":{"id":123456789,"first_name":"John","username":"Mjohn"},
"chat":{"id":123456789,"first_name":"John","username":"Mjohn"},
"date":1441569067,
"text":"\/start"}
"text":"\/start"
}
},
{"update_id":124,
{
"update_id":124,
"message":{
"message_id":91,
"from":{"id":123456788,"first_name":"Patrizia","username":"Patry"},
"chat":{"id":123456788,"first_name":"Patrizia","username":"Patry"},
"date":1441569073,
"text":"Hello!"}
"text":"Hello!"
}
},
{"update_id":125,
{
"update_id":125,
"message":{
"message_id":92,
"from":{"id":123456789,"first_name":"John","username":"MJohn"},
"chat":{"id":123456789,"first_name":"John","username":"MJohn"},
"date":1441569094,
"text":"\/echo hello!"}
"text":"\/echo hello!"
}
},
{"update_id":126,
{
"update_id":126,
"message":{
"message_id":93,
"from":{"id":123456788,"first_name":"Patrizia","username":"Patry"},
......@@ -178,13 +170,11 @@ class ServerResponseTest extends TestCase
}';
}
public function testGetUpdatesArray() {
$result = $this->getUpdatesArray();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertCount(4, $this->server->getResult());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\Update', $this->server->getResult()[0]);
}
......@@ -193,10 +183,10 @@ class ServerResponseTest extends TestCase
return '{"ok":true,"result":[]}';
}
public function testGetUpdatesEmpty() {
$result = $this->getUpdatesEmpty();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertNull($this->server->getResult());
}
......@@ -227,18 +217,20 @@ class ServerResponseTest extends TestCase
}';
}
public function testGetUserProfilePhotos()
{
$result = $this->getUserProfilePhotos();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server_result = $this->server->getResult();
$photos = $server_result->getPhotos();
$this->assertCount(3, $this->server->getResult()->getPhotos());
$this->assertCount(3, $this->server->getResult()->getPhotos()[0]);
$this->assertInstanceOf('\Longman\TelegramBot\Entities\UserProfilePhotos', $this->server->getResult());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\PhotoSize', $this->server->getResult()->getPhotos()[0][0]);
//Photo count
$this->assertCount(3, $photos);
//Photo size count
$this->assertCount(3, $photos[0]);
$this->assertInstanceOf('\Longman\TelegramBot\Entities\UserProfilePhotos', $server_result);
$this->assertInstanceOf('\Longman\TelegramBot\Entities\PhotoSize', $photos[0][0]);
}
public function getFile()
......@@ -253,16 +245,12 @@ class ServerResponseTest extends TestCase
}';
}
public function testGetFile()
{
$result = $this->getFile();
//print_r(json_decode($result, true));
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
//var_dump($this->server->getResult()->getPhotos());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\File', $this->server->getResult());
}
public function testSetGeneralTestFakeResponse() {
......@@ -276,29 +264,29 @@ class ServerResponseTest extends TestCase
$this->assertNull($this->server->getErrorCode());
$this->assertEquals('', $this->server->getDescription());
//sendMessage ok
$fake_response = Request::generateGeneralFakeServerResponse(['chat_id' => 123456789, 'text' => 'hello']);
$this->server = new ServerResponse($fake_response, 'testbot');
$server_result = $this->server->getResult();
$this->assertTrue($this->server->isOk());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\Message', $this->server->getResult());
$this->assertNull($this->server->getErrorCode());
$this->assertNull($this->server->getDescription());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result);
//Message
$this->assertEquals('1234', $this->server->getResult()->getMessageId());
$this->assertEquals('1441378360', $this->server->getResult()->getDate());
$this->assertEquals('hello', $this->server->getResult()->getText());
$this->assertEquals('1234', $server_result->getMessageId());
$this->assertEquals('1441378360', $server_result->getDate());
$this->assertEquals('hello', $server_result->getText());
//Message //User
$this->assertEquals('123456789', $this->server->getResult()->getFrom()->getId());
$this->assertEquals('botname', $this->server->getResult()->getFrom()->getFirstName());
$this->assertEquals('namebot', $this->server->getResult()->getFrom()->getUserName());
$this->assertEquals('123456789', $server_result->getFrom()->getId());
$this->assertEquals('botname', $server_result->getFrom()->getFirstName());
$this->assertEquals('namebot', $server_result->getFrom()->getUserName());
//Message //Chat
$this->assertEquals('123456789', $this->server->getResult()->getChat()->getId());
$this->assertEquals('', $this->server->getResult()->getChat()->getFirstName());
$this->assertEquals('', $this->server->getResult()->getChat()->getUserName());
$this->assertEquals('123456789', $server_result->getChat()->getId());
$this->assertEquals('', $server_result->getChat()->getFirstName());
$this->assertEquals('', $server_result->getChat()->getUserName());
//... they are not finished...
}
......
......@@ -35,8 +35,7 @@ class UpdateTest extends TestCase
$struct = json_decode($json, true);
$update = new Update($struct, 'mybot');
$array_string_after = json_decode($update->toJSON(), true);
$array_string_after = json_decode($update->toJson(), true);
$this->assertEquals($struct, $array_string_after);
}
}
......@@ -42,7 +42,7 @@ class TelegramTest extends TestCase
{
$this->telegram = new Telegram('apikey', 'testbot');
// Create a few custom commands paths.
// Create a few dummy custom commands paths.
foreach ($this->custom_commands_paths as $custom_path) {
mkdir($custom_path);
}
......@@ -87,7 +87,7 @@ class TelegramTest extends TestCase
public function testEnableAdmins()
{
$tg = &$this->telegram;
$tg = $this->telegram;
$this->assertEmpty($tg->getAdminList());
......@@ -106,7 +106,7 @@ class TelegramTest extends TestCase
public function testAddCustomCommandsPaths()
{
$tg = &$this->telegram;
$tg = $this->telegram;
$this->assertAttributeCount(1, 'commands_paths', $tg);
......
......@@ -14,7 +14,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
{
protected function skip64BitTest()
{
if (PHP_INT_SIZE == 4) {
if (PHP_INT_SIZE === 4) {
$this->markTestSkipped(
'Skipping test that can run only on a 64-bit build of PHP.'
);
......
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