1
0
mirror of synced 2024-11-22 03:46:02 +03:00

File operations, code cleanup, tests

This commit is contained in:
Pavel 2019-06-21 16:42:04 +03:00
parent 3a3bf0eda7
commit 004b27f62c
28 changed files with 844 additions and 455 deletions

View File

@ -12,4 +12,4 @@ before_script:
- flags="-o" - flags="-o"
- composer install $flags - composer install $flags
script: make test script: make travis

View File

@ -22,3 +22,6 @@ stan:
@echo "==> Running analysis" @echo "==> Running analysis"
@php $(BIN_DIR)/phpstan analyse -l 4 -c $(ROOT_DIR)/phpstan.neon $(SRC_DIR) @php $(BIN_DIR)/phpstan analyse -l 4 -c $(ROOT_DIR)/phpstan.neon $(SRC_DIR)
@echo "==> Analysis complete" @echo "==> Analysis complete"
travis: test stan
@echo "==> Completed"

View File

@ -22,7 +22,7 @@
"guzzlehttp/guzzle": "6.3.*" "guzzlehttp/guzzle": "6.3.*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "6.5.*", "phpunit/phpunit": "7.4.*",
"phpmd/phpmd": "2.6.*", "phpmd/phpmd": "2.6.*",
"phpstan/phpstan": "0.9.*", "phpstan/phpstan": "0.9.*",
"squizlabs/php_codesniffer": "3.4.*", "squizlabs/php_codesniffer": "3.4.*",

