Skip to content

Commit

Permalink
Refactoring scalar matcher test
Browse files Browse the repository at this point in the history
  • Loading branch information
defrag committed Apr 16, 2014
1 parent babdb07 commit 3d19b39
Showing 1 changed file with 72 additions and 7 deletions.
79 changes: 72 additions & 7 deletions tests/JsonMatcher/ScalarMatcherTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,82 @@
<?php
namespace JsonMatcher\Tests;

use JsonMatcher\Matcher;
use JsonMatcher\Matcher\ScalarMatcher;

class ScalarMatcherTest extends \PHPUnit_Framework_TestCase
{
public function test_match_scalars()
/**
* @dataProvider positiveCanMatches
*/
public function test_positive_can_matches($pattern)
{
$matcher = new Matcher\ScalarMatcher();
$matcher = new ScalarMatcher();
$this->assertTrue($matcher->canMatch($pattern));
}

/**
* @dataProvider negativeCanMatches
*/
public function test_negative_can_matches($pattern)
{
$matcher = new ScalarMatcher();
$this->assertFalse($matcher->canMatch($pattern));
}

/**
* @dataProvider positiveMatches
*/
public function test_positive_matches($value, $pattern)
{
$matcher = new ScalarMatcher();
$this->assertTrue($matcher->match($value, $pattern));
}

/**
* @dataProvider negativeMatches
*/
public function test_negative_matches($value, $pattern)
{
$matcher = new ScalarMatcher();
$this->assertFalse($matcher->match($value, $pattern));
}

$this->assertTrue($matcher->match(1, 1));
$this->assertTrue($matcher->match("michal", "michal"));
$this->assertFalse($matcher->match(false, "false"));
$this->assertFalse($matcher->match(false, 0));
public static function negativeMatches()
{
return array(
array(false, "false"),
array(false, 0),
array(true, 1),
array("array", array()),
);
}

public static function positiveMatches()
{
return array(
array(1, 1),
array("michal", "michal"),
array(false, false),
array(6.66, 6.66),
);
}

public static function positiveCanMatches()
{
return array(
array(1),
array("michal"),
array(true),
array(false),
array(6.66),
);
}

public static function negativeCanMatches()
{
return array(
array(new \stdClass),
array(array())
);
}
}

0 comments on commit 3d19b39

Please sign in to comment.