mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-01 16:54:32 +02:00
Applied code style to tests/
This commit is contained in:
parent
f861de791f
commit
fe0f69f762
44 changed files with 427 additions and 306 deletions
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -32,7 +35,7 @@ class AmountFormatterTest extends WebTestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
|
@ -41,56 +44,56 @@ class AmountFormatterTest extends WebTestCase
|
|||
$this->service = self::$container->get(AmountFormatter::class);
|
||||
}
|
||||
|
||||
public function testFormatWithoutUnit()
|
||||
public function testFormatWithoutUnit(): void
|
||||
{
|
||||
$this->assertEquals('2', $this->service->format(2.321));
|
||||
$this->assertEquals('1002', $this->service->format(1002.356));
|
||||
$this->assertEquals('1000454', $this->service->format(1000454.0));
|
||||
$this->assertEquals('0', $this->service->format(0.01));
|
||||
$this->assertEquals('0', $this->service->format(0));
|
||||
$this->assertSame('2', $this->service->format(2.321));
|
||||
$this->assertSame('1002', $this->service->format(1002.356));
|
||||
$this->assertSame('1000454', $this->service->format(1000454.0));
|
||||
$this->assertSame('0', $this->service->format(0.01));
|
||||
$this->assertSame('0', $this->service->format(0));
|
||||
}
|
||||
|
||||
public function testInvalidInput()
|
||||
public function testInvalidInput(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->service->format('test');
|
||||
}
|
||||
|
||||
public function testFormatUnitWithoutSI()
|
||||
public function testFormatUnitWithoutSI(): void
|
||||
{
|
||||
$meters = new MeasurementUnit();
|
||||
$meters->setIsInteger(false)->setUseSIPrefix(false)->setUnit('m');
|
||||
|
||||
$this->assertEquals('0.32 m', $this->service->format(0.3245, $meters));
|
||||
$this->assertEquals('10003.56 m', $this->service->format(10003.556, $meters));
|
||||
$this->assertEquals('0.00 m', $this->service->format(0.0004, $meters));
|
||||
$this->assertSame('0.32 m', $this->service->format(0.3245, $meters));
|
||||
$this->assertSame('10003.56 m', $this->service->format(10003.556, $meters));
|
||||
$this->assertSame('0.00 m', $this->service->format(0.0004, $meters));
|
||||
}
|
||||
|
||||
public function testFormatUnitWithSI()
|
||||
public function testFormatUnitWithSI(): void
|
||||
{
|
||||
$meters = new MeasurementUnit();
|
||||
$meters->setIsInteger(false)->setUseSIPrefix(true)->setUnit('m');
|
||||
|
||||
$this->assertEquals('0.32 m', $this->service->format(0.3245, $meters));
|
||||
$this->assertEquals('12.32 m', $this->service->format(12.323, $meters));
|
||||
$this->assertEquals('120.32 km', $this->service->format(120320.45, $meters));
|
||||
$this->assertSame('0.32 m', $this->service->format(0.3245, $meters));
|
||||
$this->assertSame('12.32 m', $this->service->format(12.323, $meters));
|
||||
$this->assertSame('120.32 km', $this->service->format(120320.45, $meters));
|
||||
|
||||
$this->assertEquals('0.32 mm', $this->service->format(0.00032, $meters));
|
||||
$this->assertSame('0.32 mm', $this->service->format(0.00032, $meters));
|
||||
}
|
||||
|
||||
public function testFormatMoreDigits()
|
||||
public function testFormatMoreDigits(): void
|
||||
{
|
||||
$this->assertEquals('12.12345', $this->service->format(12.1234532, null, ['is_integer' => false, 'decimals' => 5]));
|
||||
$this->assertEquals('12.1', $this->service->format(12.1234532, null, ['is_integer' => false, 'decimals' => 1]));
|
||||
$this->assertSame('12.12345', $this->service->format(12.1234532, null, ['is_integer' => false, 'decimals' => 5]));
|
||||
$this->assertSame('12.1', $this->service->format(12.1234532, null, ['is_integer' => false, 'decimals' => 1]));
|
||||
}
|
||||
|
||||
public function testFormatOptionsOverride()
|
||||
public function testFormatOptionsOverride(): void
|
||||
{
|
||||
$meters = new MeasurementUnit();
|
||||
$meters->setIsInteger(false)->setUseSIPrefix(true)->setUnit('m');
|
||||
|
||||
$this->assertEquals('12.32', $this->service->format(12.323, $meters, ['unit' => '']));
|
||||
$this->assertEquals('12002.32 m', $this->service->format(12002.32, $meters, ['show_prefix' => false]));
|
||||
$this->assertEquals('123 m', $this->service->format(123.234, $meters, ['is_integer' => true]));
|
||||
$this->assertSame('12.32', $this->service->format(12.323, $meters, ['unit' => '']));
|
||||
$this->assertSame('12002.32 m', $this->service->format(12002.32, $meters, ['show_prefix' => false]));
|
||||
$this->assertSame('123 m', $this->service->format(123.234, $meters, ['is_integer' => true]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue