Completed
Pull Request — master (#3)
by Julien
02:13
created

VersionSorterTest::testSort()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 32
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 24
nc 1
nop 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace SemVer\SemVer\Tests;
5
6
use PHPUnit_Framework_TestCase;
7
use SemVer\SemVer\Version;
8
use SemVer\SemVer\VersionSorter;
9
10
/**
11
 * Test VersionSorter class
12
 */
13
final class VersionSorterTest extends PHPUnit_Framework_TestCase
14
{
15
    ////////////////////////////////////////////////////////////////////////////
16
    // ::sort()
17
    ////////////////////////////////////////////////////////////////////////////
18
    /**
19
     * @dataProvider provideVersions
20
     * @param array $versions
21
     * @param array $expectedResult
22
     */
23
    public function testSort(array $versions, array $expectedResult)
24
    {
25
        $result = VersionSorter::sort($versions);
26
        
27
        static::assertCount(count($versions), $result, 'sort result should contain every items.');
28
        static::assertCount(count($expectedResult), $result);
29
        
30
        do {
31
            $version   = array_shift($result);
32
            $expectedVersion = array_shift($expectedResult);
33
            static::assertEquals(
34
                $expectedVersion->getMajor(),
35
                $version->getMajor(),
36
                '::sort() versions must be ordered by major version'
37
            );
38
            static::assertEquals(
39
                $expectedVersion->getMinor(),
40
                $version->getMinor(),
41
                '::sort() versions must be ordered by major version'
42
            );
43
            static::assertEquals(
44
                $expectedVersion->getPatch(),
45
                $version->getPatch(),
46
                '::sort() versions must be ordered by major version'
47
            );
48
            static::assertEquals(
49
                $expectedVersion->getPreRelease(),
50
                $version->getPreRelease(),
51
                '::sort() versions must be ordered by major version'
52
            );
53
        } while (count($result));
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function provideVersions() : array
60
    {
61
        return [
62
            [
63
                [Version::fromString('2.0.0'), Version::fromString('1.10.10'),],
64
                [Version::fromString('1.10.10'), Version::fromString('2.0.0'),]
65
            ]
66
        ];
67
    }
68
}
69