/**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $payment_line_items = new LineItemCollection();
     /** @var \Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemInterface $item */
     foreach ($items as $delta => $item) {
         $payment_line_items->setLineItem($item->getContainedPluginInstance());
     }
     $entity = $items->getEntity();
     if ($entity instanceof LineItemCollectionInterface) {
         $payment_line_items->setCurrencyCode($entity->getCurrencyCode());
     }
     $build[0] = array('#payment_line_items' => $payment_line_items, '#type' => 'payment_line_items_display');
     return $build;
 }
 /**
  * @covers ::getAmount
  */
 public function testGetAmount()
 {
     $line_item_amount_a = mt_rand();
     $line_item_amount_b = mt_rand();
     /** @var \Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemInterface|\PHPUnit_Framework_MockObject_MockObject $line_item_a */
     /** @var \Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemInterface|\PHPUnit_Framework_MockObject_MockObject $line_item_b */
     list($line_item_a, $line_item_b) = array_values($this->lineItems);
     $line_item_a->expects($this->atLeastOnce())->method('getTotalAmount')->willReturn($line_item_amount_a);
     $line_item_b->expects($this->atLeastOnce())->method('getTotalAmount')->willReturn($line_item_amount_b);
     $this->assertSame(bcadd($line_item_amount_a, $line_item_amount_b, 6), $this->sut->getAmount());
 }