fix serialization annotation
This commit is contained in:
parent
0e2892581b
commit
2ae9de5d54
8 changed files with 124 additions and 57 deletions
|
@ -40,9 +40,9 @@ class Delivery
|
|||
private $name;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $price
|
||||
* @var Cost $price
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
|
||||
* @Type("Cost")
|
||||
* @Accessor(getter="getPrice",setter="setPrice")
|
||||
*
|
||||
* @Assert\Currency
|
||||
|
@ -84,7 +84,7 @@ class Delivery
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
|
||||
* @return Cost
|
||||
*/
|
||||
public function getPrice()
|
||||
{
|
||||
|
@ -92,7 +92,7 @@ class Delivery
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $price
|
||||
* @param Cost $price
|
||||
*/
|
||||
public function setPrice(Cost $price)
|
||||
{
|
||||
|
|
|
@ -34,8 +34,7 @@ class Order
|
|||
*
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getNumber",setter="setNumber")
|
||||
*
|
||||
* @Assert\NotBlank
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $number;
|
||||
|
||||
|
@ -58,27 +57,27 @@ class Order
|
|||
private $date;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $cost
|
||||
* @var Cost $cost
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
|
||||
* @Type("Cost")
|
||||
* @Accessor(getter="getCost",setter="setCost")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $cost;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Status $status
|
||||
* @var Status $status
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Status")
|
||||
* @Type("Status")
|
||||
* @Accessor(getter="getStatus",setter="setStatus")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Delivery $delivery
|
||||
* @var Delivery $delivery
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Delivery")
|
||||
* @Type("Delivery")
|
||||
* @Accessor(getter="getDelivery",setter="setDelivery")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
|
@ -151,7 +150,7 @@ class Order
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
|
||||
* @return Cost
|
||||
*/
|
||||
public function getCost()
|
||||
{
|
||||
|
@ -159,7 +158,7 @@ class Order
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $cost
|
||||
* @param Cost $cost
|
||||
*/
|
||||
public function setCost(Cost $cost)
|
||||
{
|
||||
|
@ -167,7 +166,7 @@ class Order
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Status
|
||||
* @return Status
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
|
@ -175,7 +174,7 @@ class Order
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Status $status
|
||||
* @param Status $status
|
||||
*/
|
||||
public function setStatus(Status $status)
|
||||
{
|
||||
|
@ -183,7 +182,7 @@ class Order
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Delivery
|
||||
* @return Delivery
|
||||
*/
|
||||
public function getDelivery()
|
||||
{
|
||||
|
@ -191,7 +190,7 @@ class Order
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Delivery $delivery
|
||||
* @param Delivery $delivery
|
||||
*/
|
||||
public function setDelivery(Delivery $delivery)
|
||||
{
|
||||
|
|
|
@ -57,18 +57,18 @@ class OrderItem
|
|||
private $img;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $price
|
||||
* @var Cost $price
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
|
||||
* @Type("Cost")
|
||||
* @Accessor(getter="getPrice",setter="setPrice")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $price;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Quantity $quantity
|
||||
* @var Quantity $quantity
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Quantity")
|
||||
* @Type("Quantity")
|
||||
* @Accessor(getter="getQuantity",setter="setQuantity)
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
|
@ -123,7 +123,7 @@ class OrderItem
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
|
||||
* @return Cost
|
||||
*/
|
||||
public function getPrice()
|
||||
{
|
||||
|
@ -131,7 +131,7 @@ class OrderItem
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $price
|
||||
* @param Cost $price
|
||||
*/
|
||||
public function setPrice(Cost $price)
|
||||
{
|
||||
|
@ -139,7 +139,7 @@ class OrderItem
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Quantity
|
||||
* @return Quantity
|
||||
*/
|
||||
public function getQuantity()
|
||||
{
|
||||
|
@ -147,7 +147,7 @@ class OrderItem
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Quantity $quantity
|
||||
* @param Quantity $quantity
|
||||
*/
|
||||
public function setQuantity(Quantity $quantity)
|
||||
{
|
||||
|
|
|
@ -39,18 +39,18 @@ class Payment
|
|||
private $name;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\PaymentStatus $status
|
||||
* @var PaymentStatus $status
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\PaymentStatus")
|
||||
* @Type("PaymentStatus")
|
||||
* @Accessor(getter="getStatus",setter="setStatus")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $amount
|
||||
* @var Cost $amount
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
|
||||
* @Type("Cost")
|
||||
* @Accessor(getter="getAmount",setter="setAmount")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
|
@ -73,7 +73,7 @@ class Payment
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\PaymentStatus
|
||||
* @return PaymentStatus
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ class Payment
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\PaymentStatus $status
|
||||
* @param PaymentStatus $status
|
||||
*/
|
||||
public function setStatus(PaymentStatus $status)
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ class Payment
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
|
||||
* @return Cost
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ class Payment
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $amount
|
||||
* @param Cost $amount
|
||||
*/
|
||||
public function setAmount(Cost $amount)
|
||||
{
|
||||
|
|
|
@ -34,8 +34,7 @@ class Product
|
|||
*
|
||||
* @Type("int")
|
||||
* @Accessor(getter="getId",setter="setId")
|
||||
*
|
||||
* @Assert\NotBlank
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $id;
|
||||
|
||||
|
@ -44,8 +43,7 @@ class Product
|
|||
*
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getName",setter="setName")
|
||||
*
|
||||
* @Assert\NotBlank
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $name;
|
||||
|
||||
|
@ -77,18 +75,18 @@ class Product
|
|||
private $img;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Cost $cost
|
||||
* @var Cost $cost
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Cost")
|
||||
* @Type("Cost")
|
||||
* @Accessor(getter="getCost",setter="setCost")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $cost;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Quantity $quantity
|
||||
* @var Quantity $quantity
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Quantity")
|
||||
* @Type("Quantity")
|
||||
* @Accessor(getter="getQuantity",setter="setQuantity)
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
|
@ -175,7 +173,7 @@ class Product
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Cost
|
||||
* @return Cost
|
||||
*/
|
||||
public function getCost()
|
||||
{
|
||||
|
@ -183,7 +181,7 @@ class Product
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Cost $cost
|
||||
* @param Cost $cost
|
||||
*/
|
||||
public function setCost(Cost $cost)
|
||||
{
|
||||
|
@ -191,7 +189,7 @@ class Product
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Quantity
|
||||
* @return Quantity
|
||||
*/
|
||||
public function getQuantity()
|
||||
{
|
||||
|
@ -199,7 +197,7 @@ class Product
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Quantity $quantity
|
||||
* @param Quantity $quantity
|
||||
*/
|
||||
public function setQuantity(Quantity $quantity)
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace RetailCrm\Mg\Bot\Model\Request;
|
|||
use JMS\Serializer\Annotation\Accessor;
|
||||
use JMS\Serializer\Annotation\SkipWhenEmpty;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Order;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Product;
|
||||
|
||||
|
@ -45,23 +46,24 @@ class MessageSendRequest
|
|||
*
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getContent",setter="setContent")
|
||||
* @SkipWhenEmpty()
|
||||
*
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Product $product
|
||||
* @var Product $product
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Product")
|
||||
* @Type("Product")
|
||||
* @Accessor(getter="getProduct",setter="setProduct")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $product;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Mg\Bot\Model\Entity\Order $order
|
||||
* @var Order $order
|
||||
*
|
||||
* @Type("\RetailCrm\Mg\Bot\Model\Entity\Order")
|
||||
* @Type("Order")
|
||||
* @Accessor(getter="getOrder",setter="setOrder")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
|
@ -81,7 +83,8 @@ class MessageSendRequest
|
|||
*
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getScope",setter="setScope")
|
||||
* @SkipWhenEmpty()
|
||||
*
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
private $scope;
|
||||
|
||||
|
@ -90,7 +93,8 @@ class MessageSendRequest
|
|||
*
|
||||
* @Type("int")
|
||||
* @Accessor(getter="getChatId",setter="setChatId")
|
||||
* @SkipWhenEmpty
|
||||
*
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
private $chatId;
|
||||
|
||||
|
@ -170,7 +174,7 @@ class MessageSendRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Product
|
||||
* @return Product
|
||||
*/
|
||||
public function getProduct()
|
||||
{
|
||||
|
@ -178,7 +182,7 @@ class MessageSendRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Product $product
|
||||
* @param Product $product
|
||||
*/
|
||||
public function setProduct(Product $product)
|
||||
{
|
||||
|
@ -186,7 +190,7 @@ class MessageSendRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \RetailCrm\Mg\Bot\Model\Entity\Order
|
||||
* @return Order
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
|
@ -194,7 +198,7 @@ class MessageSendRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RetailCrm\Mg\Bot\Model\Entity\Order $order
|
||||
* @param Order $order
|
||||
*/
|
||||
public function setOrder(Order $order)
|
||||
{
|
||||
|
|
|
@ -126,6 +126,7 @@ class Request
|
|||
|
||||
$response = Response::parseJSON($responseBody);
|
||||
$errorMessage = !empty($response['errorMsg']) ? $response['errorMsg'] : '';
|
||||
$errorMessage = !empty($response['errors']) ? $this->getErrors($response['errors']) : $errorMessage;
|
||||
|
||||
/**
|
||||
* responses with 400 & 460 http codes contains extended error data
|
||||
|
@ -190,4 +191,15 @@ class Request
|
|||
throw new InvalidArgumentException($message);
|
||||
}
|
||||
}
|
||||
|
||||
private function getErrors(array $errors)
|
||||
{
|
||||
$errorString = '';
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$errorString .= $error . " ";
|
||||
}
|
||||
|
||||
return $errorString;
|
||||
}
|
||||
}
|
||||
|
|
54
tests/Bot/Tests/MessagesTest.php
Normal file
54
tests/Bot/Tests/MessagesTest.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.0
|
||||
*
|
||||
* Client Test
|
||||
*
|
||||
* @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 Exception;
|
||||
use InvalidArgumentException;
|
||||
use RetailCrm\Common\Exception\CurlException;
|
||||
use RetailCrm\Common\Exception\InvalidJsonException;
|
||||
use RetailCrm\Mg\Bot\Model\Constants;
|
||||
use RetailCrm\Mg\Bot\Model\Request\CommandEditRequest;
|
||||
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
|
||||
*/
|
||||
public function testMessageSend()
|
||||
{
|
||||
$client = self::getApiClient();
|
||||
|
||||
$request = new MessageSendRequest();
|
||||
$request->setChatId(0);
|
||||
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
|
||||
$request->setContent("Hello");
|
||||
|
||||
$request = $client->messageSend($request);
|
||||
|
||||
self::assertEquals($request->getStatusCode(), 400);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue