You are here

public function ChargeTest::testCharge in Commerce Recurring Framework 8

@covers ::__construct @covers ::getTitle @covers ::getQuantity @covers ::getUnitPrice @covers ::getBillingPeriod @covers ::getFullBillingPeriod @covers ::needsProration

File

tests/src/Kernel/ChargeTest.php, line 114

Class

ChargeTest
@coversDefaultClass \Drupal\commerce_recurring\Charge @group commerce_recurring

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

public function testCharge() {
  $purchased_entity = $this
    ->prophesize(PurchasableEntityInterface::class)
    ->reveal();
  $billing_period = new BillingPeriod(new DrupalDateTime('2019-01-15 00:00:00'), new DrupalDateTime('2019-02-01 00:00:00'));
  $full_billing_period = new BillingPeriod(new DrupalDateTime('2019-01-01 00:00:00'), new DrupalDateTime('2019-02-01 00:00:00'));
  $charge = new Charge([
    'purchased_entity' => $purchased_entity,
    'title' => 'My subscription',
    'quantity' => '2',
    'unit_price' => new Price('99.99', 'USD'),
    'billing_period' => $billing_period,
    'full_billing_period' => $full_billing_period,
  ]);
  $this
    ->assertEquals($purchased_entity, $charge
    ->getPurchasedEntity());
  $this
    ->assertEquals('My subscription', $charge
    ->getTitle());
  $this
    ->assertEquals('2', $charge
    ->getQuantity());
  $this
    ->assertEquals(new Price('99.99', 'USD'), $charge
    ->getUnitPrice());
  $this
    ->assertEquals($billing_period, $charge
    ->getBillingPeriod());
  $this
    ->assertEquals($full_billing_period, $charge
    ->getFullBillingPeriod());
  $this
    ->assertTrue($charge
    ->needsProration());
  $another_charge = new Charge([
    'purchased_entity' => $purchased_entity,
    'title' => 'My subscription',
    'quantity' => '2',
    'unit_price' => new Price('99.99', 'USD'),
    'billing_period' => $full_billing_period,
    'full_billing_period' => $full_billing_period,
  ]);
  $this
    ->assertFalse($another_charge
    ->needsProration());
}