VersionsTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 6
Bugs 1 Features 3
Metric Value
wmc 10
c 6
b 1
f 3
lcom 2
cbo 2
dl 0
loc 79
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testValidVersions() 0 15 2
A testInvalidVersionsAreRejected() 0 6 1
A testGetShortVersion() 0 15 2
A testInvalidVersionsAreRejectedInGetShortVersion() 0 6 1
A testGetMajorVersion() 0 15 2
A testInvalidVersionsAreRejectedInGetMajorVersion() 0 6 1
1
<?php
2
3
namespace PackageVersionsTest;
4
5
use PackageVersions\Versions;
6
use PHPUnit_Framework_TestCase;
7
8
/**
9
 * @covers \PackageVersions\Versions
10
 */
11
final class VersionsTest extends PHPUnit_Framework_TestCase
12
{
13
14
    protected function setUp()
15
    {
16
        parent::setUp();
17
18
        \PHPUnit_Framework_Error_Deprecated::$enabled = FALSE;
19
    }
20
21
    public function testValidVersions()
22
    {
23
        $lockData = json_decode(file_get_contents(__DIR__ . '/../../composer.lock'), true);
24
25
        $packages = array_merge($lockData['packages'], $lockData['packages-dev']);
26
27
        self::assertNotEmpty($packages);
28
29
        foreach ($packages as $package) {
30
            self::assertSame(
31
                $package['version'] . '@' . $package['source']['reference'],
32
                Versions::getVersion($package['name'])
33
            );
34
        }
35
    }
36
37
    public function testInvalidVersionsAreRejected()
38
    {
39
        $this->setExpectedException(\OutOfBoundsException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
40
41
        Versions::getVersion(uniqid('', true) . '/' . uniqid('', true));
42
    }
43
44
    public function testGetShortVersion()
45
    {
46
        $lockData = json_decode(file_get_contents(__DIR__ . '/../../composer.lock'), true);
47
48
        $packages = array_merge($lockData['packages'], $lockData['packages-dev']);
49
50
        self::assertNotEmpty($packages);
51
52
        foreach ($packages as $package) {
53
            self::assertSame(
54
                $package['version'],
55
                Versions::getShortVersion($package['name'])
56
            );
57
        }
58
    }
59
60
    public function testInvalidVersionsAreRejectedInGetShortVersion()
61
    {
62
        $this->setExpectedException(\OutOfBoundsException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
63
64
        Versions::getShortVersion(uniqid('', true) . '/' . uniqid('', true));
65
    }
66
67
    public function testGetMajorVersion()
68
    {
69
        $lockData = json_decode(file_get_contents(__DIR__ . '/../../composer.lock'), true);
70
71
        $packages = array_merge($lockData['packages'], $lockData['packages-dev']);
72
73
        self::assertNotEmpty($packages);
74
75
        foreach ($packages as $package) {
76
            self::assertSame(
77
                explode('.', $package['version'])[0],
78
                Versions::getMajorVersion($package['name'])
79
            );
80
        }
81
    }
82
83
    public function testInvalidVersionsAreRejectedInGetMajorVersion()
84
    {
85
        $this->setExpectedException(\OutOfBoundsException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
86
87
        Versions::getMajorVersion(uniqid('', true) . '/' . uniqid('', true));
88
    }
89
}
90