|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Coduo\PHPMatcher\Tests\PHPUnit; |
| 4 | + |
| 5 | +use Coduo\PHPMatcher\PHPUnit\PHPMatcherConstraint; |
| 6 | + |
| 7 | +class PHPMatcherConstraintTest extends \PHPUnit_Framework_TestCase |
| 8 | +{ |
| 9 | + public function test_it_is_a_phpunit_constraint() |
| 10 | + { |
| 11 | + $this->assertInstanceOf('PHPUnit_Framework_Constraint', new PHPMatcherConstraint('@string@')); |
| 12 | + } |
| 13 | + |
| 14 | + public function test_it_returns_true_if_a_value_matches_the_pattern() |
| 15 | + { |
| 16 | + $constraint = new PHPMatcherConstraint('@string@'); |
| 17 | + |
| 18 | + $this->assertTrue($constraint->evaluate('foo', '', true)); |
| 19 | + } |
| 20 | + |
| 21 | + public function test_it_returns_false_if_a_value_does_not_match_the_pattern() |
| 22 | + { |
| 23 | + $constraint = new PHPMatcherConstraint('@string@'); |
| 24 | + |
| 25 | + $this->assertFalse($constraint->evaluate(42, '', true)); |
| 26 | + } |
| 27 | + |
| 28 | + public function test_it_returns_false_if_a_pattern_is_not_a_string() |
| 29 | + { |
| 30 | + $constraint = new PHPMatcherConstraint(new \stdClass()); |
| 31 | + |
| 32 | + $this->assertFalse($constraint->evaluate('foo', '', true)); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @expectedException \PHPUnit_Framework_ExpectationFailedException |
| 37 | + * @expectedExceptionMessage Failed asserting that 42 matches the pattern |
| 38 | + */ |
| 39 | + public function test_it_sets_a_failure_description_if_not_given() |
| 40 | + { |
| 41 | + $constraint = new PHPMatcherConstraint('@string@'); |
| 42 | + |
| 43 | + $this->assertFalse($constraint->evaluate(42)); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * @expectedException \PHPUnit_Framework_ExpectationFailedException |
| 48 | + * @expectedExceptionMessage integer "42" is not a valid string |
| 49 | + */ |
| 50 | + public function test_it_sets_additional_failure_description() |
| 51 | + { |
| 52 | + $constraint = new PHPMatcherConstraint('@string@'); |
| 53 | + |
| 54 | + $this->assertFalse($constraint->evaluate(42)); |
| 55 | + } |
| 56 | +} |
0 commit comments