Completed
Pull Request — master (#2)
by Julien
02:17
created

VersionComparatorTest::provideCompareVersions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 122
Code Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 122
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 78
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of semver/semver.
5
 *
6
 * (c) SemVer <https://github.com/git-pull-request>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace SemVer\SemVer\Tests;
15
16
use PHPUnit_Framework_TestCase;
17
use SemVer\SemVer\PreReleaseComparator;
18
use SemVer\SemVer\Version;
19
use SemVer\SemVer\VersionComparator;
20
21
final class VersionComparatorTest extends PHPUnit_Framework_TestCase
22
{
23
    ////////////////////////////////////////////////////////////////////////////
24
    // compare()
25
    ////////////////////////////////////////////////////////////////////////////
26
27
    /**
28
     * @dataProvider provideCompareVersions
29
     *
30
     * @param Version $version1
31
     * @param Version $version2
32
     * @param int     $expectedResult
33
     * @param string  $message
34
     */
35
    public function testCompare(Version $version1, Version $version2, int $expectedResult, string $message)
36
    {
37
        (new PreReleaseComparator())();
38
        static::assertEquals($expectedResult, VersionComparator::compare($version1, $version2), $message);
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function provideCompareVersions() : array
45
    {
46
        return [
47
            // major
48
            [
49
                Version::fromString('1.0.0'),
50
                Version::fromString('2.0.0'),
51
                -1,
52
                '::compare() versions must be ordered by major version (current lower than other)',
53
            ],
54
            [
55
                Version::fromString('2.0.0'),
56
                Version::fromString('1.0.0'),
57
                1,
58
                '::compare() versions must be ordered by major version (current greater than other)',
59
            ],
60
            [
61
                Version::fromString('2.0.0'),
62
                Version::fromString('10.0.0'),
63
                -1,
64
                '::compare() versions must be ordered by major version numerically',
65
            ],
66
            // minor
67
            [
68
                Version::fromString('2.10.0'),
69
                Version::fromString('2.0.0'),
70
                1,
71
                '::compare() if major versions are equals, then it must be ordered by minor version (current lower than other)',
72
            ],
73
            [
74
                Version::fromString('2.0.0'),
75
                Version::fromString('2.10.0'),
76
                -1,
77
                '::compare() if major versions are equals, then it must be ordered by minor version (current greater than other)',
78
            ],
79
            [
80
                Version::fromString('2.10.0'),
81
                Version::fromString('2.2.0'),
82
                1,
83
                '::compare() if major versions are equals, then it must be ordered by minor version numerically',
84
            ],
85
            // patch
86
            [
87
                Version::fromString('2.0.10'),
88
                Version::fromString('2.0.0'),
89
                1,
90
                '::compare() if major and minor versions are equals, then it must be ordered by patch version numerically (current lower than other)',
91
            ],
92
            [
93
                Version::fromString('2.0.0'),
94
                Version::fromString('2.0.10'),
95
                -1,
96
                '::compare() if major and minor versions are equals, then it must be ordered by patch version numerically (current greater than other)',
97
            ],
98
            [
99
                Version::fromString('2.0.10'),
100
                Version::fromString('2.0.2'),
101
                1,
102
                '::compare() if major and minor versions are equals, then it must be ordered by patch version numerically',
103
            ],
104
            [
105
                Version::fromString('2.0.0'),
106
                Version::fromString('2.0.0+build'),
107
                0,
108
                '::compare() if major, minor and patch versions are equals and both versions do not have pre-release, then they are equals',
109
            ],
110
            [
111
                Version::fromString('2.0.0'),
112
                Version::fromString('2.0.0-alpha'),
113
                1,
114
                '::compare() When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version. (current without pre-release)',
115
            ],
116
            [
117
                Version::fromString('2.0.0-alpha'),
118
                Version::fromString('2.0.0'),
119
                -1,
120
                '::compare() A larger set of pre-release fields has a higher precedence than a smaller set',
121
            ],
122
            [
123
                Version::fromString('2.0.0-alpha.1'),
124
                Version::fromString('2.0.0-alpha'),
125
                1,
126
                '::compare() A larger set of pre-release fields has a higher precedence than a smaller set (multiple level)',
127
            ],
128
            [
129
                Version::fromString('2.0.0-alpha'),
130
                Version::fromString('2.0.0-alpha.1'),
131
                -1,
132
                '::compare() A larger set of pre-release fields has a higher precedence than a smaller set (multiple level)',
133
            ],
134
            [
135
                Version::fromString('2.0.0-1'),
136
                Version::fromString('2.0.0-beta'),
137
                -1,
138
                '::compare() Precedence for two pre-release versions with the same major, minor, and patch version. Numeric identifiers always have lower precedence than non-numeric identifiers',
139
            ],
140
            [
141
                Version::fromString('2.0.0-beta'),
142
                Version::fromString('2.0.0-1'),
143
                1,
144
                '::compare() Precedence for two pre-release versions with the same major, minor, and patch version. Numeric identifiers always have lower precedence than non-numeric identifiers',
145
            ],
146
            [
147
                Version::fromString('2.0.0-alpha.1'),
148
                Version::fromString('2.0.0-alpha.beta'),
149
                -1,
150
                '::compare() Precedence for two pre-release versions with the same major, minor, and patch version. Numeric identifiers always have lower precedence than non-numeric identifiers. Test with multiple identifiers level.',
151
            ],
152
            [
153
                Version::fromString('2.0.0-alpha.10'),
154
                Version::fromString('2.0.0-alpha.2'),
155
                1,
156
                '::compare() numeric pre-release, minor, and patch version. Numeric identifiers always have lower precedence than non-numeric identifiers. Test with multiple identifiers level.',
157
            ],
158
            [
159
                Version::fromString('2.0.0-alpha+build127'),
160
                Version::fromString('2.0.0-alpha+build128'),
161
                0,
162
                '::compare() numeric pre-release, minor, and patch version. Numeric identifiers always have lower precedence than non-numeric identifiers. Test with multiple identifiers level.',
163
            ],
164
        ];
165
    }
166
}
167