public addPlatformsFile ( string $src ) : |
||
$src | string | Name of the file |
Résultat |
public function addPlatformsFile($src)
{
$json = $this->loadFile($src);
if (!isset($json['platforms'])) {
throw new \UnexpectedValueException('required "platforms" structure is missing');
}
$platformFactory = new Factory\PlatformFactory();
foreach (array_keys($json['platforms']) as $platformName) {
$platformData = $json['platforms'][$platformName];
if (!isset($platformData['match'])) {
throw new \UnexpectedValueException('required attibute "match" is missing');
}
if (!isset($platformData['properties']) && !isset($platformData['inherits'])) {
throw new \UnexpectedValueException('required attibute "properties" is missing');
}
$this->platforms[$platformName] = $platformFactory->build($platformData, $json, $platformName);
}
$this->divisionsHaveBeenSorted = false;
return $this;
}
/** * tests getting an exiting platform * * @group data * @group sourcetest */ public function testGetPlatform() { $this->object->addPlatformsFile($this->getPlatformsJsonFixture()); self::assertInternalType('array', $this->object->getPlatforms()); $platform = $this->object->getPlatform('Platform1'); self::assertInstanceOf('\\Browscap\\Data\\Platform', $platform); $properties = $platform->getProperties(); self::assertInternalType('array', $properties); self::assertArrayHasKey('Platform', $properties); self::assertSame('Platform1', $properties['Platform']); }