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