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
|
<?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\Device;
use DeviceDetector\Parser\Device\Camera;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Spyc;
class CameraTest extends TestCase
{
/**
* @dataProvider getFixtures
*/
#[DataProvider('getFixtures')]
public function testParse(string $useragent, array $device): void
{
$consoleParser = new Camera();
$consoleParser->setUserAgent($useragent);
$this->assertIsArray($consoleParser->parse());
$this->assertEquals($device['type'], Camera::getDeviceName($consoleParser->getDeviceType()));
$this->assertEquals($device['brand'], $consoleParser->getBrand());
$this->assertEquals($device['model'], $consoleParser->getModel());
}
public static function getFixtures(): array
{
$fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/camera.yml');
$fixtureData = \array_map(static function (array $item): array {
return ['useragent' => $item['user_agent'], 'device' => $item['device']];
}, $fixtureData);
return $fixtureData;
}
}
|