Ei kuvausta

FeatureMatcherTest.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Hamcrest;
  3. class Thingy
  4. {
  5. private $_result;
  6. public function __construct($result)
  7. {
  8. $this->_result = $result;
  9. }
  10. public function getResult()
  11. {
  12. return $this->_result;
  13. }
  14. }
  15. /* Test-specific subclass only */
  16. class ResultMatcher extends \Hamcrest\FeatureMatcher
  17. {
  18. public function __construct()
  19. {
  20. parent::__construct(self::TYPE_ANY, null, equalTo('bar'), 'Thingy with result', 'result');
  21. }
  22. public function featureValueOf($actual)
  23. {
  24. if ($actual instanceof \Hamcrest\Thingy) {
  25. return $actual->getResult();
  26. }
  27. }
  28. }
  29. class FeatureMatcherTest extends \Hamcrest\AbstractMatcherTest
  30. {
  31. private $_resultMatcher;
  32. protected function setUp()
  33. {
  34. $this->_resultMatcher = $this->_resultMatcher();
  35. }
  36. protected function createMatcher()
  37. {
  38. return $this->_resultMatcher();
  39. }
  40. public function testMatchesPartOfAnObject()
  41. {
  42. $this->assertMatches($this->_resultMatcher, new \Hamcrest\Thingy('bar'), 'feature');
  43. $this->assertDescription('Thingy with result "bar"', $this->_resultMatcher);
  44. }
  45. public function testMismatchesPartOfAnObject()
  46. {
  47. $this->assertMismatchDescription(
  48. 'result was "foo"',
  49. $this->_resultMatcher,
  50. new \Hamcrest\Thingy('foo')
  51. );
  52. }
  53. public function testDoesNotGenerateNoticesForNull()
  54. {
  55. $this->assertMismatchDescription('result was null', $this->_resultMatcher, null);
  56. }
  57. // -- Creation Methods
  58. private function _resultMatcher()
  59. {
  60. return new \Hamcrest\ResultMatcher();
  61. }
  62. }