public function RadioactivityProcessorTest::testQueueProcessIncidents in Radioactivity 4.0.x
Same name and namespace in other branches
- 8.3 tests/src/Unit/RadioactivityProcessorTest.php \Drupal\Tests\radioactivity\Unit\RadioactivityProcessorTest::testQueueProcessIncidents()
@covers ::queueProcessIncidents @dataProvider providerQueueProcessIncidents
File
- tests/
src/ Unit/ RadioactivityProcessorTest.php, line 392
Class
- RadioactivityProcessorTest
- @coversDefaultClass \Drupal\radioactivity\RadioactivityProcessor @group radioactivity
Namespace
Drupal\Tests\radioactivity\UnitCode
public function testQueueProcessIncidents($isRevisonable, $initialEnergy, $emittedEnergy, $resultEnergy) {
$energyField = (object) [
'energy' => $initialEnergy,
'timestamp' => $this->requestTime,
];
/** @var \Drupal\Core\Entity\EntityTypeInterface $entityType */
$entityType = $this
->prophesize(EntityTypeInterface::class);
$entityType
->isRevisionable()
->willReturn($isRevisonable);
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this
->prophesize(ContentEntityInterface::class);
$entity
->getEntityType()
->willReturn($entityType);
$entity
->id()
->willReturn(123);
$entity
->get('ra_field')
->willReturn($energyField);
$entity
->setNewRevision(FALSE)
->shouldBeCalledTimes($isRevisonable ? 1 : 0);
$entity
->save()
->shouldBeCalled();
// Prophesize entityTypeManager->getStorage->loadMultiple.
$entityStorage = $this
->prophesize(EntityStorageInterface::class);
$entityStorage
->loadMultiple([
123,
])
->willReturn([
'123' => $entity
->reveal(),
]);
$this->entityTypeManager
->getStorage('entity_test')
->willReturn($entityStorage
->reveal());
$incident = $this
->prophesize(IncidentInterface::class);
$incident
->getFieldName()
->willReturn('ra_field');
$incident
->getEnergy()
->willReturn($emittedEnergy);
$incident
->getTargetId()
->willReturn(0);
$this->sut
->queueProcessIncidents('entity_test', [
'123' => [
$incident
->reveal(),
],
]);
// @todo Find a way to check the resulting energy value.
}