File: VendorFragmentTest.php

package info (click to toggle)
matomo-device-detector 6.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,684 kB
  • sloc: php: 7,758; xml: 79; makefile: 15; sh: 3
file content (59 lines) | stat: -rw-r--r-- 1,683 bytes parent folder | download
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
<?php

/**
 * Device Detector - The Universal Device Detection library for parsing User Agents
 *
 * @link https://matomo.org
 *
 * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
 */

declare(strict_types=1);

namespace DeviceDetector\Tests\Parser;

use DeviceDetector\Parser\VendorFragment;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Spyc;

class VendorFragmentTest extends TestCase
{
    protected static $regexesTested = [];

    /**
     * @dataProvider getFixtures
     */
    #[DataProvider('getFixtures')]
    public function testParse(string $useragent, string $vendor): void
    {
        $vfParser = new VendorFragment();
        $vfParser->setUserAgent($useragent);
        $this->assertEquals(['brand' => $vendor], $vfParser->parse());
        self::$regexesTested[] = $vfParser->getMatchedRegex();
    }

    public static function getFixtures(): array
    {
        return Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/vendorfragments.yml');
    }

    public function testAllRegexesTested(): void
    {
        $regexesNotTested = [];

        $vendorRegexes = Spyc::YAMLLoad(\realpath(__DIR__ . '/../../regexes/') . DIRECTORY_SEPARATOR . 'vendorfragments.yml');

        foreach ($vendorRegexes as $vendor => $regexes) {
            foreach ($regexes as $regex) {
                if (\in_array($regex, self::$regexesTested, true)) {
                    continue;
                }

                $regexesNotTested[] = $vendor . ' / ' . $regex;
            }
        }

        $this->assertEmpty($regexesNotTested, 'Following vendor fragments are not tested: ' . \implode(', ', $regexesNotTested));
    }
}