1<?php
2/*
3 * This file is part of the Comparator package.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11namespace SebastianBergmann\Comparator;
12
13use SplObjectStorage;
14use stdClass;
15
16/**
17 * @coversDefaultClass SebastianBergmann\Comparator\SplObjectStorageComparator
18 *
19 */
20class SplObjectStorageComparatorTest extends \PHPUnit_Framework_TestCase
21{
22    private $comparator;
23
24    protected function setUp()
25    {
26        $this->comparator = new SplObjectStorageComparator;
27    }
28
29    public function acceptsFailsProvider()
30    {
31        return array(
32          array(new SplObjectStorage, new stdClass),
33          array(new stdClass, new SplObjectStorage),
34          array(new stdClass, new stdClass)
35        );
36    }
37
38    public function assertEqualsSucceedsProvider()
39    {
40        $object1 = new stdClass();
41        $object2 = new stdClass();
42
43        $storage1 = new SplObjectStorage();
44        $storage2 = new SplObjectStorage();
45
46        $storage3 = new SplObjectStorage();
47        $storage3->attach($object1);
48        $storage3->attach($object2);
49
50        $storage4 = new SplObjectStorage();
51        $storage4->attach($object2);
52        $storage4->attach($object1);
53
54        return array(
55          array($storage1, $storage1),
56          array($storage1, $storage2),
57          array($storage3, $storage3),
58          array($storage3, $storage4)
59        );
60    }
61
62    public function assertEqualsFailsProvider()
63    {
64        $object1 = new stdClass;
65        $object2 = new stdClass;
66
67        $storage1 = new SplObjectStorage;
68
69        $storage2 = new SplObjectStorage;
70        $storage2->attach($object1);
71
72        $storage3 = new SplObjectStorage;
73        $storage3->attach($object2);
74        $storage3->attach($object1);
75
76        return array(
77          array($storage1, $storage2),
78          array($storage1, $storage3),
79          array($storage2, $storage3),
80        );
81    }
82
83    /**
84     * @covers  ::accepts
85     */
86    public function testAcceptsSucceeds()
87    {
88        $this->assertTrue(
89          $this->comparator->accepts(
90            new SplObjectStorage,
91            new SplObjectStorage
92          )
93        );
94    }
95
96    /**
97     * @covers       ::accepts
98     * @dataProvider acceptsFailsProvider
99     */
100    public function testAcceptsFails($expected, $actual)
101    {
102        $this->assertFalse(
103          $this->comparator->accepts($expected, $actual)
104        );
105    }
106
107    /**
108     * @covers       ::assertEquals
109     * @dataProvider assertEqualsSucceedsProvider
110     */
111    public function testAssertEqualsSucceeds($expected, $actual)
112    {
113        $exception = null;
114
115        try {
116            $this->comparator->assertEquals($expected, $actual);
117        }
118
119        catch (ComparisonFailure $exception) {
120        }
121
122        $this->assertNull($exception, 'Unexpected ComparisonFailure');
123    }
124
125    /**
126     * @covers       ::assertEquals
127     * @dataProvider assertEqualsFailsProvider
128     */
129    public function testAssertEqualsFails($expected, $actual)
130    {
131        $this->setExpectedException(
132          'SebastianBergmann\\Comparator\\ComparisonFailure',
133          'Failed asserting that two objects are equal.'
134        );
135        $this->comparator->assertEquals($expected, $actual);
136    }
137}
138