LengthTest.php in Physical Fields 8
File
tests/src/Unit/LengthTest.php
View source
<?php
namespace Drupal\Tests\physical\Unit;
use Drupal\physical\Length;
use Drupal\Tests\UnitTestCase;
class LengthTest extends UnitTestCase {
protected $length;
public function setUp() {
parent::setUp();
$this->length = new Length('3', 'm');
}
public function testInvalidUnit() {
$this
->expectException(\InvalidArgumentException::class);
$length = new Length('1', 'kg');
}
public function testConvert() {
$this
->assertEquals(new Length('3000', 'mm'), $this->length
->convert('mm')
->round());
$this
->assertEquals(new Length('300', 'cm'), $this->length
->convert('cm')
->round());
$this
->assertEquals(new Length('0.003', 'km'), $this->length
->convert('km')
->round(3));
$this
->assertEquals(new Length('118.110', 'in'), $this->length
->convert('in')
->round(3));
$this
->assertEquals(new Length('9.843', 'ft'), $this->length
->convert('ft')
->round(3));
$this
->assertEquals(new Length('0.00162', 'M'), $this->length
->convert('M')
->round(5));
}
}