VolumeTest.php in Physical Fields 8
File
tests/src/Unit/VolumeTest.php
View source
<?php
namespace Drupal\Tests\physical\Unit;
use Drupal\physical\Volume;
use Drupal\Tests\UnitTestCase;
class VolumeTest extends UnitTestCase {
protected $volume;
public function setUp() {
parent::setUp();
$this->volume = new Volume('4', 'm3');
}
public function testInvalidUnit() {
$this
->expectException(\InvalidArgumentException::class);
$volume = new Volume('1', 'kg');
}
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));
}
}