Part-DB.Part-DB-server/tests/Entity/PartInstockTest.php
Jan Böhmer a97d016740 Added some more tests.
Also changed the behavior of some code to meet the expectation.
2019-09-22 23:47:40 +02:00

110 lines
No EOL
3.4 KiB
PHP

<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Entity;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use PHPUnit\Framework\TestCase;
/**
* Here we test the instock related functions of part class (functions in InstockTrait)
* @package App\Tests\Entity
*/
class PartInstockTest extends TestCase
{
protected $float_unit;
protected $int_unit;
public function setUp()
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->float_unit = new MeasurementUnit();
$this->float_unit->setIsInteger(false);
$this->int_unit = new MeasurementUnit();
$this->int_unit->setIsInteger(true);
}
public function testUseFloatAmount()
{
$part = new Part();
$part->setPartUnit(null);
$this->assertFalse($part->useFloatAmount());
$part->setPartUnit($this->float_unit);
$this->assertTrue($part->useFloatAmount());
$part->setPartUnit($this->int_unit);
$this->assertFalse($part->useFloatAmount());
}
public function testGetMinAmount()
{
$part = new Part();
$part->setMinAmount(10.32);
$part->setPartUnit(null);
$this->assertEquals(10.0, $part->getMinAmount());
$part->setPartUnit($this->float_unit);
$this->assertEquals(10.32, $part->getMinAmount());
}
public function testAddPartLot()
{
$part = new Part();
//Part must be empty after creation
$this->assertEmpty($part->getPartLots());
$part_lot = new PartLot();
$part->addPartLot($part_lot);
$this->assertCount(1, $part->getPartLots());
//PartLot must now be assigned to part
$this->assertEquals($part, $part_lot->getPart());
}
public function testGetAmountSum()
{
$part = new Part();
$part->addPartLot((new PartLot())->setAmount(5.42));
$part->addPartLot((new PartLot())->setAmount(0.4));
$part->addPartLot((new PartLot())->setAmount(10.4));
$part->addPartLot((new PartLot())->setAmount(100)->setInstockUnknown(true));
$part->setPartUnit(null);
//It is important that we get 15 here (values are round and then summed), not 16 (sum and then round)
$this->assertEquals(15, $part->getAmountSum());
$part->setPartUnit($this->float_unit);
$this->assertEquals(16.22, $part->getAmountSum());
}
}