VersionsTest::testInvalidVersionsAreRejected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 3
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PackageVersionsTest;
6
7
use OutOfBoundsException;
8
use PackageVersions\Versions;
9
use PHPUnit\Framework\TestCase;
10
use function array_merge;
11
use function file_get_contents;
12
use function json_decode;
13
use function uniqid;
14
15
/**
16
 * @uses \PackageVersions\FallbackVersions
17
 *
18
 * @covers \PackageVersions\Versions
19
 */
20
final class VersionsTest extends TestCase
21
{
22
    public function testValidVersions() : void
23
    {
24
        $lockData = json_decode(file_get_contents(__DIR__ . '/../../composer.lock'), true);
25
26
        $packages = array_merge($lockData['packages'], $lockData['packages-dev']);
27
28
        self::assertNotEmpty($packages);
29
30
        foreach ($packages as $package) {
31
            self::assertSame(
32
                $package['version'] . '@' . $package['source']['reference'],
33
                Versions::getVersion($package['name'])
34
            );
35
        }
36
    }
37
38
    public function testInvalidVersionsAreRejected() : void
39
    {
40
        $this->expectException(OutOfBoundsException::class);
41
42
        /**
43
         * @psalm-suppress ArgumentTypeCoercion we are explicitly testing for something not allowed by the type system
44
         */
45
        Versions::getVersion(uniqid('', true) . '/' . uniqid('', true));
46
    }
47
}
48