class DatabaseQueueTest in Payment 8.2
@coversDefaultClass \Drupal\payment\DatabaseQueue
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\DatabaseQueueTest
Expanded class hierarchy of DatabaseQueueTest
File
- tests/
src/ Unit/ DatabaseQueueTest.php, line 16
Namespace
Drupal\Tests\payment\UnitView source
class DatabaseQueueTest extends UnitTestCase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection|\PHPUnit\Framework\MockObject\MockObject
*/
protected $database;
/**
* The event dispatcher.
*
* @var \Drupal\payment\EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $eventDispatcher;
/**
* The database connection.
*
* @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paymentStatusManager;
/**
* The class under test.
*
* @var \Drupal\payment\DatabaseQueue
*/
protected $sut;
/**
* The unique ID of the queue (instance).
*
* @var string
*/
protected $queueId;
/**
* {@inheritdoc}
*/
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);
}
/**
* @covers ::getClaimExpirationPeriod
* @covers ::setClaimExpirationPeriod
*/
public function testGetClaimExpirationPeriod() {
$expiration_period = mt_rand();
$this
->assertSame($this->sut, $this->sut
->setClaimExpirationPeriod($expiration_period));
$this
->assertSame($expiration_period, $this->sut
->getClaimExpirationPeriod());
}
/**
* @covers ::getAllowedPaymentStatusIds
* @covers ::setAllowedPaymentStatusIds
*/
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());
}
/**
* @covers ::claimPayment
*/
public function testClaimPayment() {
$payment_id = mt_rand();
$acquisition_code = $this
->randomMachineName();
/** @var \Drupal\payment\DatabaseQueue|\PHPUnit\Framework\MockObject\MockObject $queue */
$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));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DatabaseQueueTest:: |
protected | property | The database connection. | |
DatabaseQueueTest:: |
protected | property | The event dispatcher. | |
DatabaseQueueTest:: |
protected | property | The database connection. | |
DatabaseQueueTest:: |
protected | property | The unique ID of the queue (instance). | |
DatabaseQueueTest:: |
protected | property | The class under test. | |
DatabaseQueueTest:: |
function |
Overrides UnitTestCase:: |
||
DatabaseQueueTest:: |
public | function | @covers ::claimPayment | |
DatabaseQueueTest:: |
public | function | @covers ::getAllowedPaymentStatusIds @covers ::setAllowedPaymentStatusIds | |
DatabaseQueueTest:: |
public | function | @covers ::getClaimExpirationPeriod @covers ::setClaimExpirationPeriod | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |