~ballot/wordpress/openstack-objectstorage-bis

« back to all changes in this revision

Viewing changes to vendor/sebastian/comparator/tests/ScalarComparatorTest.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\ScalarComparator
 
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 ScalarComparatorTest extends \PHPUnit_Framework_TestCase
 
23
{
 
24
    private $comparator;
 
25
 
 
26
    protected function setUp()
 
27
    {
 
28
        $this->comparator = new ScalarComparator;
 
29
    }
 
30
 
 
31
    public function acceptsSucceedsProvider()
 
32
    {
 
33
        return array(
 
34
          array("string", "string"),
 
35
          array(new ClassWithToString, "string"),
 
36
          array("string", new ClassWithToString),
 
37
          array("string", null),
 
38
          array(false, "string"),
 
39
          array(false, true),
 
40
          array(null, false),
 
41
          array(null, null),
 
42
          array("10", 10),
 
43
          array("", false),
 
44
          array("1", true),
 
45
          array(1, true),
 
46
          array(0, false),
 
47
          array(0.1, "0.1")
 
48
        );
 
49
    }
 
50
 
 
51
    public function acceptsFailsProvider()
 
52
    {
 
53
        return array(
 
54
          array(array(), array()),
 
55
          array("string", array()),
 
56
          array(new ClassWithToString, new ClassWithToString),
 
57
          array(false, new ClassWithToString),
 
58
          array(tmpfile(), tmpfile())
 
59
        );
 
60
    }
 
61
 
 
62
    public function assertEqualsSucceedsProvider()
 
63
    {
 
64
        return array(
 
65
          array("string", "string"),
 
66
          array(new ClassWithToString, new ClassWithToString),
 
67
          array("string representation", new ClassWithToString),
 
68
          array(new ClassWithToString, "string representation"),
 
69
          array("string", "STRING", true),
 
70
          array("STRING", "string", true),
 
71
          array("String Representation", new ClassWithToString, true),
 
72
          array(new ClassWithToString, "String Representation", true),
 
73
          array("10", 10),
 
74
          array("", false),
 
75
          array("1", true),
 
76
          array(1, true),
 
77
          array(0, false),
 
78
          array(0.1, "0.1"),
 
79
          array(false, null),
 
80
          array(false, false),
 
81
          array(true, true),
 
82
          array(null, null)
 
83
        );
 
84
    }
 
85
 
 
86
    public function assertEqualsFailsProvider()
 
87
    {
 
88
        $stringException = 'Failed asserting that two strings are equal.';
 
89
        $otherException = 'matches expected';
 
90
 
 
91
        return array(
 
92
          array("string", "other string", $stringException),
 
93
          array("string", "STRING", $stringException),
 
94
          array("STRING", "string", $stringException),
 
95
          array("string", "other string", $stringException),
 
96
          // https://github.com/sebastianbergmann/phpunit/issues/1023
 
97
          array('9E6666666','9E7777777', $stringException),
 
98
          array(new ClassWithToString, "does not match", $otherException),
 
99
          array("does not match", new ClassWithToString, $otherException),
 
100
          array(0, 'Foobar', $otherException),
 
101
          array('Foobar', 0, $otherException),
 
102
          array("10", 25, $otherException),
 
103
          array("1", false, $otherException),
 
104
          array("", true, $otherException),
 
105
          array(false, true, $otherException),
 
106
          array(true, false, $otherException),
 
107
          array(null, true, $otherException),
 
108
          array(0, true, $otherException)
 
109
        );
 
110
    }
 
111
 
 
112
    /**
 
113
     * @covers       ::accepts
 
114
     * @dataProvider acceptsSucceedsProvider
 
115
     */
 
116
    public function testAcceptsSucceeds($expected, $actual)
 
117
    {
 
118
        $this->assertTrue(
 
119
          $this->comparator->accepts($expected, $actual)
 
120
        );
 
121
    }
 
122
 
 
123
    /**
 
124
     * @covers       ::accepts
 
125
     * @dataProvider acceptsFailsProvider
 
126
     */
 
127
    public function testAcceptsFails($expected, $actual)
 
128
    {
 
129
        $this->assertFalse(
 
130
          $this->comparator->accepts($expected, $actual)
 
131
        );
 
132
    }
 
133
 
 
134
    /**
 
135
     * @covers       ::assertEquals
 
136
     * @dataProvider assertEqualsSucceedsProvider
 
137
     */
 
138
    public function testAssertEqualsSucceeds($expected, $actual, $ignoreCase = false)
 
139
    {
 
140
        $exception = null;
 
141
 
 
142
        try {
 
143
            $this->comparator->assertEquals($expected, $actual, 0.0, false, $ignoreCase);
 
144
        }
 
145
 
 
146
        catch (ComparisonFailure $exception) {
 
147
        }
 
148
 
 
149
        $this->assertNull($exception, 'Unexpected ComparisonFailure');
 
150
    }
 
151
 
 
152
    /**
 
153
     * @covers       ::assertEquals
 
154
     * @dataProvider assertEqualsFailsProvider
 
155
     */
 
156
    public function testAssertEqualsFails($expected, $actual, $message)
 
157
    {
 
158
        $this->setExpectedException(
 
159
          'SebastianBergmann\\Comparator\\ComparisonFailure', $message
 
160
        );
 
161
        $this->comparator->assertEquals($expected, $actual);
 
162
    }
 
163
}