1
0
mirror of synced 2024-11-25 13:16:01 +03:00

Merge pull request #4 from Neur0toxine/master

fixes for tests
This commit is contained in:
Alex Lushpai 2019-07-16 15:54:09 +03:00 committed by GitHub
commit 10121a501f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 29 deletions

6
.gitignore vendored
View File

@ -192,8 +192,6 @@ phpDocumentor.phar.pubkey
mg-bot-api-client-php.pages/*
build/*
# Test report
# Test report & coverage
test-report.xml
# GraphViz Dot
dot/*
clover.xml

View File

@ -27,11 +27,6 @@ use RetailCrm\Mg\Bot\Model\Response;
*/
class ModelAdapter
{
/**
* @var mixed $model
*/
private $model;
/**
* @var string $classname
*/
@ -45,7 +40,6 @@ class ModelAdapter
*/
public function __construct(string $classname)
{
$this->model = new $classname;
$this->classname = $classname;
}
@ -58,7 +52,7 @@ class ModelAdapter
*/
public function getResponseModel(Response $response)
{
return Serializer::deserialize($response->getBody(), $this->model);
return Serializer::deserialize($response->getBody(), $this->classname);
}
/**

View File

@ -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\User;
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\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
@ -270,7 +271,7 @@ class Client
$request
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
$adapter = new ModelAdapter(AssignResponse::class);
return $adapter->getResponseModel($response);
}

View File

@ -15,6 +15,7 @@
namespace RetailCrm\Mg\Bot\Tests;
use InvalidArgumentException;
use RetailCrm\Common\Exception\NotFoundException;
use RetailCrm\Mg\Bot\Model\Entity\Responsible;
use RetailCrm\Mg\Bot\Model\Request\DialogAssignRequest;
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
@ -38,6 +39,7 @@ class DialogsTest extends TestCase
*/
public function testDialogAssignError()
{
$this->expectException(\RuntimeException::class);
$client = self::getApiClient(
null,
null,
@ -48,10 +50,7 @@ class DialogsTest extends TestCase
$request = new DialogAssignRequest();
$request->setDialogId(-1);
$response = $client->dialogAssign($request);
self::assertTrue(!$response->isSuccessful());
self::assertNotEmpty($response->getErrors());
$client->dialogAssign($request);
}
/**
@ -85,7 +84,7 @@ class DialogsTest extends TestCase
*/
public function testDialogCloseError()
{
self::expectException(InvalidArgumentException::class);
self::expectException(NotFoundException::class);
$client = self::getApiClient(
null,

View File

@ -36,6 +36,7 @@ class MessagesTest extends TestCase
*/
public function testMessageSendError()
{
$this->expectException(\RuntimeException::class);
$client = self::getApiClient(
null,
null,
@ -51,10 +52,7 @@ class MessagesTest extends TestCase
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
$request->setContent("Hello");
$response = $client->messageSend($request);
self::assertTrue(!$response->isSuccessful());
self::assertEquals(1, count($response->getErrors()));
$client->messageSend($request);
}
/**
@ -91,6 +89,7 @@ class MessagesTest extends TestCase
*/
public function testMessageEditError()
{
$this->expectException(\RuntimeException::class);
$client = self::getApiClient(
null,
null,
@ -105,10 +104,7 @@ class MessagesTest extends TestCase
$request->setId(0);
$request->setContent("Hello");
$response = $client->messageEdit($request);
self::assertTrue(!$response->isSuccessful());
self::assertEquals(1, count($response->getErrors()));
$client->messageEdit($request);
}
/**
@ -140,6 +136,7 @@ class MessagesTest extends TestCase
*/
public function testMessageDeleteError()
{
$this->expectException(\RuntimeException::class);
$client = self::getApiClient(
null,
null,
@ -150,10 +147,7 @@ class MessagesTest extends TestCase
)
);
$response = $client->messageDelete('0');
self::assertTrue(!$response->isSuccessful());
self::assertEquals(1, count($response->getErrors()));
$client->messageDelete('0');
}
/**