diff --git a/.gitignore b/.gitignore index 1c6217f..1e13333 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/Bot/Adapter/ModelAdapter.php b/src/Bot/Adapter/ModelAdapter.php index e0b7acf..47826c7 100644 --- a/src/Bot/Adapter/ModelAdapter.php +++ b/src/Bot/Adapter/ModelAdapter.php @@ -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); } /** diff --git a/src/Bot/Client.php b/src/Bot/Client.php index 73f647e..a99c8fd 100644 --- a/src/Bot/Client.php +++ b/src/Bot/Client.php @@ -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); } diff --git a/tests/Bot/Tests/DialogsTest.php b/tests/Bot/Tests/DialogsTest.php index 15fc39e..255169b 100644 --- a/tests/Bot/Tests/DialogsTest.php +++ b/tests/Bot/Tests/DialogsTest.php @@ -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, diff --git a/tests/Bot/Tests/MessagesTest.php b/tests/Bot/Tests/MessagesTest.php index e38d6ff..a0fee60 100644 --- a/tests/Bot/Tests/MessagesTest.php +++ b/tests/Bot/Tests/MessagesTest.php @@ -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'); } /**