From 804e1fa71d8e44276d19fba50c348a42e1ec920b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 24 Oct 2021 13:18:08 +0200 Subject: [PATCH] get overall coverage to 76% --- Models/Balance.php | 18 +++++++ Models/CostCenter.php | 20 ++++++++ Models/CostObject.php | 20 ++++++++ Models/Creditor.php | 19 ++++++++ Models/Debitor.php | 19 ++++++++ .../Api/ApiControllerAccountTrait.php | 8 ++-- tests/Models/BalanceTest.php | 14 ++++++ tests/Models/BatchPostingTest.php | 47 +++++++++++++++++++ tests/Models/CostCenterTest.php | 18 +++++++ tests/Models/CostObjectTest.php | 36 ++++++++++---- tests/Models/CreditorTest.php | 15 ++++++ tests/Models/DebitorTest.php | 21 +++++++-- tests/Models/NullCostCenter.php | 42 ----------------- tests/Models/NullCostObject.php | 42 ----------------- 14 files changed, 239 insertions(+), 100 deletions(-) create mode 100644 tests/Models/BatchPostingTest.php delete mode 100644 tests/Models/NullCostCenter.php delete mode 100644 tests/Models/NullCostObject.php diff --git a/Models/Balance.php b/Models/Balance.php index b6e2f3a..39e38b0 100755 --- a/Models/Balance.php +++ b/Models/Balance.php @@ -69,4 +69,22 @@ class Balance { return $this->id; } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/Models/CostCenter.php b/Models/CostCenter.php index b6bae7f..e9a1ee8 100755 --- a/Models/CostCenter.php +++ b/Models/CostCenter.php @@ -77,4 +77,24 @@ class CostCenter { return $this->id; } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'code' => $this->code, + 'parent' => $this->parent, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/Models/CostObject.php b/Models/CostObject.php index f759d65..be0626c 100755 --- a/Models/CostObject.php +++ b/Models/CostObject.php @@ -77,4 +77,24 @@ class CostObject { return $this->id; } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'code' => $this->code, + 'parent' => $this->parent, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/Models/Creditor.php b/Models/Creditor.php index bf648d9..a0b2c16 100755 --- a/Models/Creditor.php +++ b/Models/Creditor.php @@ -53,4 +53,23 @@ class Creditor { return $this->id; } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'account' => $this->account, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/Models/Debitor.php b/Models/Debitor.php index 88245e7..ec8364b 100755 --- a/Models/Debitor.php +++ b/Models/Debitor.php @@ -53,4 +53,23 @@ class Debitor { return $this->id; } + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'account' => $this->account, + ]; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } } diff --git a/tests/Controller/Api/ApiControllerAccountTrait.php b/tests/Controller/Api/ApiControllerAccountTrait.php index bcf7a1c..8bb9f13 100644 --- a/tests/Controller/Api/ApiControllerAccountTrait.php +++ b/tests/Controller/Api/ApiControllerAccountTrait.php @@ -27,7 +27,7 @@ trait ApiControllerAccountTrait */ public function testApiAccountCreate() : void { - $response = new HttpResponse(); + $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); $request->header->account = 1; @@ -45,7 +45,7 @@ trait ApiControllerAccountTrait */ public function testApiAccountCreateInvalid() : void { - $response = new HttpResponse(); + $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); $request->header->account = 1; @@ -61,7 +61,7 @@ trait ApiControllerAccountTrait */ public function testApiAccountUpdate() : void { - $response = new HttpResponse(); + $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); $request->header->account = 1; @@ -79,7 +79,7 @@ trait ApiControllerAccountTrait */ public function testApiAccountUpdateInvalid() : void { - $response = new HttpResponse(); + $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); $request->header->account = 1; diff --git a/tests/Models/BalanceTest.php b/tests/Models/BalanceTest.php index 1868f96..4917bff 100644 --- a/tests/Models/BalanceTest.php +++ b/tests/Models/BalanceTest.php @@ -39,4 +39,18 @@ final class BalanceTest extends \PHPUnit\Framework\TestCase { self::assertEquals(0, $this->balance->getId()); } + + /** + * @covers Modules\Accounting\Models\Balance + * @group module + */ + public function testSerialize() : void + { + self::assertEquals( + [ + 'id' => 0, + ], + $this->balance->jsonSerialize() + ); + } } diff --git a/tests/Models/BatchPostingTest.php b/tests/Models/BatchPostingTest.php new file mode 100644 index 0000000..7ab9306 --- /dev/null +++ b/tests/Models/BatchPostingTest.php @@ -0,0 +1,47 @@ +batch = new BatchPosting(); + } + + /** + * @covers Modules\Accounting\Models\BatchPosting + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->batch->getId()); + self::assertEquals(0, $this->batch->creator); + self::assertEquals('', $this->batch->description); + self::assertEquals(0, $this->batch->count()); + self::assertEquals(null, $this->batch->getPosting(1)); + self::assertInstanceOf('\DateTimeImmutable', $this->batch->created); + } +} diff --git a/tests/Models/CostCenterTest.php b/tests/Models/CostCenterTest.php index 424a782..2301920 100755 --- a/tests/Models/CostCenterTest.php +++ b/tests/Models/CostCenterTest.php @@ -61,4 +61,22 @@ final class CostCenterTest extends \PHPUnit\Framework\TestCase $this->cc->parent = 1; self::assertEquals(1, $this->cc->parent); } + + /** + * @covers Modules\Accounting\Models\CostCenter + * @group module + */ + public function testSerialize() : void + { + $this->cc->code = '123'; + + self::assertEquals( + [ + 'id' => 0, + 'code' => '123', + 'parent' => null, + ], + $this->cc->jsonSerialize() + ); + } } diff --git a/tests/Models/CostObjectTest.php b/tests/Models/CostObjectTest.php index 78a92ae..a74f3a5 100755 --- a/tests/Models/CostObjectTest.php +++ b/tests/Models/CostObjectTest.php @@ -21,14 +21,14 @@ use Modules\Accounting\Models\CostObject; */ final class CostObjectTest extends \PHPUnit\Framework\TestCase { - private CostObject $cc; + private CostObject $co; /** * {@inheritdoc} */ protected function setUp() : void { - $this->cc = new CostObject(); + $this->co = new CostObject(); } /** @@ -37,9 +37,9 @@ final class CostObjectTest extends \PHPUnit\Framework\TestCase */ public function testDefault() : void { - self::assertEquals(0, $this->cc->getId()); - self::assertEquals('', $this->cc->code); - self::assertNull($this->cc->parent); + self::assertEquals(0, $this->co->getId()); + self::assertEquals('', $this->co->code); + self::assertNull($this->co->parent); } /** @@ -48,8 +48,8 @@ final class CostObjectTest extends \PHPUnit\Framework\TestCase */ public function testCodeInputOutput() : void { - $this->cc->code = 'TestCode'; - self::assertEquals('TestCode', $this->cc->code); + $this->co->code = 'TestCode'; + self::assertEquals('TestCode', $this->co->code); } /** @@ -58,7 +58,25 @@ final class CostObjectTest extends \PHPUnit\Framework\TestCase */ public function testParentInputOutput() : void { - $this->cc->parent = 1; - self::assertEquals(1, $this->cc->parent); + $this->co->parent = 1; + self::assertEquals(1, $this->co->parent); + } + + /** + * @covers Modules\Accounting\Models\CostObject + * @group module + */ + public function testSerialize() : void + { + $this->co->code = '123'; + + self::assertEquals( + [ + 'id' => 0, + 'code' => '123', + 'parent' => null, + ], + $this->co->jsonSerialize() + ); } } diff --git a/tests/Models/CreditorTest.php b/tests/Models/CreditorTest.php index cef7821..d53658b 100644 --- a/tests/Models/CreditorTest.php +++ b/tests/Models/CreditorTest.php @@ -39,4 +39,19 @@ final class CreditorTest extends \PHPUnit\Framework\TestCase { self::assertEquals(0, $this->creditor->getId()); } + + /** + * @covers Modules\Accounting\Models\Creditor + * @group module + */ + public function testSerialize() : void + { + self::assertEquals( + [ + 'id' => 0, + 'account' => null, + ], + $this->creditor->jsonSerialize() + ); + } } diff --git a/tests/Models/DebitorTest.php b/tests/Models/DebitorTest.php index 4dc5407..0f7f69c 100644 --- a/tests/Models/DebitorTest.php +++ b/tests/Models/DebitorTest.php @@ -21,14 +21,14 @@ use Modules\Accounting\Models\Debitor; */ final class DebitorTest extends \PHPUnit\Framework\TestCase { - private Debitor $creditor; + private Debitor $debitor; /** * {@inheritdoc} */ protected function setUp() : void { - $this->creditor = new Debitor(); + $this->debitor = new Debitor(); } /** @@ -37,6 +37,21 @@ final class DebitorTest extends \PHPUnit\Framework\TestCase */ public function testDefault() : void { - self::assertEquals(0, $this->creditor->getId()); + self::assertEquals(0, $this->debitor->getId()); + } + + /** + * @covers Modules\Accounting\Models\Debitor + * @group module + */ + public function testSerialize() : void + { + self::assertEquals( + [ + 'id' => 0, + 'account' => null, + ], + $this->debitor->jsonSerialize() + ); } } diff --git a/tests/Models/NullCostCenter.php b/tests/Models/NullCostCenter.php deleted file mode 100644 index a9a42b7..0000000 --- a/tests/Models/NullCostCenter.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/NullCostObject.php b/tests/Models/NullCostObject.php deleted file mode 100644 index a41cbfb..0000000 --- a/tests/Models/NullCostObject.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -}