PropertyMatcherTest.php 948 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace DeepCopyTest\Matcher;
  3. use DeepCopy\Matcher\PropertyMatcher;
  4. use PHPUnit\Framework\TestCase;
  5. /**
  6. * @covers \DeepCopy\Matcher\PropertyMatcher
  7. */
  8. class PropertyMatcherTest extends TestCase
  9. {
  10. /**
  11. * @dataProvider providePairs
  12. */
  13. public function test_it_matches_the_given_objects($object, $prop, $expected)
  14. {
  15. $matcher = new PropertyMatcher(X::class, 'foo');
  16. $actual = $matcher->matches($object, $prop);
  17. $this->assertEquals($expected, $actual);
  18. }
  19. public function providePairs()
  20. {
  21. return [
  22. 'matching case' => [new X(), 'foo', true],
  23. 'match class, non matching prop' => [new X(), 'bar', false],
  24. 'match class, unknown prop' => [new X(), 'unknown', false],
  25. 'non matching class, matching prop' => [new Y(), 'unknown', false],
  26. ];
  27. }
  28. }
  29. class X
  30. {
  31. public $foo;
  32. public $bar;
  33. }
  34. class Y
  35. {
  36. public $foo;
  37. }