1
0
mirror of synced 2024-11-21 21:06:07 +03:00

updated method TelephonyCallEvent (#88)

This commit is contained in:
Yura 2020-09-09 12:51:31 +03:00 committed by GitHub
parent 88cb6526b0
commit 5d0e20581c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 9 deletions

View File

@ -57,6 +57,8 @@ trait Telephony
* @param string $phone phone number
* @param string $type call type
* @param array $codes
* @param array $userIds
* @param string $callExternalId
* @param string $hangupStatus
* @param string $externalPhone
* @param array $webAnalyticsData
@ -70,8 +72,10 @@ trait Telephony
$phone,
$type,
$codes,
$userIds = [],
$hangupStatus = null,
$externalPhone = null,
$callExternalId = null,
$webAnalyticsData = [],
$site = null
) {
@ -90,8 +94,14 @@ trait Telephony
$parameters['phone'] = $phone;
$parameters['type'] = $type;
$parameters['codes'] = $codes;
if (!empty($userIds)) {
$parameters['userIds'] = $userIds;
}
$parameters['hangupStatus'] = $hangupStatus;
$parameters['callExternalId'] = $externalPhone;
$parameters['callExternalId'] = $callExternalId;
$parameters['externalPhone'] = $externalPhone;
$parameters['webAnalyticsData'] = $webAnalyticsData;
/* @noinspection PhpUndefinedMethodInspection */

View File

@ -14,6 +14,7 @@
namespace RetailCrm\Test;
use PHPUnit\Framework\MockObject\MockObject;
use RetailCrm\ApiClient;
use RetailCrm\Http\Client;
use PHPUnit\Framework\TestCase as BaseCase;
@ -58,6 +59,22 @@ class TestCase extends BaseCase
);
}
/**
* @param \RetailCrm\Http\Client|MockObject $httpClient
* @return ApiClient
* @throws \ReflectionException
*/
public static function getMockedApiClient($httpClient)
{
$client = self::getApiClient();
$property = new \ReflectionProperty(get_class($client->request), 'client');
$property->setAccessible(true);
$property->setValue($client->request, $httpClient);
return $client;
}
/**
* Return Client object
*

View File

@ -15,6 +15,7 @@
namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\ApiClient;
use RetailCrm\Response\ApiResponse;
use RetailCrm\Test\TestCase;
/**
@ -90,19 +91,42 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyEvent()
{
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient(null, null, ApiClient::V4);
$stub = $this->getMockBuilder(\RetailCrm\Http\Client::class)
->disableOriginalConstructor()
->setMethods(['makeRequest'])
->getMock();
$parameters = [
'phone' => '+79999999999',
'type' => 'in',
'codes' => ['101'],
'userIds' => [2],
'hangupStatus' => 'failed',
'callExternalId' => '+74950000000',
'externalPhone' => '123456789',
'webAnalyticsData' => [],
'site' => 'retailcrm-ru'
];
$stub->expects(self::once())->method('makeRequest')->with(
'/telephony/call/event',
"POST",
['event' => json_encode($parameters)]
)->willReturn((new ApiResponse(200, json_encode(['success' => true])))->asJsonResponse());
$client = static::getMockedApiClient($stub);
$response = $client->request->telephonyCallEvent(
'+79999999999',
'in',
['101'],
[2],
'failed',
'+74950000000'
'123456789',
'+74950000000',
[]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}