annotate vendor/sabre/vobject/tests/VObject/TestCase.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 class TestCase extends \PHPUnit_Framework_TestCase {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 * This method tests wether two vcards or icalendar objects are
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 * semantically identical.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * It supports objects being supplied as strings, streams or
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * Sabre\VObject\Component instances.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 * PRODID is removed from both objects as this is often variable.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 * @param resource|string|Component $expected
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 * @param resource|string|Component $actual
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 * @param string $message
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 function assertVObjEquals($expected, $actual, $message = '') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 $self = $this;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 $getObj = function($input) use ($self) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 if (is_resource($input)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 $input = stream_get_contents($input);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 if (is_string($input)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 $input = Reader::read($input);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 if (!$input instanceof Component) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 $this->fail('Input must be a string, stream or VObject component');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 unset($input->PRODID);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 return $input;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 };
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 $expected = $getObj($expected);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 $actual = $getObj($actual);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 $this->assertEquals(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 $expected->serialize(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 $actual->serialize(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 $message
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 }