1
0
mirror of synced 2024-11-25 06:46: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 $phone phone number
* @param string $type call type * @param string $type call type
* @param array $codes * @param array $codes
* @param array $userIds
* @param string $callExternalId
* @param string $hangupStatus * @param string $hangupStatus
* @param string $externalPhone * @param string $externalPhone
* @param array $webAnalyticsData * @param array $webAnalyticsData
@ -70,8 +72,10 @@ trait Telephony
$phone, $phone,
$type, $type,
$codes, $codes,
$userIds = [],
$hangupStatus = null, $hangupStatus = null,
$externalPhone = null, $externalPhone = null,
$callExternalId = null,
$webAnalyticsData = [], $webAnalyticsData = [],
$site = null $site = null
) { ) {
@ -90,8 +94,14 @@ trait Telephony
$parameters['phone'] = $phone; $parameters['phone'] = $phone;
$parameters['type'] = $type; $parameters['type'] = $type;
$parameters['codes'] = $codes; $parameters['codes'] = $codes;
if (!empty($userIds)) {
$parameters['userIds'] = $userIds;
}
$parameters['hangupStatus'] = $hangupStatus; $parameters['hangupStatus'] = $hangupStatus;
$parameters['callExternalId'] = $externalPhone; $parameters['callExternalId'] = $callExternalId;
$parameters['externalPhone'] = $externalPhone;
$parameters['webAnalyticsData'] = $webAnalyticsData; $parameters['webAnalyticsData'] = $webAnalyticsData;
/* @noinspection PhpUndefinedMethodInspection */ /* @noinspection PhpUndefinedMethodInspection */

View File

@ -14,6 +14,7 @@
namespace RetailCrm\Test; namespace RetailCrm\Test;
use PHPUnit\Framework\MockObject\MockObject;
use RetailCrm\ApiClient; use RetailCrm\ApiClient;
use RetailCrm\Http\Client; use RetailCrm\Http\Client;
use PHPUnit\Framework\TestCase as BaseCase; 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 * Return Client object
* *

View File

@ -15,6 +15,7 @@
namespace RetailCrm\Tests\Methods\Version4; namespace RetailCrm\Tests\Methods\Version4;
use RetailCrm\ApiClient; use RetailCrm\ApiClient;
use RetailCrm\Response\ApiResponse;
use RetailCrm\Test\TestCase; use RetailCrm\Test\TestCase;
/** /**
@ -90,19 +91,42 @@ class ApiClientTelephonyTest extends TestCase
*/ */
public function testTelephonyEvent() public function testTelephonyEvent()
{ {
self::markTestSkipped('Should be fixed.'); $stub = $this->getMockBuilder(\RetailCrm\Http\Client::class)
$client = static::getApiClient(null, null, ApiClient::V4); ->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( $response = $client->request->telephonyCallEvent(
'+79999999999', '+79999999999',
'in', 'in',
['101'], ['101'],
[2],
'failed', 'failed',
'+74950000000' '123456789',
'+74950000000',
[]
); );
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful()); static::assertTrue($response->isSuccessful());
} }