mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Unit test fixes
This commit is contained in:
parent
f673579340
commit
2e3c475a8f
|
|
@ -303,7 +303,6 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
public function create($obj, bool $relations = true)
|
||||
{
|
||||
// todo: create should also have an option to create relations (default = true)
|
||||
$query = new Builder($this->db);
|
||||
$query->prefix($this->db->getPrefix())
|
||||
->into(static::$table);
|
||||
|
|
@ -344,7 +343,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
$primaryKey = $mapper->create($property->getValue($obj));
|
||||
}
|
||||
|
||||
$property->setValue($obj, $primaryKey);
|
||||
//$property->setValue($obj, $primaryKey);
|
||||
}
|
||||
|
||||
if ($column['internal'] === $pname) {
|
||||
|
|
@ -362,6 +361,8 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
$value = isset($value) ? json_encode($value) : '';
|
||||
} elseif ($column['type'] === 'Serializable') {
|
||||
$value = $value->serialize();
|
||||
} elseif(is_object($value)) {
|
||||
$value = $value->getId();
|
||||
}
|
||||
|
||||
$query->insert($column['name'])
|
||||
|
|
@ -453,7 +454,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
}
|
||||
}
|
||||
|
||||
$reflectionProperty = $reflectionClass->getProperty(static::$primaryField['internal']);
|
||||
$reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
|
||||
|
||||
// todo: can't i just set it accessible anyways and not set it to private afterwards?
|
||||
if (!($accessible = $reflectionProperty->isPublic())) {
|
||||
|
|
@ -824,17 +825,13 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
public function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL)
|
||||
{
|
||||
if (!isset(static::$createdAt) || !isset(static::$columns[static::$createdAt])) {
|
||||
throw new \BadMethodCallException('Method "' . __METHOD__ . '" is not supported.');
|
||||
}
|
||||
|
||||
$query = $query ?? new Builder($this->db);
|
||||
$query->prefix($this->db->getPrefix())
|
||||
->select('*')
|
||||
->from(static::$table)
|
||||
->limit($limit); /* todo: limit is not working, setting this to 2 doesn't have any effect!!! */
|
||||
|
||||
if (isset(static::$createdAt)) {
|
||||
if (!empty(static::$createdAt)) {
|
||||
$query->orderBy(static::$table . '.' . static::$columns[static::$createdAt]['name'], 'DESC');
|
||||
} else {
|
||||
$query->orderBy(static::$table . '.' . static::$columns[static::$primaryField]['name'], 'DESC');
|
||||
|
|
@ -844,9 +841,6 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
$sth->execute();
|
||||
|
||||
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
/* todo: if limit get's used this has to call populateIterable */
|
||||
|
||||
$obj = $this->populateIterable(is_bool($results) ? [] : $results);
|
||||
|
||||
$this->fillRelations($obj, $relations);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
|
|
@ -29,7 +28,7 @@ use phpOMS\Datatypes\Enum;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ISO4217DecimalEnum extends Enum
|
||||
class ISO4217NumEnum extends Enum
|
||||
{
|
||||
const C_AED = '784';
|
||||
const C_AFN = '971';
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ class Money implements \Serializable
|
|||
*/
|
||||
public function setString(string $value)
|
||||
{
|
||||
$this->value = self::toInt($value, $this->decimal);
|
||||
$this->value = self::toInt($value, $this->decimal, $this->thousands);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,27 +134,27 @@ class Money implements \Serializable
|
|||
*
|
||||
* @param string $value Money value
|
||||
* @param string $decimal Decimal character
|
||||
* @param string $thousands Thousands character
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function toInt(string $value, string $decimal = ',') : int
|
||||
public static function toInt(string $value, string $decimal = ',', string $thousands = '.') : int
|
||||
{
|
||||
$split = explode($value, $decimal);
|
||||
|
||||
$left = '';
|
||||
$left = $split[0];
|
||||
$left = str_replace($this->thousands, '', $left);
|
||||
$left = str_replace($thousands, '', $left);
|
||||
|
||||
$rigth = '';
|
||||
$right = '';
|
||||
if(count($split) > 1) {
|
||||
$right = $split[1];
|
||||
}
|
||||
|
||||
$right = substr($right, 0, -self::MAX_DECIMALS);
|
||||
$this->value = (int) $left * 100000 + (int) $right;
|
||||
return (int) $left * 100000 + (int) $right;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -169,16 +169,16 @@ class Money implements \Serializable
|
|||
*/
|
||||
public function getAmount(int $decimals = 2) : string
|
||||
{
|
||||
if($decimals > ($dec = ISO4217DecimalEnum::${'C_' . strtoupper($this->currency)})) {
|
||||
if($decimals > ($dec = constant('\phpOMS\Localization\ISO4217DecimalEnum::C_' . strtoupper($this->currency)))) {
|
||||
$decimals = $dec ;
|
||||
}
|
||||
|
||||
$value = (string) round($value, - self::MAX_DECIMALS + $this->decimals);
|
||||
$value = (string) round($this->value, - self::MAX_DECIMALS + $decimals);
|
||||
|
||||
$left = substr($value, 0, -self::MAX_DECIMALS);
|
||||
$right = substr($value, -self::MAX_DECIMALS);
|
||||
|
||||
return ($decimals > 0) : number_format($left, 0, $this->thousands, $this->decimal); . $this->decimal . $right : (string) $left;
|
||||
return ($decimals > 0) ? number_format($left, 0, $this->thousands, $this->decimal) . $this->decimal . $right : (string) $left;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -194,7 +194,7 @@ class Money implements \Serializable
|
|||
public function add($value)
|
||||
{
|
||||
if(is_string($value) || is_float($value)) {
|
||||
$this->value += self::toInt((string) $value);
|
||||
$this->value += self::toInt((string) $value, $this->decimal, $this->thousands);
|
||||
} elseif(is_int($value)) {
|
||||
$this->value += $value;
|
||||
} elseif($value instanceof Money) {
|
||||
|
|
@ -215,7 +215,7 @@ class Money implements \Serializable
|
|||
public function sub($value)
|
||||
{
|
||||
if(is_string($value) || is_float($value)) {
|
||||
$this->value -= self::toInt((string) $value);
|
||||
$this->value -= self::toInt((string) $value, $this->decimal, $this->thousands);
|
||||
} elseif(is_int($value)) {
|
||||
$this->value -= $value;
|
||||
} elseif($value instanceof Money) {
|
||||
|
|
@ -253,7 +253,7 @@ class Money implements \Serializable
|
|||
public function div($value)
|
||||
{
|
||||
if(is_float($value) || is_int($value)) {
|
||||
$this->value = self::toInt((string) ($this->value / $value));
|
||||
$this->value = self::toInt((string) ($this->value / $value), $this->decimal, $this->thousands);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ class FileLogger implements LoggerInterface
|
|||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->fp !== false) {
|
||||
if (is_resource($this->fp)) {
|
||||
fclose($this->fp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class MultiMap implements \Countable
|
|||
$id = count($this->values);
|
||||
$inserted = false;
|
||||
|
||||
if ($this->keyType !== KeyType::MULTIPLE) {
|
||||
if ($this->keyType !== KeyType::SINGLE) {
|
||||
$keys = [implode($keys, ':')];
|
||||
}
|
||||
|
||||
|
|
@ -494,6 +494,8 @@ class MultiMap implements \Countable
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $siblings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -510,9 +512,9 @@ class MultiMap implements \Countable
|
|||
{
|
||||
if ($this->orderType === OrderType::LOOSE) {
|
||||
return Permutation::permut($key);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user