From 13fe6009a5d52a8f3895ea4bf9e151173e44bcd4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 16 Nov 2021 00:05:43 +0100 Subject: [PATCH] cs fixes, bug fixes, code coverage --- CONTRIBUTING.md | 4 +-- Models/NullTagL11n.php | 12 +++++++++ Models/Tag.php | 29 +--------------------- tests/Models/NullTagL11nTest.php | 42 ++++++++++++++++++++++++++++++++ tests/Models/TagTest.php | 10 ++++---- 5 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 tests/Models/NullTagL11nTest.php diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cab9f5e..ad8944e 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,9 +12,7 @@ If you have a good idea for improvement feel free to create a new issue with all ### Issues -Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the `Project.md` file in the `Docs` repository. - -The issue information can be used to provide additional information such as priority, difficulty and type. For your first issue try to find a issue marked `[d:first]` or `[d:beginner]`. +Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the code marked with `@todo` or in the [PROJECT.md](https://github.com/Orange-Management/Docs/blob/master/Project/PROJECT.md) file. ### Code Style diff --git a/Models/NullTagL11n.php b/Models/NullTagL11n.php index a8b869e..c5f4b24 100755 --- a/Models/NullTagL11n.php +++ b/Models/NullTagL11n.php @@ -24,4 +24,16 @@ namespace Modules\Tag\Models; */ final class NullTagL11n extends TagL11n { + /** + * Constructor + * + * @param int $id Model id + * + * @since 1.0.0 + */ + public function __construct(int $id = 0) + { + $this->id = $id; + parent::__construct(); + } } diff --git a/Models/Tag.php b/Models/Tag.php index ae2f36a..8920964 100755 --- a/Models/Tag.php +++ b/Models/Tag.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace Modules\Tag\Models; use Modules\Admin\Models\Account; -use Modules\Admin\Models\NullAccount; use phpOMS\Contract\ArrayableInterface; use phpOMS\Localization\ISO639x1Enum; @@ -67,7 +66,7 @@ class Tag implements \JsonSerializable, ArrayableInterface * @var null|Account * @since 1.0.0 */ - protected ?Account $owner = null; + public ?Account $owner = null; /** * Tag type. @@ -77,32 +76,6 @@ class Tag implements \JsonSerializable, ArrayableInterface */ protected int $type = TagType::SINGLE; - /** - * Get created by - * - * @return Account - * - * @since 1.0.0 - */ - public function getOwner() : Account - { - return $this->owner ?? new NullAccount(); - } - - /** - * Set created by - * - * @param Account $id Created by - * - * @return void - * - * @since 1.0.0 - */ - public function setOwner(Account $id) : void - { - $this->owner = $id; - } - /** * Get type. * diff --git a/tests/Models/NullTagL11nTest.php b/tests/Models/NullTagL11nTest.php new file mode 100644 index 0000000..0be3211 --- /dev/null +++ b/tests/Models/NullTagL11nTest.php @@ -0,0 +1,42 @@ +getId()); + } +} diff --git a/tests/Models/TagTest.php b/tests/Models/TagTest.php index 402eec5..225a91a 100755 --- a/tests/Models/TagTest.php +++ b/tests/Models/TagTest.php @@ -41,7 +41,7 @@ final class TagTest extends \PHPUnit\Framework\TestCase public function testDefault() : void { self::assertEquals(0, $this->tag->getId()); - self::assertInstanceOf(NullAccount::class, $this->tag->getOwner()); + self::assertInstanceOf(NullAccount::class, $this->tag->owner); self::assertEquals(TagType::SINGLE, $this->tag->getType()); self::assertEquals('00000000', $this->tag->color); self::assertEquals('', $this->tag->getL11n()); @@ -69,8 +69,8 @@ final class TagTest extends \PHPUnit\Framework\TestCase */ public function testOwnerInputOutput() : void { - $this->tag->setOwner(new NullAccount(2)); - self::assertEquals(2, $this->tag->getOwner()->getId()); + $this->tag->owner = new NullAccount(2); + self::assertEquals(2, $this->tag->owner->getId()); } /** @@ -100,7 +100,7 @@ final class TagTest extends \PHPUnit\Framework\TestCase public function testSerialize() : void { $this->tag->setL11n($t = new TagL11n('Test')); - $this->tag->setOwner($a = new NullAccount(2)); + $this->tag->owner = new NullAccount(2); $this->tag->color = 'ffffffff'; $this->tag->setType(TagType::SHARED); @@ -110,7 +110,7 @@ final class TagTest extends \PHPUnit\Framework\TestCase 'title' => $t, 'color' => 'ffffffff', 'type' => TagType::SHARED, - 'owner' => $a, + 'owner' => $this->tag->owner, ], $this->tag->jsonSerialize() );