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

@ -102,7 +102,7 @@ class Currency extends StructuralDBElement
{
$tmp = $this->getExchangeRate();
if ($tmp === null || (float) $tmp === 0) {
if ($tmp === null || $tmp === "0") {
return null;
}

View file

@ -138,9 +138,9 @@ class Orderdetail extends DBElement
/**
* Get the part.
*
* @return Part the part of this orderdetails
* @return Part|null the part of this orderdetails
*/
public function getPart(): Part
public function getPart(): ?Part
{
return $this->part;
}
@ -235,12 +235,13 @@ class Orderdetail extends DBElement
}
/**
* Get the pricedetail for a specific quantity.
* Find the pricedetail that is correct for the desired amount (the one with the greatest discount value with a
* minimum order amount of the wished quantity)
* @param float $quantity this is the quantity to choose the correct pricedetails
*
* @return Pricedetail|null: the price as a bcmath string. Null if there are no orderdetails for the given quantity
*/
public function getPrice(float $quantity = 1) : ?Pricedetail
public function findPriceForQty(float $quantity = 1) : ?Pricedetail
{
if ($quantity <= 0) {
return null;

View file

@ -130,25 +130,15 @@ class Pricedetail extends DBElement
*********************************************************************************/
/**
* Get the orderdetails of this pricedetails.
* Get the orderdetail to which this pricedetail belongs to this pricedetails.
*
* @return Orderdetail the orderdetails object
* @return Orderdetail The orderdetail this price belongs to.
*/
public function getOrderdetails(): Orderdetail
public function getOrderdetail(): Orderdetail
{
return $this->orderdetail;
}
/**
* Returns the price associated with this pricedetail.
* It is given in current currency and for the price related quantity.
* @return float
*/
public function getPriceFloat() : float
{
return (float) $this->price;
}
/**
* Returns the price associated with this pricedetail.
* It is given in current currency and for the price related quantity.
@ -159,16 +149,6 @@ class Pricedetail extends DBElement
return $this->price;
}
/**
* Returns the price associated with this pricedetail as integer.
* It is given in current currency and for the price related quantity, in parts of 0.00001 (5 digits)
* @return int
*/
public function getPriceInt() : int
{
return (int) str_replace('.', '', $this->price);
}
/**
* Get the price for a single unit in the currency associated with this price detail.
*
@ -179,7 +159,6 @@ class Pricedetail extends DBElement
* in the database, you have to pass the "price_related_quantity" count as $multiplier.
*
* @return string the price as a bcmath string
*/
public function getPricePerUnit($multiplier = 1.0) : string
{
@ -201,7 +180,7 @@ class Pricedetail extends DBElement
*/
public function getPriceRelatedQuantity(): float
{
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->price_related_quantity);
return $tmp < 1 ? 1 : $tmp;
}