You are here

public function CommerceMigrateTestTrait::formatNumber in Commerce Migrate 3.0.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/CommerceMigrateTestTrait.php \Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait::formatNumber()
  2. 3.1.x tests/src/Kernel/CommerceMigrateTestTrait.php \Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait::formatNumber()

Formats a price number.

Parameters

string $expected: The expected result number to format.

string $actual: The actual result number to format.

string $format_string: The format to convert the number to.

Return value

array An associative array of the formatted numbers, 'expected' for the expected value and 'actual' for the actual value.

6 calls to CommerceMigrateTestTrait::formatNumber()
CommerceMigrateTestTrait::assertOrder in tests/src/Kernel/CommerceMigrateTestTrait.php
Asserts an order entity.
CommerceMigrateTestTrait::assertOrderItem in tests/src/Kernel/CommerceMigrateTestTrait.php
Asserts an order item.
CommerceMigrateTestTrait::assertPaymentEntity in tests/src/Kernel/CommerceMigrateTestTrait.php
Asserts a payment entity.
CommerceMigrateTestTrait::assertPrice in tests/src/Kernel/CommerceMigrateTestTrait.php
Assert a price.
CommerceMigrateTestTrait::assertProductVariationEntity in tests/src/Kernel/CommerceMigrateTestTrait.php
Asserts a product variation.

... See full list

File

tests/src/Kernel/CommerceMigrateTestTrait.php, line 910

Class

CommerceMigrateTestTrait
Helper function to test migrations.

Namespace

Drupal\Tests\commerce_migrate\Kernel

Code

public function formatNumber($expected, $actual, $format_string = '%01.6f') {
  $ret['expected'] = $expected;
  $ret['actual'] = $actual;
  if ($this->container
    ->get('database')
    ->driver() === 'sqlite') {

    // SQLite does not support scales for float data types so we need to
    // convert the value manually.
    $ret['expected'] = sprintf($format_string, $expected);
    $ret['actual'] = sprintf($format_string, $actual);
  }
  return $ret;
}