You are here

public function CronTest::testPending in Commerce Recurring Framework 8

Tests activating pending subscriptions.

@covers ::run

File

tests/src/Kernel/CronTest.php, line 267

Class

CronTest
@coversDefaultClass \Drupal\commerce_recurring\Cron @group commerce_recurring

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

public function testPending() {
  $subscription = Subscription::create([
    'type' => 'product_variation',
    'store_id' => $this->store
      ->id(),
    'billing_schedule' => $this->billingSchedule,
    'uid' => $this->user,
    'payment_method' => $this->paymentMethod,
    'purchased_entity' => $this->variation,
    'title' => $this->variation
      ->getOrderItemTitle(),
    'unit_price' => new Price('2', 'USD'),
    'state' => 'pending',
    'starts' => strtotime('2019-02-15 17:00'),
  ]);
  $subscription
    ->save();
  $this
    ->rewindTime(strtotime('2019-02-15 19:00'));
  $this->container
    ->get('commerce_recurring.cron')
    ->run();

  /** @var \Drupal\advancedqueue\Entity\QueueInterface $queue */
  $queue = Queue::load('commerce_recurring');
  $counts = array_filter($queue
    ->getBackend()
    ->countJobs());
  $this
    ->assertEquals([
    Job::STATE_QUEUED => 1,
  ], $counts);
  $job = $queue
    ->getBackend()
    ->claimJob();
  $this
    ->assertSame([
    'subscription_id' => $subscription
      ->id(),
  ], $job
    ->getPayload());
}