Clean up Entity tests.

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