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 stdClass;
14
15/**
16 * @coversDefaultClass SebastianBergmann\Comparator\TypeComparator
17 *
18 */
19class TypeComparatorTest extends \PHPUnit_Framework_TestCase
20{
21    private $comparator;
22
23    protected function setUp()
24    {
25        $this->comparator = new TypeComparator;
26    }
27
28    public function acceptsSucceedsProvider()
29    {
30        return array(
31          array(true, 1),
32          array(false, array(1)),
33          array(null, new stdClass),
34          array(1.0, 5),
35          array("", "")
36        );
37    }
38
39    public function assertEqualsSucceedsProvider()
40    {
41        return array(
42          array(true, true),
43          array(true, false),
44          array(false, false),
45          array(null, null),
46          array(new stdClass, new stdClass),
47          array(0, 0),
48          array(1.0, 2.0),
49          array("hello", "world"),
50          array("", ""),
51          array(array(), array(1,2,3))
52        );
53    }
54
55    public function assertEqualsFailsProvider()
56    {
57        return array(
58          array(true, null),
59          array(null, false),
60          array(1.0, 0),
61          array(new stdClass, array()),
62          array("1", 1)
63        );
64    }
65
66    /**
67     * @covers       ::accepts
68     * @dataProvider acceptsSucceedsProvider
69     */
70    public function testAcceptsSucceeds($expected, $actual)
71    {
72        $this->assertTrue(
73          $this->comparator->accepts($expected, $actual)
74        );
75    }
76
77    /**
78     * @covers       ::assertEquals
79     * @dataProvider assertEqualsSucceedsProvider
80     */
81    public function testAssertEqualsSucceeds($expected, $actual)
82    {
83        $exception = null;
84
85        try {
86            $this->comparator->assertEquals($expected, $actual);
87        }
88
89        catch (ComparisonFailure $exception) {
90        }
91
92        $this->assertNull($exception, 'Unexpected ComparisonFailure');
93    }
94
95    /**
96     * @covers       ::assertEquals
97     * @dataProvider assertEqualsFailsProvider
98     */
99    public function testAssertEqualsFails($expected, $actual)
100    {
101        $this->setExpectedException('SebastianBergmann\\Comparator\\ComparisonFailure', 'does not match expected type');
102        $this->comparator->assertEquals($expected, $actual);
103    }
104}
105