commit
10121a501f
6
.gitignore
vendored
6
.gitignore
vendored
@ -192,8 +192,6 @@ phpDocumentor.phar.pubkey
|
|||||||
mg-bot-api-client-php.pages/*
|
mg-bot-api-client-php.pages/*
|
||||||
build/*
|
build/*
|
||||||
|
|
||||||
# Test report
|
# Test report & coverage
|
||||||
test-report.xml
|
test-report.xml
|
||||||
|
clover.xml
|
||||||
# GraphViz Dot
|
|
||||||
dot/*
|
|
||||||
|
@ -27,11 +27,6 @@ use RetailCrm\Mg\Bot\Model\Response;
|
|||||||
*/
|
*/
|
||||||
class ModelAdapter
|
class ModelAdapter
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var mixed $model
|
|
||||||
*/
|
|
||||||
private $model;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $classname
|
* @var string $classname
|
||||||
*/
|
*/
|
||||||
@ -45,7 +40,6 @@ class ModelAdapter
|
|||||||
*/
|
*/
|
||||||
public function __construct(string $classname)
|
public function __construct(string $classname)
|
||||||
{
|
{
|
||||||
$this->model = new $classname;
|
|
||||||
$this->classname = $classname;
|
$this->classname = $classname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +52,7 @@ class ModelAdapter
|
|||||||
*/
|
*/
|
||||||
public function getResponseModel(Response $response)
|
public function getResponseModel(Response $response)
|
||||||
{
|
{
|
||||||
return Serializer::deserialize($response->getBody(), $this->model);
|
return Serializer::deserialize($response->getBody(), $this->classname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Dialog;
|
|||||||
use RetailCrm\Mg\Bot\Model\Entity\Message\Message;
|
use RetailCrm\Mg\Bot\Model\Entity\Message\Message;
|
||||||
use RetailCrm\Mg\Bot\Model\Entity\User;
|
use RetailCrm\Mg\Bot\Model\Entity\User;
|
||||||
use RetailCrm\Mg\Bot\Model\Request\UploadFileByUrlRequest;
|
use RetailCrm\Mg\Bot\Model\Request\UploadFileByUrlRequest;
|
||||||
|
use RetailCrm\Mg\Bot\Model\Response\AssignResponse;
|
||||||
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
|
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
|
||||||
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
|
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
|
||||||
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
|
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
|
||||||
@ -270,7 +271,7 @@ class Client
|
|||||||
$request
|
$request
|
||||||
);
|
);
|
||||||
|
|
||||||
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
|
$adapter = new ModelAdapter(AssignResponse::class);
|
||||||
|
|
||||||
return $adapter->getResponseModel($response);
|
return $adapter->getResponseModel($response);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
namespace RetailCrm\Mg\Bot\Tests;
|
namespace RetailCrm\Mg\Bot\Tests;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use RetailCrm\Common\Exception\NotFoundException;
|
||||||
use RetailCrm\Mg\Bot\Model\Entity\Responsible;
|
use RetailCrm\Mg\Bot\Model\Entity\Responsible;
|
||||||
use RetailCrm\Mg\Bot\Model\Request\DialogAssignRequest;
|
use RetailCrm\Mg\Bot\Model\Request\DialogAssignRequest;
|
||||||
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
|
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
|
||||||
@ -38,6 +39,7 @@ class DialogsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDialogAssignError()
|
public function testDialogAssignError()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
$client = self::getApiClient(
|
$client = self::getApiClient(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -48,10 +50,7 @@ class DialogsTest extends TestCase
|
|||||||
$request = new DialogAssignRequest();
|
$request = new DialogAssignRequest();
|
||||||
$request->setDialogId(-1);
|
$request->setDialogId(-1);
|
||||||
|
|
||||||
$response = $client->dialogAssign($request);
|
$client->dialogAssign($request);
|
||||||
|
|
||||||
self::assertTrue(!$response->isSuccessful());
|
|
||||||
self::assertNotEmpty($response->getErrors());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,7 +84,7 @@ class DialogsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDialogCloseError()
|
public function testDialogCloseError()
|
||||||
{
|
{
|
||||||
self::expectException(InvalidArgumentException::class);
|
self::expectException(NotFoundException::class);
|
||||||
|
|
||||||
$client = self::getApiClient(
|
$client = self::getApiClient(
|
||||||
null,
|
null,
|
||||||
|
@ -36,6 +36,7 @@ class MessagesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMessageSendError()
|
public function testMessageSendError()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
$client = self::getApiClient(
|
$client = self::getApiClient(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -51,10 +52,7 @@ class MessagesTest extends TestCase
|
|||||||
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
|
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
|
||||||
$request->setContent("Hello");
|
$request->setContent("Hello");
|
||||||
|
|
||||||
$response = $client->messageSend($request);
|
$client->messageSend($request);
|
||||||
|
|
||||||
self::assertTrue(!$response->isSuccessful());
|
|
||||||
self::assertEquals(1, count($response->getErrors()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,6 +89,7 @@ class MessagesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMessageEditError()
|
public function testMessageEditError()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
$client = self::getApiClient(
|
$client = self::getApiClient(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -105,10 +104,7 @@ class MessagesTest extends TestCase
|
|||||||
$request->setId(0);
|
$request->setId(0);
|
||||||
$request->setContent("Hello");
|
$request->setContent("Hello");
|
||||||
|
|
||||||
$response = $client->messageEdit($request);
|
$client->messageEdit($request);
|
||||||
|
|
||||||
self::assertTrue(!$response->isSuccessful());
|
|
||||||
self::assertEquals(1, count($response->getErrors()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,6 +136,7 @@ class MessagesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMessageDeleteError()
|
public function testMessageDeleteError()
|
||||||
{
|
{
|
||||||
|
$this->expectException(\RuntimeException::class);
|
||||||
$client = self::getApiClient(
|
$client = self::getApiClient(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -150,10 +147,7 @@ class MessagesTest extends TestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $client->messageDelete('0');
|
$client->messageDelete('0');
|
||||||
|
|
||||||
self::assertTrue(!$response->isSuccessful());
|
|
||||||
self::assertEquals(1, count($response->getErrors()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user