Added some tests for important entity methods.

This commit is contained in:
Jan Böhmer 2019-11-09 00:31:42 +01:00
parent 0663a00df8
commit 89258bc102
18 changed files with 480 additions and 160 deletions

View file

@ -116,7 +116,6 @@ class PartLot extends DBElement
* Check if the current part lot is expired.
* This is the case, if the expiration date is greater the the current date.
* @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set.
* @throws \Exception
*/
public function isExpired(): ?bool
{
@ -125,7 +124,7 @@ class PartLot extends DBElement
}
//Check if the expiration date is bigger then current time
return $this->expiration_date < new \DateTime();
return $this->expiration_date < new \DateTime('now');
}
/**

View file

@ -35,7 +35,7 @@ use Doctrine\Common\Collections\Collection;
trait InstockTrait
{
/**
* @var ?PartLot[]|Collection A list of part lots where this part is stored
* @var Collection|PartLot[] A list of part lots where this part is stored
* @ORM\OneToMany(targetEntity="PartLot", mappedBy="part", cascade={"persist", "remove"}, orphanRemoval=true)
* @Assert\Valid()
* @ColumnSecurity(type="collection", prefix="lots")
@ -146,6 +146,7 @@ trait InstockTrait
/**
* Returns the summed amount of this part (over all part lots)
* Part Lots that have unknown value or are expired, are not used for this value
* @return float The amount of parts given in partUnit
*/
public function getAmountSum() : float
@ -154,7 +155,7 @@ trait InstockTrait
$sum = 0;
foreach ($this->getPartLots() as $lot) {
//Dont use the instock value, if it is unkown
if ($lot->isInstockUnknown()) {
if ($lot->isInstockUnknown() || $lot->isExpired() ?? false) {
continue;
}