Completed
Pull Request — master (#2)
by Julien
02:13
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
        static::assertEquals($expectedResult, VersionComparator::compare($version1, $version2), $message);
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function provideCompareVersions() : array
44
    {
45
        return [
46
            // major
47
            [
48
                Version::fromString('1.0.0'),
49
                Version::fromString('2.0.0'),
50
                -1,
51
                '::compare() versions must be ordered by major version (current lower than other)',
52
            ],
53
            [
54
                Version::fromString('2.0.0'),
55
                Version::fromString('1.0.0'),
56
                1,
57
                '::compare() versions must be ordered by major version (current greater than other)',
58
            ],
59
            [
60
                Version::fromString('2.0.0'),
61
                Version::fromString('10.0.0'),
62
                -1,
63
                '::compare() versions must be ordered by major version numerically',
64
            ],
65
            // minor
66
            [
67
                Version::fromString('2.10.0'),
68
                Version::fromString('2.0.0'),
69
                1,
70
                '::compare() if major versions are equals, then it must be ordered by minor version (current lower than other)',
71
            ],
72
            [
73
                Version::fromString('2.0.0'),
74
                Version::fromString('2.10.0'),
75
                -1,
76
                '::compare() if major versions are equals, then it must be ordered by minor version (current greater than other)',
77
            ],
78
            [
79
                Version::fromString('2.10.0'),
80
                Version::fromString('2.2.0'),
81
                1,
82
                '::compare() if major versions are equals, then it must be ordered by minor version numerically',
83
            ],
84
            // patch
85
            [
86
                Version::fromString('2.0.10'),
87
                Version::fromString('2.0.0'),
88
                1,
89
                '::compare() if major and minor versions are equals, then it must be ordered by patch version numerically (current lower than other)',
90
            ],
91
            [
92
                Version::fromString('2.0.0'),
93
                Version::fromString('2.0.10'),
94
                -1,
95
                '::compare() if major and minor versions are equals, then it must be ordered by patch version numerically (current greater than other)',
96
            ],
97
            [
98
                Version::fromString('2.0.10'),
99
                Version::fromString('2.0.2'),
100
                1,
101
                '::compare() if major and minor versions are equals, then it must be ordered by patch version numerically',
102
            ],
103
            [
104
                Version::fromString('2.0.0'),
105
                Version::fromString('2.0.0+build'),
106
                0,
107
                '::compare() if major, minor and patch versions are equals and both versions do not have pre-release, then they are equals',
108
            ],
109
            [
110
                Version::fromString('2.0.0'),
111
                Version::fromString('2.0.0-alpha'),
112
                1,
113
                '::compare() When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version. (current without pre-release)',
114
            ],
115
            [
116
                Version::fromString('2.0.0-alpha'),
117
                Version::fromString('2.0.0'),
118
                -1,
119
                '::compare() A larger set of pre-release fields has a higher precedence than a smaller set',
120
            ],
121
            [
122
                Version::fromString('2.0.0-alpha.1'),
123
                Version::fromString('2.0.0-alpha'),
124
                1,
125
                '::compare() A larger set of pre-release fields has a higher precedence than a smaller set (multiple level)',
126
            ],
127
            [
128
                Version::fromString('2.0.0-alpha'),
129
                Version::fromString('2.0.0-alpha.1'),
130
                -1,
131
                '::compare() A larger set of pre-release fields has a higher precedence than a smaller set (multiple level)',
132
            ],
133
            [
134
                Version::fromString('2.0.0-1'),
135
                Version::fromString('2.0.0-beta'),
136
                -1,
137
                '::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',
138
            ],
139
            [
140
                Version::fromString('2.0.0-beta'),
141
                Version::fromString('2.0.0-1'),
142
                1,
143
                '::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',
144
            ],
145
            [
146
                Version::fromString('2.0.0-alpha.1'),
147
                Version::fromString('2.0.0-alpha.beta'),
148
                -1,
149
                '::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.',
150
            ],
151
            [
152
                Version::fromString('2.0.0-alpha.10'),
153
                Version::fromString('2.0.0-alpha.2'),
154
                1,
155
                '::compare() numeric pre-release, minor, and patch version. Numeric identifiers always have lower precedence than non-numeric identifiers. Test with multiple identifiers level.',
156
            ],
157
            [
158
                Version::fromString('2.0.0-alpha+build127'),
159
                Version::fromString('2.0.0-alpha+build128'),
160
                0,
161
                '::compare() numeric pre-release, minor, and patch version. Numeric identifiers always have lower precedence than non-numeric identifiers. Test with multiple identifiers level.',
162
            ],
163
        ];
164
    }
165
}
166