/** * Load a platforms.json file and parse it into the platforms data array * * @param array $platformData * @param array $json * @param string $platformName * @param DataCollection $datacollection * * @return \Browscap\Data\Platform * @throws \RuntimeException if the file does not exist or has invalid JSON * @throws \UnexpectedValueException */ public function build(array $platformData, array $json, $platformName, DataCollection $datacollection) { if (!isset($platformData['properties'])) { $platformData['properties'] = array(); } if (!isset($platformData['lite'])) { $platformData['lite'] = true; } if (array_key_exists('inherits', $platformData)) { $parentName = $platformData['inherits']; if (!isset($json['platforms'][$parentName])) { throw new \UnexpectedValueException('parent Platform "' . $parentName . '" is missing for platform "' . $platformName . '"'); } $parentPlatform = $this->build($json['platforms'][$parentName], $json, $parentName, $datacollection); $parentPlatformData = $parentPlatform->getProperties(); $platformProperties = $platformData['properties']; foreach ($platformProperties as $name => $value) { if (isset($parentPlatformData[$name]) && $parentPlatformData[$name] == $value) { throw new \UnexpectedValueException('the value for property "' . $name . '" has the same value in the keys "' . $platformName . '" and its parent "' . $platformData['inherits'] . '"'); } } $platformData['properties'] = array_merge($parentPlatformData, $platformProperties); if (!$parentPlatform->isLite()) { $platformData['lite'] = false; } } if (array_key_exists('device', $platformData)) { $deviceName = $platformData['device']; $deviceData = $datacollection->getDevice($deviceName); $platformData['properties'] = array_merge($deviceData->getProperties(), $platformData['properties']); } $platform = new Platform(); $platform->setMatch($platformData['match'])->setProperties($platformData['properties'])->setIsLite($platformData['lite']); return $platform; }
/** * tests setter and getter for the match property * * @group data * @group sourcetest */ public function testGetter() { $match = 'TestMatchName'; $properties = ['abc' => 'def']; $object = new Platform($match, $properties, true, false); self::assertSame($match, $object->getMatch()); self::assertSame($properties, $object->getProperties()); $this->assertTrue($object->isLite()); $this->assertFalse($object->isStandard()); }
/** * tests setter and getter for the lite property * * @group data * @group sourcetest */ public function testSetGetIsLite() { $this->assertFalse($this->object->isLite()); $this->object->setIsLite(true); $this->assertTrue($this->object->isLite()); }