Completed
Pull Request — master (#2)
by Abdul Malik
03:27 queued 01:18
created

VersionsTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 7
c 5
b 1
f 2
lcom 1
cbo 2
dl 0
loc 56
rs 10

5 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
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