AddPaymentStatusTest.php in Payment 8.2
File
tests/src/Unit/Controller/AddPaymentStatusTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit\Controller;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\payment\Controller\AddPaymentStatus;
use Drupal\payment\Entity\PaymentStatusInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AddPaymentStatusTest extends UnitTestCase {
protected $entityFormBuilder;
protected $paymentStatusStorage;
protected $sut;
protected function setUp() : void {
$this->entityFormBuilder = $this
->createMock(EntityFormBuilderInterface::class);
$this->paymentStatusStorage = $this
->createMock(EntityStorageInterface::class);
$this->sut = new AddPaymentStatus($this->entityFormBuilder, $this->paymentStatusStorage);
}
function testCreate() {
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_type_manager
->expects($this
->once())
->method('getStorage')
->with('payment_status')
->willReturn($this->paymentStatusStorage);
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'entity.form_builder',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->entityFormBuilder,
],
[
'entity_type.manager',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$entity_type_manager,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = AddPaymentStatus::create($container);
$this
->assertInstanceOf(AddPaymentStatus::class, $sut);
}
public function testExecute() {
$payment_status = $this
->createMock(PaymentStatusInterface::class);
$this->paymentStatusStorage
->expects($this
->once())
->method('create')
->willReturn($payment_status);
$form = $this
->createMock(FormInterface::class);
$this->entityFormBuilder
->expects($this
->once())
->method('getForm')
->with($payment_status)
->willReturn($form);
$this
->assertSame($form, $this->sut
->execute());
}
}