-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
); | ||
} | ||
} |