874
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,10 @@ namespace RetailCrm\Mg\Bot;
use RetailCrm\Common\Exception\InvalidJsonException; use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Url; use RetailCrm\Common\Url;
use RetailCrm\Common\Serializer; use RetailCrm\Common\Serializer;
use RetailCrm\Mg\Bot\Model\Response\AssignResponse; use RetailCrm\Mg\Bot\Model\Request\GetFileRequest;
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse; use RetailCrm\Mg\Bot\Model\Request\UploadFileByUrlRequest;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\ListResponse; use RetailCrm\Mg\Bot\Model\Response\ListResponse;
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
/** /**
* PHP version 7.0 * PHP version 7.0
@ -67,13 +67,13 @@ class Client
* @param string $method * @param string $method
* @param object $request Request parameters * @param object $request Request parameters
* @param string $responseType * @param string $responseType
* @param int $serializeTo * @param string $serializeTo
* @param bool $arrayOfObjects * @param bool $arrayOfObjects
* *
* @return object * @return object|null
* @throws \Exception * @throws \Exception
*/ */
private function getData( private function submitRequest(
$path, $path,
$method, $method,
$request, $request,
@ -158,7 +158,7 @@ class Client
*/ */
public function bots(Model\Request\BotsRequest $request) public function bots(Model\Request\BotsRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/bots', '/bots',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -178,7 +178,7 @@ class Client
*/ */
public function info(Model\Request\InfoRequest $request) public function info(Model\Request\InfoRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/my/info', '/my/info',
HttpClient::METHOD_PATCH, HttpClient::METHOD_PATCH,
$request, $request,
@ -196,7 +196,7 @@ class Client
*/ */
public function channels(Model\Request\ChannelsRequest $request) public function channels(Model\Request\ChannelsRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/channels', '/channels',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -216,7 +216,7 @@ class Client
*/ */
public function chats(Model\Request\ChatsRequest $request) public function chats(Model\Request\ChatsRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/chats', '/chats',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -236,7 +236,7 @@ class Client
*/ */
public function commands(Model\Request\CommandsRequest $request) public function commands(Model\Request\CommandsRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/my/commands', '/my/commands',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -256,7 +256,7 @@ class Client
*/ */
public function commandEdit(Model\Request\CommandEditRequest $request) public function commandEdit(Model\Request\CommandEditRequest $request)
{ {
return $this->getData( return $this->submitRequest(
sprintf("/my/commands/%s", $request->getName()), sprintf("/my/commands/%s", $request->getName()),
HttpClient::METHOD_PUT, HttpClient::METHOD_PUT,
$request, $request,
@ -275,7 +275,7 @@ class Client
*/ */
public function commandDelete(string $request) public function commandDelete(string $request)
{ {
return $this->getData( return $this->submitRequest(
sprintf("/my/commands/%s", $request), sprintf("/my/commands/%s", $request),
HttpClient::METHOD_DELETE, HttpClient::METHOD_DELETE,
null, null,
@ -294,7 +294,7 @@ class Client
*/ */
public function customers(Model\Request\CustomersRequest $request) public function customers(Model\Request\CustomersRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/customers', '/customers',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -314,7 +314,7 @@ class Client
*/ */
public function dialogs(Model\Request\DialogsRequest $request) public function dialogs(Model\Request\DialogsRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/dialogs', '/dialogs',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -334,7 +334,7 @@ class Client
*/ */
public function dialogAssign(Model\Request\DialogAssignRequest $request) public function dialogAssign(Model\Request\DialogAssignRequest $request)
{ {
return $this->getData( return $this->submitRequest(
sprintf("/dialogs/%d/assign", $request->getDialogId()), sprintf("/dialogs/%d/assign", $request->getDialogId()),
HttpClient::METHOD_PATCH, HttpClient::METHOD_PATCH,
$request, $request,
@ -353,7 +353,7 @@ class Client
*/ */
public function dialogClose(string $request) public function dialogClose(string $request)
{ {
return $this->getData( return $this->submitRequest(
sprintf("/dialogs/%d/close", $request), sprintf("/dialogs/%d/close", $request),
HttpClient::METHOD_DELETE, HttpClient::METHOD_DELETE,
null, null,
@ -371,7 +371,7 @@ class Client
*/ */
public function members(Model\Request\MembersRequest $request) public function members(Model\Request\MembersRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/members', '/members',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -391,7 +391,7 @@ class Client
*/ */
public function messages(Model\Request\MessagesRequest $request) public function messages(Model\Request\MessagesRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/messages', '/messages',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -411,7 +411,7 @@ class Client
*/ */
public function messageSend(Model\Request\MessageSendRequest $request) public function messageSend(Model\Request\MessageSendRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/messages', '/messages',
HttpClient::METHOD_POST, HttpClient::METHOD_POST,
$request, $request,
@ -429,7 +429,7 @@ class Client
*/ */
public function messageEdit(Model\Request\MessageEditRequest $request) public function messageEdit(Model\Request\MessageEditRequest $request)
{ {
return $this->getData( return $this->submitRequest(
sprintf("/messages/%d", $request->getId()), sprintf("/messages/%d", $request->getId()),
HttpClient::METHOD_PATCH, HttpClient::METHOD_PATCH,
$request, $request,
@ -447,7 +447,7 @@ class Client
*/ */
public function messageDelete(string $request) public function messageDelete(string $request)
{ {
return $this->getData( return $this->submitRequest(
sprintf("/messages/%d", $request), sprintf("/messages/%d", $request),
HttpClient::METHOD_DELETE, HttpClient::METHOD_DELETE,
null, null,
@ -465,7 +465,7 @@ class Client
*/ */
public function users(Model\Request\UsersRequest $request) public function users(Model\Request\UsersRequest $request)
{ {
return $this->getData( return $this->submitRequest(
'/users', '/users',
HttpClient::METHOD_GET, HttpClient::METHOD_GET,
$request, $request,
@ -474,4 +474,54 @@ class Client
true true
); );
} }
/**
* Returns filtered users list
*
* @param string $url File URL
*
* @return \RetailCrm\Mg\Bot\Model\Response\UploadFileResponse|object
* @throws \Exception
*/
public function uploadFileByUrl(string $url)
{
$request = new UploadFileByUrlRequest();
$request->setUrl($url);
return $this->submitRequest(
'/files/upload_by_url',
HttpClient::METHOD_POST,
$request,
self::getResponseClass('UploadFileResponse')
);
}
/**
* @param string $filename
* @return Model\Response\UploadFileResponse
*
* @throws \Exception
*/
public function uploadFile(string $filename)
{
return $this->client->uploadFileViaForm($filename);
}
/**
* @param string $fileId
* @return Model\Response\FullFileResponse|null
*
* @throws \Exception
*/
public function getFileById(string $fileId)
{
$obj = $this->submitRequest(
\sprintf('/files/%s', $fileId),
HttpClient::METHOD_GET,
null,
self::getResponseClass('FullFileResponse')
);
return ($obj instanceof FullFileResponse) ? $obj : null;
}
} }

View File

@ -18,9 +18,9 @@ use RetailCrm\Common\Exception\LimitException;
use InvalidArgumentException; use InvalidArgumentException;
use RetailCrm\Common\Serializer; use RetailCrm\Common\Serializer;
use RetailCrm\Common\Url; use RetailCrm\Common\Url;
use RetailCrm\Mg\Bot\Model\Response\UploadFileResponse;
use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Validation;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@ -107,7 +107,7 @@ class HttpClient
* @param string $path Request URL * @param string $path Request URL
* @param string $method Request method (default: 'GET') * @param string $method Request method (default: 'GET')
* @param mixed $request Request model (default: null) * @param mixed $request Request model (default: null)
* @param int $serializeTo Serializer::S_JSON or Serializer::S_ARRAY * @param string $serializeTo Serializer::S_JSON or Serializer::S_ARRAY
* *
* @return ResponseInterface * @return ResponseInterface
* @throws \Exception * @throws \Exception
@ -122,7 +122,7 @@ class HttpClient
$this->validateRequest($request); $this->validateRequest($request);
} }
if ($method == self::METHOD_GET) { if ($method == self::METHOD_GET && !is_null($request)) {
$getParameters = Url::buildGetParameters(Serializer::serialize($request, Serializer::S_ARRAY)); $getParameters = Url::buildGetParameters(Serializer::serialize($request, Serializer::S_ARRAY));
} }
@ -176,6 +176,47 @@ class HttpClient
return $responseObject; return $responseObject;
} }
/**
* @param string $filename
* @return UploadFileResponse
*
* @throws \Exception
*/
public function uploadFileViaForm(string $filename): UploadFileResponse
{
if (!file_exists($filename)) {
throw new \InvalidArgumentException("File doesn't exist");
}
try {
$responseData = $this->client->request(
self::METHOD_POST,
\sprintf("%s/files/upload", $this->basePath),
[
'headers' => [
'X-Bot-Token' => $this->token
],
'multipart' => [
[
'name' => basename($filename),
'filename' => basename($filename),
'contents' => fopen($filename, 'r')
]
]
]
);
} catch (GuzzleException $exception) {
throw new \Exception($exception->getMessage(), $exception->getCode(), $exception);
}
$obj = Serializer::deserialize(
(string) $responseData->getBody(),
'RetailCrm\Mg\Bot\Model\Response\UploadFileResponse'
);
return $obj instanceof UploadFileResponse ? $obj : null;
}
/** /**
* Validate HTTP method * Validate HTTP method
* *

View File

@ -16,9 +16,6 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor; use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty; use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type; use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Cost;
use RetailCrm\Mg\Bot\Model\Entity\Delivery;
use RetailCrm\Mg\Bot\Model\Entity\Status;
/** /**
* PHP version 7.0 * PHP version 7.0
@ -32,16 +29,6 @@ use RetailCrm\Mg\Bot\Model\Entity\Status;
*/ */
class MessageOrder class MessageOrder
{ {
// const JSON_PROPERTY_MAP = [
// 'cost' => 'MessageCost',
// 'date' => 'string',
// 'delivery' => 'MessageDelivery',
// 'items' => 'MessageOrderItem[]',
// 'number' => 'string',
// 'payments' => 'MessagePayment[]',
// 'status' => 'MessageStatus'
// ];
/** /**
* @var string $number * @var string $number
* *

View File

@ -1,14 +1,14 @@
<?php <?php
/** /**
* PHP version 7.0 * PHP version 7.0.
* *
* MessageOrderItem entity * MessageOrderItem entity
* *
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru> * @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License * @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers *
* @see http://help.retailcrm.pro/docs/Developers
*/ */
namespace RetailCrm\Mg\Bot\Model\Entity\Message; namespace RetailCrm\Mg\Bot\Model\Entity\Message;
@ -18,19 +18,19 @@ use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type; use JMS\Serializer\Annotation\Type;
/** /**
* PHP version 7.0 * PHP version 7.0.
* *
* MessageOrderItem class * MessageOrderItem class
* *
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru> * @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License * @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers *
* @see http://help.retailcrm.pro/docs/Developers
*/ */
class MessageOrderItem class MessageOrderItem
{ {
/** /**
* @var string $name * @var string
* *
* @Type("string") * @Type("string")
* @Accessor(getter="getName",setter="setName") * @Accessor(getter="getName",setter="setName")
@ -39,7 +39,7 @@ class MessageOrderItem
private $name; private $name;
/** /**
* @var string $url * @var string
* *
* @Type("string") * @Type("string")
* @Accessor(getter="getUrl",setter="setUrl") * @Accessor(getter="getUrl",setter="setUrl")
@ -48,7 +48,7 @@ class MessageOrderItem
private $url; private $url;
/** /**
* @var string $img * @var string
* *
* @Type("string") * @Type("string")
* @Accessor(getter="getImg",setter="setImg") * @Accessor(getter="getImg",setter="setImg")
@ -57,7 +57,7 @@ class MessageOrderItem
private $img; private $img;
/** /**
* @var MessageCost $price * @var MessageCost
* *
* @Type("MessageCost") * @Type("MessageCost")
* @Accessor(getter="getPrice",setter="setPrice") * @Accessor(getter="getPrice",setter="setPrice")
@ -66,7 +66,7 @@ class MessageOrderItem
private $price; private $price;
/** /**
* @var MessageQuantity $quantity * @var MessageQuantity
* *
* @Type("MessageQuantity") * @Type("MessageQuantity")
* @Accessor(getter="getQuantity",setter="setQuantity) * @Accessor(getter="getQuantity",setter="setQuantity)

View File

@ -30,6 +30,8 @@ use JMS\Serializer\Annotation\Type;
trait CommonFields trait CommonFields
{ {
/** /**
* @var int
*
* @Type("int") * @Type("int")
* @Accessor(getter="getId",setter="setId") * @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty * @SkipWhenEmpty
@ -37,14 +39,18 @@ trait CommonFields
private $id; private $id;
/** /**
* @Type("string") * @var \DateTime
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getSince",setter="setSince") * @Accessor(getter="getSince",setter="setSince")
* @SkipWhenEmpty * @SkipWhenEmpty
*/ */
private $since; private $since;
/** /**
* @Type("string") * @var \DateTime
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUntil",setter="setUntil") * @Accessor(getter="getUntil",setter="setUntil")
* @SkipWhenEmpty * @SkipWhenEmpty
*/ */
@ -67,7 +73,7 @@ trait CommonFields
} }
/** /**
* @return string * @return \DateTime
*/ */
public function getSince() public function getSince()
{ {
@ -75,15 +81,15 @@ trait CommonFields
} }
/** /**
* @param string $since * @param \DateTime $since
*/ */
public function setSince($since) public function setSince(\DateTime $since): void
{ {
$this->since = $since; $this->since = $since;
} }
/** /**
* @return string * @return \DateTime
*/ */
public function getUntil() public function getUntil()
{ {
@ -91,9 +97,9 @@ trait CommonFields
} }
/** /**
* @param string $until * @param \DateTime $until
*/ */
public function setUntil($until) public function setUntil(\DateTime $until): void
{ {
$this->until = $until; $this->until = $until;
} }

View File

@ -0,0 +1,57 @@
<?php
/**
* PHP version 7.0
*
* Upload file by url request
*
* @package RetailCrm\Mg\Bot\Model\Request
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
/**
* PHP version 7.0
*
* UploadFileByUrlRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UploadFileByUrlRequest
{
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @Assert\NotBlank()
* @Assert\Url()
*/
private $url;
/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url): void
{
$this->url = $url;
}
}

View File

@ -23,6 +23,7 @@ namespace RetailCrm\Mg\Bot\Model\Response;
* @license https://opensource.org/licenses/MIT MIT License * @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers * @link http://help.retailcrm.pro/docs/Developers
*/ */
class ErrorOnlyResponse { class ErrorOnlyResponse
{
use CommonFields; use CommonFields;
} }

View File

@ -36,7 +36,7 @@ class Serializer
* Serialize given object to JSON or Array * Serialize given object to JSON or Array
* *
* @param object $request * @param object $request
* @param int $serialize * @param string $serialize
* *
* @return array|string * @return array|string
*/ */
@ -63,10 +63,10 @@ class Serializer
* Deserialize given array or JSON to object * Deserialize given array or JSON to object
* *
* @param mixed $data * @param mixed $data
* @param string self::normalizeNamespace($entityType) * @param string $entityType
* @param string $from * @param string $from
* *
* @return array|object|null * @return object|null
*/ */
public static function deserialize($data, $entityType, $from = self::S_JSON) public static function deserialize($data, $entityType, $from = self::S_JSON)
{ {
@ -85,7 +85,7 @@ class Serializer
break; break;
} }
return $deserialized; return is_object($deserialized) ? $deserialized : null;
} }
/** /**

View File

@ -22,7 +22,6 @@ 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; use RetailCrm\Mg\Bot\Model\Request;
use RetailCrm\Mg\Bot\Model\Response;
use RetailCrm\Mg\Bot\Test\TestCase; use RetailCrm\Mg\Bot\Test\TestCase;
/** /**
@ -37,7 +36,6 @@ use RetailCrm\Mg\Bot\Test\TestCase;
*/ */
class ClientListTest extends TestCase class ClientListTest extends TestCase
{ {
/** /**
* @group("list") * @group("list")
* @throws \Exception * @throws \Exception

View File

@ -0,0 +1,113 @@
<?php
/**
* PHP version 7.0
*
* Upload file 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 RetailCrm\Mg\Bot\Model\Constants;
use RetailCrm\Mg\Bot\Model\Request\MessageSendRequest;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\UploadFileResponse;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class UploadFileTest
*
* @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 FileTest extends TestCase
{
/**
* @group("upload")
* @throws \Exception
*/
public function testUploadFileByUrlException()
{
$client = self::getApiClient(
null,
null,
false,
$this->getEmptyResponse(400)
);
self::expectException(\InvalidArgumentException::class);
$client->uploadFileByUrl('');
$client->uploadFileByUrl('rar');
}
/**
* @group("upload")
* @throws \Exception
*/
public function testUploadFileByUrl()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{"id":"881712bb-4062-4973-9e23-3373135836e2","type":"image","size":3773}')
);
$response = $client->uploadFileByUrl('https://2ip.ru/images/logo.gif');
self::assertTrue($response->isSuccessful());
self::assertEquals('881712bb-4062-4973-9e23-3373135836e2', $response->getId());
self::assertEquals('image', $response->getType());
self::assertEquals('3773', $response->getSize());
}
/**
* @group("upload")
* @throws \Exception
*/
public function testUploadFileViaForm()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{"id":"b2bdba90-166c-4e0a-829d-69f26a09fd2a","type":"file","size":214}')
);
$response = $client->uploadFile(__FILE__);
self::assertTrue($response instanceof UploadFileResponse);
self::assertEquals('b2bdba90-166c-4e0a-829d-69f26a09fd2a', $response->getId());
self::assertEquals('file', $response->getType());
self::assertEquals(214, $response->getSize());
}
/**
* @group("upload")
* @throws \Exception
*/
public function testGetFileById()
{
$fileId = 'b2bdba90-166c-4e0a-829d-69f26a09fd2a';
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('getFile')
);
$response = $client->getFileById($fileId);
self::assertTrue($response instanceof FullFileResponse);
self::assertEquals($fileId, $response->getId());
}
}

View File

@ -0,0 +1 @@
{"id":"b2bdba90-166c-4e0a-829d-69f26a09fd2a","type":"file","size":214,"Url":"https://s3.eu-central-1.amazonaws.com/mg-node-files/files/21/b2bdba90-166c-4e0a-829d-69f26a09fd2a"}