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

VersionSorterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 56
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testSort() 0 32 2
A provideVersions() 0 9 1
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