TestCase.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Sabre\VObject;
  3. class TestCase extends \PHPUnit_Framework_TestCase {
  4. /**
  5. * This method tests wether two vcards or icalendar objects are
  6. * semantically identical.
  7. *
  8. * It supports objects being supplied as strings, streams or
  9. * Sabre\VObject\Component instances.
  10. *
  11. * PRODID is removed from both objects as this is often variable.
  12. *
  13. * @param resource|string|Component $expected
  14. * @param resource|string|Component $actual
  15. * @param string $message
  16. */
  17. function assertVObjEquals($expected, $actual, $message = '') {
  18. $self = $this;
  19. $getObj = function($input) use ($self) {
  20. if (is_resource($input)) {
  21. $input = stream_get_contents($input);
  22. }
  23. if (is_string($input)) {
  24. $input = Reader::read($input);
  25. }
  26. if (!$input instanceof Component) {
  27. $this->fail('Input must be a string, stream or VObject component');
  28. }
  29. unset($input->PRODID);
  30. return $input;
  31. };
  32. $expected = $getObj($expected);
  33. $actual = $getObj($actual);
  34. $this->assertEquals(
  35. $expected->serialize(),
  36. $actual->serialize(),
  37. $message
  38. );
  39. }
  40. }