File: VersionTest.php

package info (click to toggle)
baconqrcode 3.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 732 kB
  • sloc: php: 6,970; xml: 63; makefile: 8
file content (73 lines) | stat: -rw-r--r-- 2,336 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types = 1);

namespace BaconQrCodeTest\Common;

use BaconQrCode\Common\ErrorCorrectionLevel;
use BaconQrCode\Common\Version;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class VersionTest extends TestCase
{
    public static function versions() : array
    {
        $array = [];

        for ($i = 1; $i <= 40; ++$i) {
            $array[] = [$i, 4 * $i + 17];
        }

        return $array;
    }

    public static function decodeInformation() : array
    {
        return [
            [7, 0x07c94],
            [12, 0x0c762],
            [17, 0x1145d],
            [22, 0x168c9],
            [27, 0x1b08e],
            [32, 0x209d5],
        ];
    }

    #[DataProvider('versions')]
    public function testVersionForNumber(int $versionNumber, int $dimension) : void
    {
        $version = Version::getVersionForNumber($versionNumber);

        $this->assertNotNull($version);
        $this->assertEquals($versionNumber, $version->getVersionNumber());
        $this->assertNotNull($version->getAlignmentPatternCenters());

        if ($versionNumber > 1) {
            $this->assertTrue(count($version->getAlignmentPatternCenters()) > 0);
        }

        $this->assertEquals($dimension, $version->getDimensionForVersion());
        $this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::H()));
        $this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::L()));
        $this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::M()));
        $this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::Q()));
        $this->assertNotNull($version->buildFunctionPattern());
    }

    #[DataProvider('versions')]
    public function testGetProvisionalVersionForDimension(int $versionNumber, int $dimension) : void
    {
        $this->assertSame(
            $versionNumber,
            Version::getProvisionalVersionForDimension($dimension)->getVersionNumber()
        );
    }

    #[DataProvider('decodeInformation')]
    public function testDecodeVersionInformation(int $expectedVersion, int $mask) : void
    {
        $version = Version::decodeVersionInformation($mask);
        $this->assertNotNull($version);
        $this->assertSame($expectedVersion, $version->getVersionNumber());
    }
}