class PushQueueTest in Salesforce Suite 5.0.x
Same name in this branch
- 5.0.x modules/salesforce_push/tests/src/Functional/PushQueueTest.php \Drupal\Tests\salesforce_push\Functional\PushQueueTest
- 5.0.x modules/salesforce_push/tests/src/Unit/PushQueueTest.php \Drupal\Tests\salesforce_push\Unit\PushQueueTest
Same name and namespace in other branches
- 8.4 modules/salesforce_push/tests/src/Unit/PushQueueTest.php \Drupal\Tests\salesforce_push\Unit\PushQueueTest
- 8.3 modules/salesforce_push/tests/src/Unit/PushQueueTest.php \Drupal\Tests\salesforce_push\Unit\PushQueueTest
Test Object instantitation.
@coversDefaultClass \Drupal\salesforce_push\PushQueue
@group salesforce_push
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\salesforce_push\Unit\PushQueueTest
Expanded class hierarchy of PushQueueTest
File
- modules/
salesforce_push/ tests/ src/ Unit/ PushQueueTest.php, line 33
Namespace
Drupal\Tests\salesforce_push\UnitView source
class PushQueueTest extends UnitTestCase {
protected static $modules = [
'salesforce_push',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->schema = $this
->getMockBuilder(Schema::class)
->disableOriginalConstructor()
->getMock();
$this->schema
->expects($this
->any())
->method('tableExists')
->willReturn(TRUE);
$this->database = $this
->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
$this->database
->expects($this
->any())
->method('schema')
->willReturn($this->schema);
$this->state = $this
->getMockBuilder(StateInterface::class)
->getMock();
$this->push_queue_processor_plugin_manager = $this
->getMockBuilder(PushQueueProcessorPluginManager::class)
->disableOriginalConstructor()
->getMock();
$this->entityTypeManager = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->getMock();
$this->eventDispatcher = $this
->getMockBuilder(EventDispatcherInterface::CLASS)
->getMock();
$this->eventDispatcher
->expects($this
->any())
->method('dispatch')
->willReturn(NULL);
$this->string_translation = $this
->getMockBuilder(TranslationInterface::class)
->getMock();
$this->time = $this
->getMockBuilder(TimeInterface::class)
->getMock();
$this->mappingStorage = $this
->getMockBuilder(SalesforceMappingStorage::CLASS)
->disableOriginalConstructor()
->getMock();
$this->mappedObjectStorage = $this
->getMockBuilder(SqlEntityStorageInterface::CLASS)
->getMock();
$this->entityStorage = $this
->getMockBuilder(SqlEntityStorageInterface::CLASS)
->getMock();
$this->entityTypeManager
->expects($this
->at(0))
->method('getStorage')
->with($this
->equalTo('salesforce_mapping'))
->willReturn($this->mappingStorage);
$this->entityTypeManager
->expects($this
->at(1))
->method('getStorage')
->with($this
->equalTo('salesforce_mapped_object'))
->willReturn($this->mappedObjectStorage);
// Mock config.
$prophecy = $this
->prophesize(Config::CLASS);
$prophecy
->get('global_push_limit', Argument::any())
->willReturn(PushQueue::DEFAULT_GLOBAL_LIMIT);
$config = $prophecy
->reveal();
$prophecy = $this
->prophesize(ConfigFactoryInterface::CLASS);
$prophecy
->get('salesforce.settings')
->willReturn($config);
$this->configFactory = $prophecy
->reveal();
$container = new ContainerBuilder();
$container
->set('database', $this->database);
$container
->set('state', $this->state);
$container
->set('entity_type.manager', $this->entityTypeManager);
$container
->set('event_dispatcher', $this->eventDispatcher);
$container
->set('string_translation', $this->string_translation);
$container
->set('plugin.manager.salesforce_push_queue_processor', $this->push_queue_processor_plugin_manager);
$container
->set('datetime.time', $this->time);
$container
->set('config.factory', $this->configFactory);
\Drupal::setContainer($container);
}
/**
* @covers ::claimItem
*/
public function testClaimItem() {
$this->queue = PushQueue::create(\Drupal::getContainer());
$this
->expectException(\Exception::class);
$this->queue
->claimItem();
}
/**
* @covers ::claimItems
*/
public function testClaimItems() {
$this->queue = PushQueue::create(\Drupal::getContainer());
// Test claiming items.
$items = [
1,
2,
3,
];
$this->queryRange = $this
->getMockBuilder(StatementInterface::class)
->getMock();
$this->queryRange
->expects($this
->once())
->method('fetchAllAssoc')
->willReturn($items);
$this->database
->expects($this
->once())
->method('queryRange')
->willReturn($this->queryRange);
$this->updateQuery = $this
->getMockBuilder(Update::class)
->disableOriginalConstructor()
->getMock();
$this->updateQuery
->expects($this
->once())
->method('fields')
->willReturn($this->updateQuery);
$this->updateQuery
->expects($this
->any())
->method('condition')
->willReturn($this->updateQuery);
$this->updateQuery
->expects($this
->once())
->method('execute')
->willReturn(TRUE);
$this->database
->expects($this
->once())
->method('update')
->willReturn($this->updateQuery);
$this
->assertEquals($items, $this->queue
->claimItems(0));
}
/**
* @covers ::processQueues
*/
public function testProcessQueue() {
$items = [
1,
2,
3,
];
$mapping1 = $this
->getMockBuilder(SalesforceMappingInterface::CLASS)
->getMock();
$mapping1
->expects($this
->any())
->method('getNextPushTime')
->willReturn(0);
$mapping1
->expects($this
->any())
->method('id')
->willReturn(1);
$mapping1->push_limit = 1;
$mapping1->push_retries = 1;
$this->worker = $this
->getMockBuilder(PushQueueProcessorInterface::class)
->getMock();
$this->worker
->expects($this
->once())
->method('process')
->willReturn(NULL);
$this->push_queue_processor_plugin_manager
->expects($this
->once())
->method('createInstance')
->willReturn($this->worker);
$this->queue = $this
->getMockBuilder(PushQueue::class)
->setMethods([
'claimItems',
'setName',
'garbageCollection',
])
->setConstructorArgs([
$this->database,
$this->state,
$this->push_queue_processor_plugin_manager,
$this->entityTypeManager,
$this->eventDispatcher,
$this->time,
$this->configFactory,
])
->getMock();
$this->queue
->expects($this
->once())
->method('setName')
->willReturn(NULL);
$this->queue
->expects($this
->any())
->method('garbageCollection')
->willReturn(NULL);
// I don't know why at(2) works.
$this->queue
->expects($this
->at(2))
->method('claimItems')
->willReturn($items);
$this
->assertEquals(3, $this->queue
->processQueue($mapping1));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
PushQueueTest:: |
protected static | property | ||
PushQueueTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PushQueueTest:: |
public | function | @covers ::claimItem | |
PushQueueTest:: |
public | function | @covers ::claimItems | |
PushQueueTest:: |
public | function | @covers ::processQueues | |
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 | 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. | |
UnitTestCase:: |
public static | function |