Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] OrSpecification implementation #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Computaria/Sphecific/OrSpecification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Computaria\Sphecific;

class OrSpecification implements SpecificationInterface
{
private $leftOperand = null;
private $rightOperand = null;

public function __construct(SpecificationInterface $leftOperand, SpecificationInterface $rightOperand)
{
$this->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();
}
}
48 changes: 48 additions & 0 deletions tests/Computaria/Sphecific/OrSpecificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Computaria\Sphecific;

class OrSpecficationTest extends \PHPUnit_Framework_TestCase
{
private $onlyObjectsSpecification = null;
private $sizeSpecification = null;

protected function setUp()
{
$this->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));
}
}