From fc7cf9cb9c6020c554d5b3443e6540fab96aceda Mon Sep 17 00:00:00 2001 From: Nelson Senna Date: Mon, 30 Nov 2015 22:43:08 -0200 Subject: [PATCH] OrSpecification implementation --- src/Computaria/Sphecific/OrSpecification.php | 25 ++++++++++ .../Sphecific/OrSpecificationTest.php | 48 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/Computaria/Sphecific/OrSpecification.php create mode 100644 tests/Computaria/Sphecific/OrSpecificationTest.php diff --git a/src/Computaria/Sphecific/OrSpecification.php b/src/Computaria/Sphecific/OrSpecification.php new file mode 100644 index 0000000..7d41014 --- /dev/null +++ b/src/Computaria/Sphecific/OrSpecification.php @@ -0,0 +1,25 @@ +leftOperand = $leftOperand; + $this->rightOperand = $rightOperand; + } + + public function isSatisfiedBy($object) + { + return ($this->leftOperand->isSatisfiedBy($object) || $this->rightOperand->isSatisfiedBy($object)); + } + + public function whyWasNotSatisfied() + { + return $this->leftOperand->whyWasNotSatisfied() . " and " . $this->rightOperand->whyWasNotSatisfied(); + } +} diff --git a/tests/Computaria/Sphecific/OrSpecificationTest.php b/tests/Computaria/Sphecific/OrSpecificationTest.php new file mode 100644 index 0000000..10e5113 --- /dev/null +++ b/tests/Computaria/Sphecific/OrSpecificationTest.php @@ -0,0 +1,48 @@ +onlyObjectsSpecification = new \Test\Stub\OnlyObjectsSpecification; + $this->sizeSpecification = new \Test\Stub\MinimumArraySizeSpecification; + } + + protected function tearDown() + { + $this->composite = null; + $this->onlyObjectsSpecification = null; + } + + public function testIsSatisfiedWhenBothOperandsAreSatisfied() + { + $orSpecification = new OrSpecification($this->onlyObjectsSpecification, $this->sizeSpecification); + + $arrayObject = new \ArrayObject(array(1, 2)); + + $this->assertTrue($orSpecification->isSatisfiedBy($arrayObject)); + } + + public function testIsSatisfiedWhenOneOperandsIsNotSatisfied() + { + $orSpecification = new OrSpecification($this->onlyObjectsSpecification, $this->sizeSpecification); + + $arrayObject = new \ArrayObject(array(1)); + + $this->assertTrue($orSpecification->isSatisfiedBy($arrayObject)); + } + + public function testIsNotSatisfiedWhenBothOperandsAreNotSatisfied() + { + $orSpecification = new OrSpecification($this->onlyObjectsSpecification, $this->sizeSpecification); + + $arrayObject = array(); + + $this->assertFalse($orSpecification->isSatisfiedBy($arrayObject)); + } +}