class VolumeTest in Physical Fields 8
Tests the volume class.
@coversDefaultClass \Drupal\physical\Volume @group physical
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\physical\Unit\VolumeTest
Expanded class hierarchy of VolumeTest
File
- tests/
src/ Unit/ VolumeTest.php, line 14
Namespace
Drupal\Tests\physical\UnitView source
class VolumeTest extends UnitTestCase {
/**
* The volume.
*
* @var \Drupal\physical\Volume
*/
protected $volume;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->volume = new Volume('4', 'm3');
}
/**
* ::covers __construct.
*/
public function testInvalidUnit() {
$this
->expectException(\InvalidArgumentException::class);
$volume = new Volume('1', 'kg');
}
/**
* Tests unit conversion.
*
* ::covers convert.
*/
public function testConvert() {
$this
->assertEquals(new Volume('4000000', 'ml'), $this->volume
->convert('ml')
->round());
$this
->assertEquals(new Volume('400000', 'cl'), $this->volume
->convert('cl')
->round());
$this
->assertEquals(new Volume('40000', 'dl'), $this->volume
->convert('dl')
->round());
$this
->assertEquals(new Volume('4000', 'l'), $this->volume
->convert('l')
->round());
$this
->assertEquals(new Volume('4000000000', 'mm3'), $this->volume
->convert('mm3')
->round());
$this
->assertEquals(new Volume('4000000', 'cm3'), $this->volume
->convert('cm3')
->round());
$this
->assertEquals(new Volume('244095', 'in3'), $this->volume
->convert('in3')
->round());
$this
->assertEquals(new Volume('141.259', 'ft3'), $this->volume
->convert('ft3')
->round(3));
$this
->assertEquals(new Volume('135256', 'fl oz'), $this->volume
->convert('fl oz')
->round());
$this
->assertEquals(new Volume('1056.69', 'gal'), $this->volume
->convert('gal')
->round(2));
}
}
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. | |
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. | |
VolumeTest:: |
protected | property | The volume. | |
VolumeTest:: |
public | function |
Overrides UnitTestCase:: |
|
VolumeTest:: |
public | function | Tests unit conversion. | |
VolumeTest:: |
public | function | ::covers __construct. |