1
0
mirror of synced 2024-11-29 22:36:02 +03:00
mg-bot-api-client-php/tests/Bot/Tests/MessagesTest.php

172 lines
4.1 KiB
PHP
Raw Normal View History

2019-06-10 16:24:22 +03:00
<?php
/**
* PHP version 7.0
*
2019-06-21 11:36:15 +03:00
* Messages Test
2019-06-10 16:24:22 +03:00
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Tests;
use RetailCrm\Mg\Bot\Model\Constants;
2019-06-24 09:11:56 +03:00
use RetailCrm\Mg\Bot\Model\Request\MessageEditRequest;
2019-06-10 16:24:22 +03:00
use RetailCrm\Mg\Bot\Model\Request\MessageSendRequest;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class MessagesTest
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessagesTest extends TestCase
{
/**
* @group("messages")
* @throws \Exception
*/
2019-06-24 09:11:56 +03:00
public function testMessageSendError()
2019-06-10 16:24:22 +03:00
{
2019-07-16 15:20:56 +03:00
$this->expectException(\RuntimeException::class);
2019-06-19 12:49:55 +03:00
$client = self::getApiClient(
null,
null,
false,
2019-06-21 17:51:57 +03:00
$this->getErrorsResponse(
400,
'chat_id is a required field'
2019-06-19 12:49:55 +03:00
)
);
2019-06-10 16:24:22 +03:00
$request = new MessageSendRequest();
$request->setChatId(0);
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
$request->setContent("Hello");
2019-07-16 15:20:56 +03:00
$client->messageSend($request);
2019-06-10 16:24:22 +03:00
}
2019-06-24 09:11:56 +03:00
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageSend()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse(
'{"message_id":3636,"time":"2019-06-24T06:02:04.434291791Z"}',
201
)
);
$request = new MessageSendRequest();
$request->setChatId(28);
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
$request->setContent("Hello");
$response = $client->messageSend($request);
self::assertTrue($response->isSuccessful());
self::assertEquals(0, count($response->getErrors()));
self::assertEquals(3636, $response->getMessageId());
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageEditError()
{
2019-07-16 15:20:56 +03:00
$this->expectException(\RuntimeException::class);
2019-06-24 09:11:56 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getErrorsResponse(
400,
'Incorrect message_id'
)
);
$request = new MessageEditRequest();
$request->setId(0);
$request->setContent("Hello");
2019-07-16 15:20:56 +03:00
$client->messageEdit($request);
2019-06-24 09:11:56 +03:00
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageEdit()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{}', 200)
);
$request = new MessageEditRequest();
$request->setId(3636);
$request->setContent("123");
$response = $client->messageEdit($request);
self::assertTrue($response->isSuccessful());
self::assertEquals(0, count($response->getErrors()));
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageDeleteError()
{
2019-07-16 15:20:56 +03:00
$this->expectException(\RuntimeException::class);
2019-06-24 09:11:56 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getErrorsResponse(
400,
'Incorrect message_id'
)
);
2019-07-16 15:20:56 +03:00
$client->messageDelete('0');
2019-06-24 09:11:56 +03:00
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageDelete()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{}', 200)
);
$response = $client->messageDelete('3636');
self::assertTrue($response->isSuccessful());
self::assertEquals(0, count($response->getErrors()));
}
2019-06-10 16:24:22 +03:00
}