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
13/**
14 * @coversDefaultClass SebastianBergmann\Comparator\ResourceComparator
15 *
16 */
17class ResourceComparatorTest extends \PHPUnit_Framework_TestCase
18{
19    private $comparator;
20
21    protected function setUp()
22    {
23        $this->comparator = new ResourceComparator;
24    }
25
26    public function acceptsSucceedsProvider()
27    {
28        $tmpfile1 = tmpfile();
29        $tmpfile2 = tmpfile();
30
31        return array(
32          array($tmpfile1, $tmpfile1),
33          array($tmpfile2, $tmpfile2),
34          array($tmpfile1, $tmpfile2)
35        );
36    }
37
38    public function acceptsFailsProvider()
39    {
40        $tmpfile1 = tmpfile();
41
42        return array(
43          array($tmpfile1, null),
44          array(null, $tmpfile1),
45          array(null, null)
46        );
47    }
48
49    public function assertEqualsSucceedsProvider()
50    {
51        $tmpfile1 = tmpfile();
52        $tmpfile2 = tmpfile();
53
54        return array(
55          array($tmpfile1, $tmpfile1),
56          array($tmpfile2, $tmpfile2)
57        );
58    }
59
60    public function assertEqualsFailsProvider()
61    {
62        $tmpfile1 = tmpfile();
63        $tmpfile2 = tmpfile();
64
65        return array(
66          array($tmpfile1, $tmpfile2),
67          array($tmpfile2, $tmpfile1)
68        );
69    }
70
71    /**
72     * @covers       ::accepts
73     * @dataProvider acceptsSucceedsProvider
74     */
75    public function testAcceptsSucceeds($expected, $actual)
76    {
77        $this->assertTrue(
78          $this->comparator->accepts($expected, $actual)
79        );
80    }
81
82    /**
83     * @covers       ::accepts
84     * @dataProvider acceptsFailsProvider
85     */
86    public function testAcceptsFails($expected, $actual)
87    {
88        $this->assertFalse(
89          $this->comparator->accepts($expected, $actual)
90        );
91    }
92
93    /**
94     * @covers       ::assertEquals
95     * @dataProvider assertEqualsSucceedsProvider
96     */
97    public function testAssertEqualsSucceeds($expected, $actual)
98    {
99        $exception = null;
100
101        try {
102            $this->comparator->assertEquals($expected, $actual);
103        }
104
105        catch (ComparisonFailure $exception) {
106        }
107
108        $this->assertNull($exception, 'Unexpected ComparisonFailure');
109    }
110
111    /**
112     * @covers       ::assertEquals
113     * @dataProvider assertEqualsFailsProvider
114     */
115    public function testAssertEqualsFails($expected, $actual)
116    {
117        $this->setExpectedException('SebastianBergmann\\Comparator\\ComparisonFailure');
118        $this->comparator->assertEquals($expected, $actual);
119    }
120}
121