Completed
Push — master ( 520f00...657555 )
by Julien
02:13
created

VersionSorterTest::provideVersions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
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\Version;
18
use SemVer\SemVer\VersionSorter;
19
20
/**
21
 * Test VersionSorter class.
22
 */
23
final class VersionSorterTest extends PHPUnit_Framework_TestCase
24
{
25
    ////////////////////////////////////////////////////////////////////////////
26
    // ::sort()
27
    ////////////////////////////////////////////////////////////////////////////
28
29
    /**
30
     * @dataProvider provideVersions
31
     *
32
     * @param array $versions
33
     * @param array $expectedResult
34
     */
35
    public function testSort(array $versions, array $expectedResult)
36
    {
37
        $result = VersionSorter::sort($versions);
38
39
        static::assertCount(count($versions), $result, 'sort result should contain every items.');
40
        static::assertCount(count($expectedResult), $result);
41
42
        do {
43
            $version         = array_shift($result);
44
            $expectedVersion = array_shift($expectedResult);
45
            static::assertEquals(
46
                $expectedVersion->getMajor(),
47
                $version->getMajor(),
48
                '::sort() versions must be ordered by major version'
49
            );
50
            static::assertEquals(
51
                $expectedVersion->getMinor(),
52
                $version->getMinor(),
53
                '::sort() versions must be ordered by major version'
54
            );
55
            static::assertEquals(
56
                $expectedVersion->getPatch(),
57
                $version->getPatch(),
58
                '::sort() versions must be ordered by major version'
59
            );
60
            static::assertEquals(
61
                $expectedVersion->getPreRelease(),
62
                $version->getPreRelease(),
63
                '::sort() versions must be ordered by major version'
64
            );
65
        } while (count($result));
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function provideVersions() : array
72
    {
73
        return [
74
            [
75
                [
76
                    Version::fromString('2.0.0'),
77
                    Version::fromString('1.2.3'),
78
                    Version::fromString('1.3.3'),
79
                    Version::fromString('1.3.3-alpha.10'),
80
                    Version::fromString('1.3.3-alpha.2'),
81
                    Version::fromString('1.2.3-rc.1+exp.sha.5114f85'),
82
                ],
83
                [
84
                    Version::fromString('1.2.3-rc.1+exp.sha.5114f85'),
85
                    Version::fromString('1.2.3'),
86
                    Version::fromString('1.3.3-alpha.2'),
87
                    Version::fromString('1.3.3-alpha.10'),
88
                    Version::fromString('1.3.3'),
89
                    Version::fromString('2.0.0'),
90
                ],
91
            ],
92
        ];
93
    }
94
}
95