DatabaseQueueTest.php in Payment 8.2
File
tests/src/Unit/DatabaseQueueTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit;
use Drupal\Core\Database\Connection;
use Drupal\payment\DatabaseQueue;
use Drupal\payment\EventDispatcherInterface;
use Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface;
use Drupal\Tests\UnitTestCase;
class DatabaseQueueTest extends UnitTestCase {
protected $database;
protected $eventDispatcher;
protected $paymentStatusManager;
protected $sut;
protected $queueId;
function setUp() : void {
parent::setUp();
$this->database = $this
->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
$this->eventDispatcher = $this
->createMock(EventDispatcherInterface::class);
$this->paymentStatusManager = $this
->createMock(PaymentStatusManagerInterface::class);
$this->queueId = $this
->randomMachineName();
$this->sut = new DatabaseQueue($this->queueId, $this->database, $this->eventDispatcher, $this->paymentStatusManager);
}
public function testGetClaimExpirationPeriod() {
$expiration_period = mt_rand();
$this
->assertSame($this->sut, $this->sut
->setClaimExpirationPeriod($expiration_period));
$this
->assertSame($expiration_period, $this->sut
->getClaimExpirationPeriod());
}
public function testGetAllowedPaymentStatusIds() {
$allowed_payment_status_ids = array(
$this
->randomMachineName(),
$this
->randomMachineName(),
);
$this
->assertSame($this->sut, $this->sut
->setAllowedPaymentStatusIds($allowed_payment_status_ids));
$this
->assertSame($allowed_payment_status_ids, $this->sut
->getAllowedPaymentStatusIds());
}
public function testClaimPayment() {
$payment_id = mt_rand();
$acquisition_code = $this
->randomMachineName();
$queue = $this
->getMockBuilder(DatabaseQueue::class)
->setConstructorArgs(array(
$this->queueId,
$this->database,
$this->eventDispatcher,
$this->paymentStatusManager,
))
->setMethods(array(
'tryClaimPaymentOnce',
))
->getMock();
$queue
->expects($this
->at(0))
->method('tryClaimPaymentOnce')
->with($payment_id)
->willReturn(FALSE);
$queue
->expects($this
->at(1))
->method('tryClaimPaymentOnce')
->with($payment_id)
->willReturn($acquisition_code);
$this
->assertSame($acquisition_code, $queue
->claimPayment($payment_id));
}
}