Clean up Entity tests.

parent b1cc1f06
......@@ -90,7 +90,7 @@ class InlineKeyboardTest extends TestCase
{
$keyboard = (new InlineKeyboard([
$this->getRandomButton('Button Text 1'),
$this->getRandomButton('Button Text 2')
$this->getRandomButton('Button Text 2'),
]))->getProperty('inline_keyboard');
self::assertSame('Button Text 1', $keyboard[0][0]->getText());
self::assertSame('Button Text 2', $keyboard[0][1]->getText());
......@@ -101,11 +101,11 @@ class InlineKeyboardTest extends TestCase
$keyboard = (new InlineKeyboard(
[
$this->getRandomButton('Button Text 1'),
$this->getRandomButton('Button Text 2')
$this->getRandomButton('Button Text 2'),
],
[
$this->getRandomButton('Button Text 3'),
$this->getRandomButton('Button Text 4')
$this->getRandomButton('Button Text 4'),
]
))->getProperty('inline_keyboard');
......
......@@ -12,7 +12,6 @@ namespace Longman\TelegramBot\Tests\Unit;
use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Entities\KeyboardButton;
use Longman\TelegramBot\Exception\TelegramException;
/**
* @package TelegramTest
......
......@@ -10,7 +10,7 @@
namespace Longman\TelegramBot\Tests\Unit;
use \Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\Update;
/**
* @package TelegramTest
......@@ -21,29 +21,16 @@ use \Longman\TelegramBot\Entities\Update;
*/
class ReplyToMessageTest extends TestCase
{
/**
* @var \Longman\TelegramBot\Entities\Message
*/
private $reply_to_message;
/**
* @var \Longman\TelegramBot\Entities\Message
*/
private $message;
public function testChatType()
{
$json = '
{"update_id":137809335,
"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');
$this->message = $update->getMessage();
$this->reply_to_message = $this->message->getReplyToMessage();
$this->assertNull($this->reply_to_message->getReplyToMessage());
$update = new Update(json_decode($json, true), 'mybot');
$reply_to_message = $update->getMessage()->getReplyToMessage();
self::assertNull($reply_to_message->getReplyToMessage());
}
}
......@@ -13,8 +13,8 @@
namespace Longman\TelegramBot\Tests\Unit;
use Longman\TelegramBot\Entities\Message;
use \Longman\TelegramBot\Entities\ServerResponse;
use \Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Request;
/**
* @package TelegramTest
......@@ -25,11 +25,6 @@ use \Longman\TelegramBot\Request;
*/
class ServerResponseTest extends TestCase
{
/**
* @var \Longman\TelegramBot\Entities\ServerResponse
*/
private $server;
public function sendMessageOk()
{
return '{
......@@ -44,26 +39,27 @@ class ServerResponseTest extends TestCase
}';
}
public function testSendMessageOk() {
public function testSendMessageOk()
{
$result = $this->sendMessageOk();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server_result = $this->server->getResult();
$server = new ServerResponse(json_decode($result, true), 'testbot');
$server_result = $server->getResult();
$this->assertTrue($this->server->isOk());
$this->assertNull($this->server->getErrorCode());
$this->assertNull($this->server->getDescription());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result);
self::assertTrue($server->isOk());
self::assertNull($server->getErrorCode());
self::assertNull($server->getDescription());
self::assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result);
//Message
$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());
self::assertEquals('1234', $server_result->getMessageId());
self::assertEquals('123456789', $server_result->getFrom()->getId());
self::assertEquals('botname', $server_result->getFrom()->getFirstName());
self::assertEquals('namebot', $server_result->getFrom()->getUsername());
self::assertEquals('123456789', $server_result->getChat()->getId());
self::assertEquals('john', $server_result->getChat()->getFirstName());
self::assertEquals('Mjohn', $server_result->getChat()->getUsername());
self::assertEquals('1441378360', $server_result->getDate());
self::assertEquals('hello', $server_result->getText());
//... they are not finished...
}
......@@ -77,14 +73,15 @@ class ServerResponseTest extends TestCase
}';
}
public function testSendMessageFail() {
public function testSendMessageFail()
{
$result = $this->sendMessageFail();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertFalse($this->server->isOk());
$this->assertNull($this->server->getResult());
$this->assertEquals('400', $this->server->getErrorCode());
$this->assertEquals('Error: Bad Request: wrong chat id', $this->server->getDescription());
self::assertFalse($server->isOk());
self::assertNull($server->getResult());
self::assertEquals('400', $server->getErrorCode());
self::assertEquals('Error: Bad Request: wrong chat id', $server->getDescription());
}
public function setWebhookOk()
......@@ -92,14 +89,15 @@ class ServerResponseTest extends TestCase
return '{"ok":true,"result":true,"description":"Webhook was set"}';
}
public function testSetWebhookOk() {
public function testSetWebhookOk()
{
$result = $this->setWebhookOk();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertTrue($this->server->isOk());
$this->assertTrue($this->server->getResult());
$this->assertNull($this->server->getErrorCode());
$this->assertEquals('Webhook was set', $this->server->getDescription());
self::assertTrue($server->isOk());
self::assertTrue($server->getResult());
self::assertNull($server->getErrorCode());
self::assertEquals('Webhook was set', $server->getDescription());
}
public function setWebhookFail()
......@@ -111,14 +109,15 @@ class ServerResponseTest extends TestCase
}';
}
public function testSetWebhookFail() {
public function testSetWebhookFail()
{
$result = $this->setWebhookFail();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertFalse($this->server->isOk());
$this->assertNull($this->server->getResult());
$this->assertEquals(400, $this->server->getErrorCode());
$this->assertEquals("Error: Bad request: htttps://domain.host.org/dir/hook.php", $this->server->getDescription());
self::assertFalse($server->isOk());
self::assertNull($server->getResult());
self::assertEquals(400, $server->getErrorCode());
self::assertEquals('Error: Bad request: htttps://domain.host.org/dir/hook.php', $server->getDescription());
}
public function getUpdatesArray()
......@@ -170,12 +169,13 @@ class ServerResponseTest extends TestCase
}';
}
public function testGetUpdatesArray() {
public function testGetUpdatesArray()
{
$result = $this->getUpdatesArray();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertCount(4, $this->server->getResult());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\Update', $this->server->getResult()[0]);
self::assertCount(4, $server->getResult());
self::assertInstanceOf('\Longman\TelegramBot\Entities\Update', $server->getResult()[0]);
}
public function getUpdatesEmpty()
......@@ -183,11 +183,12 @@ class ServerResponseTest extends TestCase
return '{"ok":true,"result":[]}';
}
public function testGetUpdatesEmpty() {
public function testGetUpdatesEmpty()
{
$result = $this->getUpdatesEmpty();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertEmpty($this->server->getResult());
self::assertEmpty($server->getResult());
}
public function getUserProfilePhotos()
......@@ -220,19 +221,19 @@ class ServerResponseTest extends TestCase
public function testGetUserProfilePhotos()
{
$result = $this->getUserProfilePhotos();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server_result = $this->server->getResult();
$server = new ServerResponse(json_decode($result, true), 'testbot');
$server_result = $server->getResult();
$photos = $server_result->getPhotos();
//Photo count
$this->assertEquals(3, $server_result->getTotalCount());
$this->assertCount(3, $photos);
self::assertEquals(3, $server_result->getTotalCount());
self::assertCount(3, $photos);
//Photo size count
$this->assertCount(3, $photos[0]);
self::assertCount(3, $photos[0]);
$this->assertInstanceOf('\Longman\TelegramBot\Entities\UserProfilePhotos', $server_result);
$this->assertInstanceOf('\Longman\TelegramBot\Entities\PhotoSize', $photos[0][0]);
self::assertInstanceOf('\Longman\TelegramBot\Entities\UserProfilePhotos', $server_result);
self::assertInstanceOf('\Longman\TelegramBot\Entities\PhotoSize', $photos[0][0]);
}
public function getFile()
......@@ -250,9 +251,9 @@ class ServerResponseTest extends TestCase
public function testGetFile()
{
$result = $this->getFile();
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
$server = new ServerResponse(json_decode($result, true), 'testbot');
$this->assertInstanceOf('\Longman\TelegramBot\Entities\File', $this->server->getResult());
self::assertInstanceOf('\Longman\TelegramBot\Entities\File', $server->getResult());
}
public function testSetGeneralTestFakeResponse()
......@@ -260,40 +261,40 @@ class ServerResponseTest extends TestCase
//setWebhook ok
$fake_response = Request::generateGeneralFakeServerResponse();
$this->server = new ServerResponse($fake_response, 'testbot');
$server = new ServerResponse($fake_response, 'testbot');
$this->assertTrue($this->server->isOk());
$this->assertTrue($this->server->getResult());
$this->assertNull($this->server->getErrorCode());
$this->assertEquals('', $this->server->getDescription());
self::assertTrue($server->isOk());
self::assertTrue($server->getResult());
self::assertNull($server->getErrorCode());
self::assertEquals('', $server->getDescription());
//sendMessage ok
$fake_response = Request::generateGeneralFakeServerResponse(['chat_id' => 123456789, 'text' => 'hello']);
$this->server = new ServerResponse($fake_response, 'testbot');
$server = new ServerResponse($fake_response, 'testbot');
/** @var Message $server_result */
$server_result = $this->server->getResult();
$server_result = $server->getResult();
$this->assertTrue($this->server->isOk());
$this->assertNull($this->server->getErrorCode());
$this->assertNull($this->server->getDescription());
$this->assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result);
self::assertTrue($server->isOk());
self::assertNull($server->getErrorCode());
self::assertNull($server->getDescription());
self::assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result);
//Message
$this->assertEquals('1234', $server_result->getMessageId());
$this->assertEquals('1441378360', $server_result->getDate());
$this->assertEquals('hello', $server_result->getText());
self::assertEquals('1234', $server_result->getMessageId());
self::assertEquals('1441378360', $server_result->getDate());
self::assertEquals('hello', $server_result->getText());
//Message //User
$this->assertEquals('123456789', $server_result->getFrom()->getId());
$this->assertEquals('botname', $server_result->getFrom()->getFirstName());
$this->assertEquals('namebot', $server_result->getFrom()->getUsername());
self::assertEquals('123456789', $server_result->getFrom()->getId());
self::assertEquals('botname', $server_result->getFrom()->getFirstName());
self::assertEquals('namebot', $server_result->getFrom()->getUsername());
//Message //Chat
$this->assertEquals('123456789', $server_result->getChat()->getId());
$this->assertEquals('', $server_result->getChat()->getFirstName());
$this->assertEquals('', $server_result->getChat()->getUsername());
self::assertEquals('123456789', $server_result->getChat()->getId());
self::assertEquals('', $server_result->getChat()->getFirstName());
self::assertEquals('', $server_result->getChat()->getUsername());
//... they are not finished...
}
......
......@@ -10,7 +10,7 @@
namespace Longman\TelegramBot\Tests\Unit;
use \Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\Update;
/**
* @package TelegramTest
......@@ -31,6 +31,6 @@ class UpdateTest extends TestCase
$update = new Update($struct, 'mybot');
$array_string_after = json_decode($update->toJson(), true);
$this->assertEquals($struct, $array_string_after);
self::assertEquals($struct, $array_string_after);
}
}
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