updated method
This commit is contained in:
parent
e68a23885e
commit
2672fcdebf
@ -159,27 +159,57 @@ trait Files
|
|||||||
/**
|
/**
|
||||||
* Edit file data
|
* Edit file data
|
||||||
*
|
*
|
||||||
|
* @param int $id file ID
|
||||||
* @param array $file file data
|
* @param array $file file data
|
||||||
*
|
*
|
||||||
|
* $file = [
|
||||||
|
* 'filename' => 'Test file',
|
||||||
|
* 'attachment' => [
|
||||||
|
* [
|
||||||
|
* 'customer' => [
|
||||||
|
* 'id' => 1
|
||||||
|
* ],
|
||||||
|
* 'order' => [
|
||||||
|
* 'id' => 1
|
||||||
|
* ]
|
||||||
|
* ]
|
||||||
|
* ]
|
||||||
|
* ];
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @throws \RetailCrm\Exception\CurlException
|
* @throws \RetailCrm\Exception\CurlException
|
||||||
* @throws \RetailCrm\Exception\InvalidJsonException
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||||
*
|
*
|
||||||
* @return \RetailCrm\Response\ApiResponse
|
* @return \RetailCrm\Response\ApiResponse
|
||||||
*/
|
*/
|
||||||
public function fileEdit(array $file)
|
public function fileEdit($id, array $file)
|
||||||
{
|
{
|
||||||
|
if (empty($id)) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `id` can`t be blank'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($file)) {
|
if (empty($file)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
'Parameter `file` must contains a data'
|
'Parameter `file` must contains a data'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @noinspection PhpUndefinedMethodInspection */
|
$allowedFields = ['filename', 'attachment'];
|
||||||
return $this->client->makeRequest(
|
foreach (array_keys($file) as $field) {
|
||||||
sprintf('/files/%s/edit', $file['id']),
|
if (!in_array($field, $allowedFields)) {
|
||||||
"POST",
|
throw new \InvalidArgumentException(
|
||||||
['file' => json_encode($file)]
|
'Invalid structure of `file` parameter'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @noinspection PhpUndefinedMethodInspection */
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
sprintf('/files/%s/edit', $id),
|
||||||
|
"POST",
|
||||||
|
['file' => json_encode($file), 'id' => $id]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ class ApiClientFilesTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testFileUpload()
|
public function testFileUpload()
|
||||||
{
|
{
|
||||||
|
|
||||||
$client = static::getApiClient();
|
$client = static::getApiClient();
|
||||||
|
|
||||||
$response = $client->request->fileUpload(__DIR__ . '/../../../Tests/Resources/Report.pdf');
|
$response = $client->request->fileUpload(__DIR__ . '/../../../Tests/Resources/Report.pdf');
|
||||||
@ -67,6 +66,14 @@ class ApiClientFilesTest extends TestCase
|
|||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
|
$response = $client->request->fileEdit($fileId, ['filename' => 'Test file']);
|
||||||
|
|
||||||
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
|
static::assertEquals(200, $response->getStatusCode());
|
||||||
|
static::assertTrue($response->isSuccessful());
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
$response = $client->request->fileDelete($fileId);
|
$response = $client->request->fileDelete($fileId);
|
||||||
|
|
||||||
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||||
@ -75,4 +82,12 @@ class ApiClientFilesTest extends TestCase
|
|||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFileEditFailure()
|
||||||
|
{
|
||||||
|
static::expectExceptionObject(new \InvalidArgumentException('Invalid structure of `file` parameter'));
|
||||||
|
$client = static::getApiClient();
|
||||||
|
|
||||||
|
$client->request->fileEdit(1, ['file' => []]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user