mautic / plugins /MauticCrmBundle /Tests /Api /ConnectwiseApiTest.php
chrisbryan17's picture
Upload folder using huggingface_hub
d2897cd verified
raw
history blame contribute delete
1.55 kB
<?php
namespace MauticPlugin\MauticCrmBundle\Tests\Api;
use MauticPlugin\MauticCrmBundle\Api\ConnectwiseApi;
use MauticPlugin\MauticCrmBundle\Integration\ConnectwiseIntegration;
use MauticPlugin\MauticCrmBundle\Tests\Integration\DataGeneratorTrait;
class ConnectwiseApiTest extends \PHPUnit\Framework\TestCase
{
use DataGeneratorTrait;
/**
* @testdox Tests that fetchAllRecords loops until all records are obtained
*
* @covers \MauticPlugin\MauticCrmBundle\Api\ConnectwiseApi::fetchAllRecords
*
* @throws \Mautic\PluginBundle\Exception\ApiErrorException
*/
public function testResultPagination(): void
{
$integration = $this->getMockBuilder(ConnectwiseIntegration::class)
->disableOriginalConstructor()
->onlyMethods(['makeRequest', 'getApiUrl'])
->getMock();
$page = 0;
$integration->expects($this->exactly(3))
->method('makeRequest')
->willReturnCallback(
function ($endpoint, $parameters) use (&$page) {
++$page;
// Page should be incremented 3 times by fetchAllRecords method
$this->assertEquals(['page' => $page, 'pageSize' => ConnectwiseIntegration::PAGESIZE], $parameters);
return $this->generateData(3);
}
);
$api = new ConnectwiseApi($integration);
$records = $api->fetchAllRecords('test');
$this->assertEquals($this->generatedRecords, $records);
}
}