Skip to content

Commit

Permalink
Merge pull request #54 from koriym/tests
Browse files Browse the repository at this point in the history
add more tests for #53 and fix Not Matcher
  • Loading branch information
koriym committed May 27, 2015
2 parents e05722a + 8c29546 commit ebda1d3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Matcher/LogicalNotMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function matchesClass(\ReflectionClass $class, array $arguments)
{
list($matcher) = $arguments;
/* @var $matcher AbstractMatcher */
$isNot = ! $matcher->matchesClass($class, [$arguments]);
$isNot = ! $matcher->matchesClass($class, $matcher->getArguments());

return $isNot;
}
Expand Down
18 changes: 12 additions & 6 deletions tests/Fake/FakeMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@

class FakeMatcher extends AbstractMatcher
{
private $return;

public function __construct($return = true)
public function __construct($arg1 = true, $arg2 = true)
{
$this->return = $return;
$this->arguments = [$arg1, $arg2];
}

public function matchesClass(\ReflectionClass $class, array $arguments)
{
return $this->return;
if (isset($arguments[1])) {
return $arguments[0] && $arguments[1];
}

return $arguments[0];
}

public function matchesMethod(\ReflectionMethod $method, array $arguments)
{
return $this->return;
if (isset($arguments[1])) {
return $arguments[0] && $arguments[1];
}

return $arguments[0];
}
}
9 changes: 5 additions & 4 deletions tests/Matcher/LogicalAndMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@
namespace Ray\Aop\Matcher;

use Ray\Aop\FakeAnnotateClass;
use Ray\Aop\FakeClass;
use Ray\Aop\FakeMatcher;

class LogicalAndMatcherTest extends \PHPUnit_Framework_TestCase
{
public function testMatchesClass()
{
$class = new \ReflectionClass(FakeAnnotateClass::class);
$isMatched = (new LogicalAndMatcher)->matchesClass($class, [new FakeMatcher, new FakeMatcher]);
$isMatched = (new LogicalAndMatcher)->matchesClass($class, [new FakeMatcher(true, true), new FakeMatcher(true, true)]);

$this->assertTrue($isMatched);
}

public function testMatchesClassFalse()
{
$class = new \ReflectionClass(FakeAnnotateClass::class);
$isMatched = (new LogicalAndMatcher)->matchesClass($class, [new FakeMatcher, new FakeMatcher(false)]);
$isMatched = (new LogicalAndMatcher)->matchesClass($class, [new FakeMatcher(true, true), new FakeMatcher(true, false)]);

$this->assertFalse($isMatched);
}

public function testMatchesClassThreeConditions()
{
$class = new \ReflectionClass(FakeAnnotateClass::class);
$isMatched = (new LogicalAndMatcher)->matchesClass($class, [new FakeMatcher, new FakeMatcher, new FakeMatcher(false)]);
$isMatched = (new LogicalAndMatcher)->matchesClass($class, [new FakeMatcher(true, true), new FakeMatcher(true, true), new FakeMatcher(true, false)]);

$this->assertFalse($isMatched);
}

public function testMatchesMethod()
{
$method = new \ReflectionMethod(FakeAnnotateClass::class, 'getDouble');
$isMatched = (new LogicalAndMatcher)->matchesMethod($method, [new FakeMatcher, new FakeMatcher]);
$isMatched = (new LogicalAndMatcher)->matchesMethod($method, [new FakeMatcher(true, true), new FakeMatcher(true, true)]);

$this->assertTrue($isMatched);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Matcher/LogicalOrMathcerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Ray\Aop\FakeAnnotateClass;
use Ray\Aop\FakeMatcher;

class LogicalOrMathcerTest extends \PHPUnit_Framework_TestCase
class LogicalOrMatcherTest extends \PHPUnit_Framework_TestCase
{
public function testMatchesClass()
{
Expand Down Expand Up @@ -33,7 +33,7 @@ public function testMatchesClassThreeConditions()
public function testLogicalOrNotMatch()
{
$class = new \ReflectionClass(FakeAnnotateClass::class);
$isMatched = (new LogicalOrMatcher)->matchesClass($class, [new FakeMatcher(false), new FakeMatcher(false), new FakeMatcher(false)]);
$isMatched = (new LogicalOrMatcher)->matchesClass($class, [new FakeMatcher(true, false), new FakeMatcher(true, false), new FakeMatcher(true, false)]);
$this->assertFalse($isMatched);
}

Expand Down

0 comments on commit ebda1d3

Please sign in to comment.