test fixes

This commit is contained in:
Dennis Eichhorn 2022-11-25 23:55:35 +01:00
parent a813e1677a
commit d6c21e0aeb
4 changed files with 33 additions and 44 deletions

View File

@ -227,7 +227,10 @@ final class ApiController extends Controller
{
$val = [];
if (($val['client/supplier'] = (empty($request->getData('client'))
&& (empty($request->getData('supplier')) && ((int) ($request->getData('supplier') ?? -1) !== 0))))
&& (empty($request->getData('supplier'))
&& ((int) ($request->getData('supplier') ?? -1) !== 0)
)))
|| ($val['type'] = (empty($request->getData('type'))))
) {
return $val;
}

View File

@ -61,10 +61,10 @@ class Bill implements \JsonSerializable
/**
* Bill type.
*
* @var int|BillType
* @var BillType
* @since 1.0.0
*/
public int | BillType $type = 0;
public BillType $type;
/**
* Bill status.
@ -428,6 +428,7 @@ class Bill implements \JsonSerializable
$this->performanceDate = new \DateTime();
$this->createdBy = new NullAccount();
$this->referral = new NullAccount();
$this->type = new NullBillType();
}
/**
@ -486,32 +487,6 @@ class Bill implements \JsonSerializable
return $this->number;
}
/**
* Get type
*
* @return int | BillType
*
* @since 1.0.0
*/
public function getType() : int | BillType
{
return $this->type;
}
/**
* Set type
*
* @param int|BillType $type Type
*
* @return void
*
* @since 1.0.0
*/
public function setType(int | BillType $type) : void
{
$this->type = $type;
}
/**
* Get status
*
@ -707,7 +682,7 @@ class Bill implements \JsonSerializable
{
$files = [];
foreach ($this->media as $file) {
if ($file->type->getId() === $type) {
if ($file->type !== null && $file->type->getId() === $type) {
$files[] = $file;
}
}

View File

@ -26,7 +26,7 @@ use phpOMS\Localization\ISO639x1Enum;
* @link https://karaka.app
* @since 1.0.0
*/
class BillType
class BillType implements \JsonSerializable
{
/**
* Id
@ -108,4 +108,24 @@ class BillType
{
return $this->l11n instanceof BillTypeL11n ? $this->l11n->name : $this->l11n;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'numberFormat' => $this->numberFormat,
'transferType' => $this->transferType,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

View File

@ -18,6 +18,7 @@ use Modules\Billing\Models\Bill;
use Modules\Billing\Models\BillElement;
use Modules\Billing\Models\BillStatus;
use Modules\Billing\Models\BillType;
use Modules\Billing\Models\NullBillType;
use Modules\Media\Models\Media;
use phpOMS\Localization\ISO4217CharEnum;
@ -46,7 +47,7 @@ final class BillTest extends \PHPUnit\Framework\TestCase
self::assertEquals('', $this->bill->number);
self::assertEquals('', $this->bill->referralName);
self::assertEquals('', $this->bill->info);
self::assertEquals(0, $this->bill->type);
self::assertInstanceOf('\Modules\Billing\Models\NullBillType', $this->bill->type);
self::assertInstanceOf('\DateTimeImmutable', $this->bill->createdAt);
self::assertInstanceOf('\DateTime', $this->bill->performanceDate);
self::assertNull($this->bill->send);
@ -97,16 +98,6 @@ final class BillTest extends \PHPUnit\Framework\TestCase
self::assertEquals(\date('Y') . \date('m') . \date('d') . '-0', $this->bill->getNumber());
}
/**
* @covers Modules\Billing\Models\Bill
* @group module
*/
public function testTypeInputOutput() : void
{
$this->bill->setType(new BillType());
self::assertInstanceOf('\Modules\Billing\Models\BillType', $this->bill->getType());
}
/**
* @covers Modules\Billing\Models\Bill
* @group module
@ -176,7 +167,7 @@ final class BillTest extends \PHPUnit\Framework\TestCase
{
$this->bill->number = '123456';
$this->bill->numberFormat = '{y}';
$this->bill->type = 2;
$this->bill->type = new NullBillType(2);
$this->bill->shipTo = 'To';
$this->bill->shipFAO = 'FAO';
$this->bill->shipAddress = 'Address';
@ -195,7 +186,7 @@ final class BillTest extends \PHPUnit\Framework\TestCase
'id' => 0,
'number' => '123456',
'numberFormat' => '{y}',
'type' => 2,
'type' => $this->bill->type,
'shipTo' => 'To',
'shipFAO' => 'FAO',
'shipAddress' => 'Address',