updated method
This commit is contained in:
parent
e68a23885e
commit
2672fcdebf
@ -159,27 +159,57 @@ trait Files
|
||||
/**
|
||||
* Edit file data
|
||||
*
|
||||
* @param int $id file ID
|
||||
* @param array $file file data
|
||||
*
|
||||
* $file = [
|
||||
* 'filename' => 'Test file',
|
||||
* 'attachment' => [
|
||||
* [
|
||||
* 'customer' => [
|
||||
* 'id' => 1
|
||||
* ],
|
||||
* 'order' => [
|
||||
* 'id' => 1
|
||||
* ]
|
||||
* ]
|
||||
* ]
|
||||
* ];
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \RetailCrm\Exception\CurlException
|
||||
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||
*
|
||||
* @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)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Parameter `file` must contains a data'
|
||||
);
|
||||
}
|
||||
|
||||
/* @noinspection PhpUndefinedMethodInspection */
|
||||
return $this->client->makeRequest(
|
||||
sprintf('/files/%s/edit', $file['id']),
|
||||
"POST",
|
||||
['file' => json_encode($file)]
|
||||
$allowedFields = ['filename', 'attachment'];
|
||||
foreach (array_keys($file) as $field) {
|
||||
if (!in_array($field, $allowedFields)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'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()
|
||||
{
|
||||
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->request->fileUpload(__DIR__ . '/../../../Tests/Resources/Report.pdf');
|
||||
@ -67,6 +66,14 @@ class ApiClientFilesTest extends TestCase
|
||||
|
||||
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);
|
||||
|
||||
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
@ -75,4 +82,12 @@ class ApiClientFilesTest extends TestCase
|
||||
|
||||
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