class QueueHandlerTest in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 modules/salesforce_pull/tests/src/Unit/QueueHandlerTest.php \Drupal\Tests\salesforce_pull\Unit\QueueHandlerTest
- 5.0.x modules/salesforce_pull/tests/src/Unit/QueueHandlerTest.php \Drupal\Tests\salesforce_pull\Unit\QueueHandlerTest
Test Object instantitation.
@group salesforce_pull
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\salesforce_pull\Unit\QueueHandlerTest
Expanded class hierarchy of QueueHandlerTest
File
- modules/
salesforce_pull/ tests/ src/ Unit/ QueueHandlerTest.php, line 27
Namespace
Drupal\Tests\salesforce_pull\UnitView source
class QueueHandlerTest extends UnitTestCase {
public static $modules = [
'salesforce_pull',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$result = [
'totalSize' => 1,
'done' => TRUE,
'records' => [],
];
$this->sqrDone = new SelectQueryResult($result);
$result['records'] = [
[
'Id' => '1234567890abcde',
'attributes' => [
'type' => 'dummy',
],
'name' => 'Example',
],
];
$this->sqr = new SelectQueryResult($result);
$soql = new SelectQuery('dummy');
$soql->fields = [
'Id',
];
$soql
->addCondition('LastModifiedDate', '1970-1-1T00:00:00Z', '>');
$prophecy = $this
->prophesize(RestClientInterface::CLASS);
$prophecy
->query(Argument::any())
->willReturn($this->sqr);
$prophecy
->queryMore(Argument::any())
->willReturn($this->sqrDone);
$this->sfapi = $prophecy
->reveal();
$this->mapping = $this
->getMock(SalesforceMappingInterface::CLASS);
$this->mapping
->expects($this
->any())
->method('__get')
->with($this
->equalTo('id'))
->willReturn(1);
$this->mapping
->expects($this
->any())
->method('getSalesforceObjectType')
->willReturn('default');
$this->mapping
->expects($this
->any())
->method('getPullFieldsArray')
->willReturn([
'Name' => 'Name',
'Account Number' => 'Account Number',
]);
$this->mapping
->expects($this
->any())
->method('getNextPullTime')
->willReturn(0);
$this->mapping
->method('getPullQuery')
->willReturn($soql);
$prophecy = $this
->prophesize(QueueInterface::CLASS);
$prophecy
->createItem()
->willReturn(1);
$prophecy
->numberOfItems()
->willReturn(2);
$this->queue = $prophecy
->reveal();
$prophecy = $this
->prophesize(QueueDatabaseFactory::CLASS);
$prophecy
->get(Argument::any())
->willReturn($this->queue);
$this->queue_factory = $prophecy
->reveal();
// Mock mapping ConfigEntityStorage object.
$prophecy = $this
->prophesize(SalesforceMappingStorage::CLASS);
$prophecy
->loadCronPullMappings(Argument::any())
->willReturn([
$this->mapping,
]);
$this->mappingStorage = $prophecy
->reveal();
// Mock EntityTypeManagerInterface.
$prophecy = $this
->prophesize(EntityTypeManagerInterface::CLASS);
$prophecy
->getStorage('salesforce_mapping')
->willReturn($this->mappingStorage);
$this->etm = $prophecy
->reveal();
// Mock config.
$prophecy = $this
->prophesize(Config::CLASS);
$prophecy
->get('pull_max_queue_size', Argument::any())
->willReturn(QueueHandler::PULL_MAX_QUEUE_SIZE);
$config = $prophecy
->reveal();
$prophecy = $this
->prophesize(ConfigFactoryInterface::CLASS);
$prophecy
->get('salesforce.settings')
->willReturn($config);
$this->configFactory = $prophecy
->reveal();
// Mock state.
$prophecy = $this
->prophesize(StateInterface::CLASS);
$prophecy
->get('salesforce.mapping_pull_info', Argument::any())
->willReturn([
1 => [
'last_pull_timestamp' => '0',
],
]);
$prophecy
->set('salesforce.mapping_pull_info', Argument::any())
->willReturn(NULL);
$this->state = $prophecy
->reveal();
// Mock event dispatcher.
$prophecy = $this
->prophesize(EventDispatcherInterface::CLASS);
$prophecy
->dispatch(Argument::any(), Argument::any())
->willReturn();
$this->ed = $prophecy
->reveal();
$this->time = $this
->getMock(TimeInterface::CLASS);
$this->qh = $this
->getMockBuilder(QueueHandler::CLASS)
->setMethods([
'parseUrl',
])
->setConstructorArgs([
$this->sfapi,
$this->etm,
$this->queue_factory,
$this->configFactory,
$this->ed,
$this->time,
])
->getMock();
$this->qh
->expects($this
->any())
->method('parseUrl')
->willReturn('https://example.salesforce.com');
}
/**
* Test object instantiation.
*/
public function testObject() {
$this
->assertTrue($this->qh instanceof QueueHandler);
}
/**
* Test handler operation, good data.
*/
public function testGetUpdatedRecords() {
$result = $this->qh
->getUpdatedRecords();
$this
->assertTrue($result);
}
/**
* Test handler operation, too many queue items.
*/
public function testTooManyQueueItems() {
// Initialize with queue size > 100000 (default)
$prophecy = $this
->prophesize(QueueInterface::CLASS);
$prophecy
->createItem()
->willReturn(1);
$prophecy
->numberOfItems()
->willReturn(QueueHandler::PULL_MAX_QUEUE_SIZE + 1);
$this->queue = $prophecy
->reveal();
$prophecy = $this
->prophesize(QueueDatabaseFactory::CLASS);
$prophecy
->get(Argument::any())
->willReturn($this->queue);
$this->queue_factory = $prophecy
->reveal();
$this->qh = $this
->getMockBuilder(QueueHandler::CLASS)
->setMethods([
'parseUrl',
])
->setConstructorArgs([
$this->sfapi,
$this->etm,
$this->queue_factory,
$this->configFactory,
$this->ed,
$this->time,
])
->getMock();
$this->qh
->expects($this
->any())
->method('parseUrl')
->willReturn('https://example.salesforce.com');
$result = $this->qh
->getUpdatedRecords();
$this
->assertFalse($result);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
QueueHandlerTest:: |
public static | property | ||
QueueHandlerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
QueueHandlerTest:: |
public | function | Test handler operation, good data. | |
QueueHandlerTest:: |
public | function | Test object instantiation. | |
QueueHandlerTest:: |
public | function | Test handler operation, too many queue items. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |