public function RadioactivityProcessorTest::testQueueProcessIncidents in Radioactivity 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/RadioactivityProcessorTest.php \Drupal\Tests\radioactivity\Unit\RadioactivityProcessorTest::testQueueProcessIncidents()
@covers ::queueProcessIncidents @dataProvider providerQueueProcessIncidents
File
- tests/
src/ Unit/ RadioactivityProcessorTest.php, line 354
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|\Drupal\Core\Entity\EntityPublishedInterface $entity */
$entity = $this
->prophesize(PublishedContentEntityInterface::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([
$entity
->reveal(),
]);
$this->entityTypeManager
->getStorage('entity_test')
->willReturn($entityStorage
->reveal());
$incident = $this
->prophesize(IncidentInterface::class);
$incident
->getFieldName()
->willReturn('ra_field');
$incident
->getEnergy()
->willReturn($emittedEnergy);
$this->sut
->queueProcessIncidents('entity_test', [
123 => $incident,
]);
// @todo Find a way to check the resulting energy value.
}