You are here

public function LocalStockUpdaterTest::testTransactionCreation in Commerce Stock 8

Whether transactions are created.

File

modules/local_storage/tests/src/Kernel/LocalStockUpdaterTest.php, line 149

Class

LocalStockUpdaterTest
Testing the local stock updater.

Namespace

Drupal\Tests\commerce_stock_local\Kernel

Code

public function testTransactionCreation() {

  // Whether the transaction events work.
  $logger = $this
    ->prophesize(LoggerInterface::class);
  $logger
    ->log(Argument::is(7), Argument::containingString('LOCAL_STOCK_TRANSACTION_CREATE'), Argument::type('array'))
    ->shouldBeCalled();
  $logger
    ->log(Argument::is(7), Argument::containingString('LOCAL_STOCK_TRANSACTION_INSERT'), Argument::type('array'))
    ->shouldBeCalled();
  $this->container
    ->get('logger.factory')
    ->get('commerce_local_stock_test')
    ->addLogger($logger
    ->reveal());
  $this->stockService
    ->getStockUpdater()
    ->createTransaction($this->variation, $this->locations[1]
    ->getId(), '', 10, 10.1, 'USD', StockTransactionsInterface::STOCK_IN, []);
  $query = \Drupal::database()
    ->select('commerce_stock_transaction', 'txn')
    ->fields('txn')
    ->condition('transaction_type_id', StockTransactionsInterface::STOCK_IN);
  $result = $query
    ->execute()
    ->fetchAll();
  $this
    ->assertEquals('1', $result[0]->id);
  $this
    ->assertEquals($this->variation
    ->id(), $result[0]->entity_id);
  $this
    ->assertEquals(10, $this->checker
    ->getTotalStockLevel($this->variation, $this->locations));
}