diff --git a/src/Expression/Boolean/Not.php b/src/Expression/Boolean/Not.php new file mode 100644 index 00000000..3db76654 --- /dev/null +++ b/src/Expression/Boolean/Not.php @@ -0,0 +1,42 @@ +expression = $expression; + } + + public function describe(ClassDescription $theClass, string $because): Description + { + return new Description('must NOT ('.$this->expression->describe($theClass, '')->toString().')', $because); + } + + public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void + { + $newViolations = new Violations(); + $this->expression->evaluate($theClass, $newViolations, $because); + if (0 !== $newViolations->count()) { + return; + } + + $violations->add(Violation::create( + $theClass->getFQCN(), + ViolationMessage::selfExplanatory($this->describe($theClass, $because)) + )); + } +} diff --git a/tests/Unit/Expressions/Boolean/NotTest.php b/tests/Unit/Expressions/Boolean/NotTest.php new file mode 100644 index 00000000..ac844d8a --- /dev/null +++ b/tests/Unit/Expressions/Boolean/NotTest.php @@ -0,0 +1,59 @@ +describe($classDescription, $because)->toString(); + + $violations = new Violations(); + $isNotInterface->evaluate($classDescription, $violations, $because); + self::assertNotEquals(0, $violations->count()); + + $this->assertEquals('must NOT (HappyIsland should be an interface) because we want to add this rule for our software', $violationError); + } + + public function test_it_should_return_true_if_is_not_interface(): void + { + $isNotInterface = new Not(new IsInterface()); + $classDescription = new ClassDescription( + FullyQualifiedClassName::fromString('HappyIsland'), + [], + [], + null, + false, + false, + false, + false, + false + ); + $because = 'we want to add this rule for our software'; + $violations = new Violations(); + $isNotInterface->evaluate($classDescription, $violations, $because); + self::assertEquals(0, $violations->count()); + } +}