From a3d10ac9af5d038fd4ea7450cc65e4cfb6b20755 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Tue, 6 Nov 2018 20:56:54 +0100 Subject: [PATCH] Implemented tests for condition --- .../src/Entity/Attribut/ConditionAttribut.php | 2 +- .../Entity/Attribut/ConditionAttributTest.php | 38 +++++++++++++++++++ .../tests/Unit/Entity/Meta/RightTest.php | 12 +++++- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 application/tests/Unit/Entity/Attribut/ConditionAttributTest.php diff --git a/application/src/Entity/Attribut/ConditionAttribut.php b/application/src/Entity/Attribut/ConditionAttribut.php index e0eac6e..b477c98 100644 --- a/application/src/Entity/Attribut/ConditionAttribut.php +++ b/application/src/Entity/Attribut/ConditionAttribut.php @@ -26,6 +26,6 @@ trait ConditionAttribut public function hasCondition(): bool { - return $this->condition; + return $this->condition instanceof OperationInterface; } } diff --git a/application/tests/Unit/Entity/Attribut/ConditionAttributTest.php b/application/tests/Unit/Entity/Attribut/ConditionAttributTest.php new file mode 100644 index 0000000..08ac42e --- /dev/null +++ b/application/tests/Unit/Entity/Attribut/ConditionAttributTest.php @@ -0,0 +1,38 @@ +condition = new class() implements ConditionAttributInterface { + use ConditionAttribut; + }; + } + + public function testConstructor(): void + { + $this->expectException(\TypeError::class); + $this->condition->getCondition(); + } + + public function testAccessors(): void + { + $this->assertEquals(false, $this->condition->hasCondition()); + $condition = $this->createMock(OperationInterface::class); + $this->assertNull($this->condition->setCondition($condition)); + $this->assertEquals(true, $this->condition->hasCondition()); + $this->assertEquals($condition, $this->condition->getCondition()); + } +} diff --git a/application/tests/Unit/Entity/Meta/RightTest.php b/application/tests/Unit/Entity/Meta/RightTest.php index 40b4ab9..25bc18e 100644 --- a/application/tests/Unit/Entity/Meta/RightTest.php +++ b/application/tests/Unit/Entity/Meta/RightTest.php @@ -25,11 +25,21 @@ class RightTest extends TestCase $this->right = new Right(); } - public function testConstructor(): void + public function testConstructorGeneral(): void { $this->assertEquals($this->right, $this->right->getReciever()->getRight()); $this->expectException(\TypeError::class); $this->assertNull($this->right->getLaw()); + } + + public function testConstructorCondition() + { + $this->expectException(\TypeError::class); + $this->right->getCondition(); + } + + public function testConstructorType(): void + { $this->expectException(\TypeError::class); $this->assertNull($this->right->getType()); }