class RounderTest in Commerce Core 8.2
Tests the Rounder class.
@coversDefaultClass \Drupal\commerce_price\Rounder @group commerce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce_price\Unit\RounderTest
Expanded class hierarchy of RounderTest
File
- modules/
price/ tests/ src/ Unit/ RounderTest.php, line 18
Namespace
Drupal\Tests\commerce_price\UnitView source
class RounderTest extends UnitTestCase {
/**
* The rounder.
*
* @var \Drupal\commerce_price\Rounder
*/
protected $rounder;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$usd_currency = $this
->prophesize(CurrencyInterface::class);
$usd_currency
->id()
->willReturn('USD');
$usd_currency
->getFractionDigits()
->willReturn('2');
$storage = $this
->prophesize(EntityStorageInterface::class);
$storage
->load('USD')
->willReturn($usd_currency
->reveal());
$storage
->load('EUR')
->willReturn(NULL);
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager
->getStorage('commerce_currency')
->willReturn($storage
->reveal());
$this->rounder = new Rounder($entity_type_manager
->reveal());
}
/**
* Tests rounding a price with an unknown currency.
*
* ::covers round.
*/
public function testUnknownCurrency() {
$this
->expectException(\InvalidArgumentException::class);
$this->rounder
->round(new Price('10', 'EUR'));
}
/**
* Tests rounding a valid price.
*
* ::covers round.
*/
public function testValid() {
$rounded_price = $this->rounder
->round(new Price('3.3698', 'USD'));
$this
->assertEquals('3.37', $rounded_price
->getNumber());
$this
->assertEquals('USD', $rounded_price
->getCurrencyCode());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
RounderTest:: |
protected | property | The rounder. | |
RounderTest:: |
protected | function |
Overrides UnitTestCase:: |
|
RounderTest:: |
public | function | Tests rounding a price with an unknown currency. | |
RounderTest:: |
public | function | Tests rounding a valid price. | |
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. |