Няма описание

AbstractMatcherTest.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Hamcrest;
  3. class UnknownType {
  4. }
  5. abstract class AbstractMatcherTest extends \PHPUnit_Framework_TestCase
  6. {
  7. const ARGUMENT_IGNORED = "ignored";
  8. const ANY_NON_NULL_ARGUMENT = "notnull";
  9. abstract protected function createMatcher();
  10. public function assertMatches(\Hamcrest\Matcher $matcher, $arg, $message)
  11. {
  12. $this->assertTrue($matcher->matches($arg), $message);
  13. }
  14. public function assertDoesNotMatch(\Hamcrest\Matcher $matcher, $arg, $message)
  15. {
  16. $this->assertFalse($matcher->matches($arg), $message);
  17. }
  18. public function assertDescription($expected, \Hamcrest\Matcher $matcher)
  19. {
  20. $description = new \Hamcrest\StringDescription();
  21. $description->appendDescriptionOf($matcher);
  22. $this->assertEquals($expected, (string) $description, 'Expected description');
  23. }
  24. public function assertMismatchDescription($expected, \Hamcrest\Matcher $matcher, $arg)
  25. {
  26. $description = new \Hamcrest\StringDescription();
  27. $this->assertFalse(
  28. $matcher->matches($arg),
  29. 'Precondtion: Matcher should not match item'
  30. );
  31. $matcher->describeMismatch($arg, $description);
  32. $this->assertEquals(
  33. $expected,
  34. (string) $description,
  35. 'Expected mismatch description'
  36. );
  37. }
  38. public function testIsNullSafe()
  39. {
  40. //Should not generate any notices
  41. $this->createMatcher()->matches(null);
  42. $this->createMatcher()->describeMismatch(
  43. null,
  44. new \Hamcrest\NullDescription()
  45. );
  46. }
  47. public function testCopesWithUnknownTypes()
  48. {
  49. //Should not generate any notices
  50. $this->createMatcher()->matches(new UnknownType());
  51. $this->createMatcher()->describeMismatch(
  52. new UnknownType(),
  53. new NullDescription()
  54. );
  55. }
  56. }