~tcuthbert/wordpress/openstack-objectstorage

« back to all changes in this revision

Viewing changes to vendor/sebastian/comparator/tests/ArrayComparatorTest.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
11
namespace SebastianBergmann\Comparator;
 
12
 
 
13
/**
 
14
 * @coversDefaultClass SebastianBergmann\Comparator\ArrayComparator
 
15
 *
 
16
 * @package    Comparator
 
17
 * @author     Jeff Welch <whatthejeff@gmail.com>
 
18
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 
19
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
20
 * @link       http://www.github.com/sebastianbergmann/comparator
 
21
 */
 
22
class ArrayComparatorTest extends \PHPUnit_Framework_TestCase
 
23
{
 
24
    private $comparator;
 
25
 
 
26
    protected function setUp()
 
27
    {
 
28
        $this->comparator = new ArrayComparator;
 
29
        $this->comparator->setFactory(new Factory);
 
30
    }
 
31
 
 
32
    public function acceptsFailsProvider()
 
33
    {
 
34
        return array(
 
35
          array(array(), null),
 
36
          array(null, array()),
 
37
          array(null, null)
 
38
        );
 
39
    }
 
40
 
 
41
    public function assertEqualsSucceedsProvider()
 
42
    {
 
43
        return array(
 
44
          array(
 
45
            array('a' => 1, 'b' => 2),
 
46
            array('b' => 2, 'a' => 1)
 
47
          ),
 
48
          array(
 
49
            array(1),
 
50
            array('1')
 
51
          ),
 
52
          array(
 
53
            array(3, 2, 1),
 
54
            array(2, 3, 1),
 
55
            0,
 
56
            true
 
57
          ),
 
58
          array(
 
59
            array(2.3),
 
60
            array(2.5),
 
61
            0.5
 
62
          ),
 
63
          array(
 
64
            array(array(2.3)),
 
65
            array(array(2.5)),
 
66
            0.5
 
67
          ),
 
68
          array(
 
69
            array(new Struct(2.3)),
 
70
            array(new Struct(2.5)),
 
71
            0.5
 
72
          ),
 
73
        );
 
74
    }
 
75
 
 
76
    public function assertEqualsFailsProvider()
 
77
    {
 
78
        return array(
 
79
          array(
 
80
            array(),
 
81
            array(0 => 1)
 
82
          ),
 
83
          array(
 
84
            array(0 => 1),
 
85
            array()
 
86
          ),
 
87
          array(
 
88
            array(0 => null),
 
89
            array()
 
90
          ),
 
91
          array(
 
92
            array(0 => 1, 1 => 2),
 
93
            array(0 => 1, 1 => 3)
 
94
          ),
 
95
          array(
 
96
            array('a', 'b' => array(1, 2)),
 
97
            array('a', 'b' => array(2, 1))
 
98
          ),
 
99
          array(
 
100
            array(2.3),
 
101
            array(4.2),
 
102
            0.5
 
103
          ),
 
104
          array(
 
105
            array(array(2.3)),
 
106
            array(array(4.2)),
 
107
            0.5
 
108
          ),
 
109
          array(
 
110
            array(new Struct(2.3)),
 
111
            array(new Struct(4.2)),
 
112
            0.5
 
113
          )
 
114
        );
 
115
    }
 
116
 
 
117
    /**
 
118
     * @covers  ::accepts
 
119
     */
 
120
    public function testAcceptsSucceeds()
 
121
    {
 
122
        $this->assertTrue(
 
123
          $this->comparator->accepts(array(), array())
 
124
        );
 
125
    }
 
126
 
 
127
    /**
 
128
     * @covers       ::accepts
 
129
     * @dataProvider acceptsFailsProvider
 
130
     */
 
131
    public function testAcceptsFails($expected, $actual)
 
132
    {
 
133
        $this->assertFalse(
 
134
          $this->comparator->accepts($expected, $actual)
 
135
        );
 
136
    }
 
137
 
 
138
    /**
 
139
     * @covers       ::assertEquals
 
140
     * @dataProvider assertEqualsSucceedsProvider
 
141
     */
 
142
    public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0, $canonicalize = false)
 
143
    {
 
144
        $exception = null;
 
145
 
 
146
        try {
 
147
            $this->comparator->assertEquals($expected, $actual, $delta, $canonicalize);
 
148
        }
 
149
 
 
150
        catch (ComparisonFailure $exception) {
 
151
        }
 
152
 
 
153
        $this->assertNull($exception, 'Unexpected ComparisonFailure');
 
154
    }
 
155
 
 
156
    /**
 
157
     * @covers       ::assertEquals
 
158
     * @dataProvider assertEqualsFailsProvider
 
159
     */
 
160
    public function testAssertEqualsFails($expected, $actual,$delta = 0.0, $canonicalize = false)
 
161
    {
 
162
        $this->setExpectedException(
 
163
          'SebastianBergmann\\Comparator\\ComparisonFailure',
 
164
          'Failed asserting that two arrays are equal'
 
165
        );
 
166
        $this->comparator->assertEquals($expected, $actual, $delta, $canonicalize);
 
167
    }
 
168
}