ListPaymentMethodsTest.php in Payment 8.2
File
tests/src/Unit/Controller/ListPaymentMethodsTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit\Controller;
use Drupal\payment\Controller\ListPaymentMethods;
use Drupal\payment\Plugin\Payment\Method\PaymentMethodInterface;
use Drupal\payment\Plugin\Payment\Method\PaymentMethodManagerInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ListPaymentMethodsTest extends UnitTestCase {
protected $paymentMethodManager;
protected $stringTranslation;
protected $sut;
protected function setUp() : void {
$this->paymentMethodManager = $this
->createMock(PaymentMethodManagerInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->sut = new ListPaymentMethods($this->stringTranslation, $this->paymentMethodManager);
}
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'plugin.manager.payment.method',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->paymentMethodManager,
],
[
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = ListPaymentMethods::create($container);
$this
->assertInstanceOf(ListPaymentMethods::class, $sut);
}
public function testExecute() {
$plugin_id_a = $this
->randomMachineName();
$plugin_id_b = $this
->randomMachineName();
$definitions = [
$plugin_id_a => [
'active' => TRUE,
'class' => $this
->getMockClass(PaymentMethodInterface::class),
'label' => $this
->randomMachineName(),
],
$plugin_id_b => [
'active' => FALSE,
'class' => $this
->getMockClass(PaymentMethodInterface::class),
'label' => $this
->randomMachineName(),
],
];
$this->paymentMethodManager
->expects($this
->once())
->method('getDefinitions')
->willReturn($definitions);
$build = $this->sut
->execute();
$this
->assertIsArray($build);
}
}