/** * tests setter and getter for versions * * @group data * @group sourcetest */ public function testSetGetVersions() { $versions = array(1, 2, 3); self::assertSame($this->object, $this->object->setVersions($versions)); self::assertSame($versions, $this->object->getVersions()); }
/** * Load a JSON file, parse it's JSON and add it to our divisions list * * @param string $src Name of the file * * @return \Browscap\Data\DataCollection * @throws \RuntimeException If the file does not exist or has invalid JSON * @throws \UnexpectedValueException If required attibutes are missing in the division * @throws \LogicException */ public function addSourceFile($src) { $divisionData = $this->loadFile($src); if (!array_key_exists('division', $divisionData)) { throw new \UnexpectedValueException('required attibute "division" is missing in File ' . $src); } if (!array_key_exists('sortIndex', $divisionData)) { throw new \UnexpectedValueException('required attibute "sortIndex" is missing in File ' . $src); } if (!array_key_exists('lite', $divisionData)) { throw new \UnexpectedValueException('required attibute "lite" is missing in File ' . $src); } $division = new Division(); $division->setName($divisionData['division'])->setSortIndex((int) $divisionData['sortIndex'])->setLite((bool) $divisionData['lite']); if (isset($divisionData['versions']) && is_array($divisionData['versions'])) { $division->setVersions($divisionData['versions']); } else { $division->setVersions(array('0.0')); } if (isset($divisionData['userAgents']) && is_array($divisionData['userAgents'])) { foreach ($divisionData['userAgents'] as $useragent) { if (false === strpos($useragent['userAgent'], '#') && in_array($useragent['userAgent'], $this->allDivision)) { throw new \UnexpectedValueException('Division "' . $useragent['userAgent'] . '" is defined twice'); } if (!isset($useragent['properties']) || !is_array($useragent['properties'])) { throw new \UnexpectedValueException('the properties entry has to be an array for key "' . $useragent['userAgent'] . '"'); } if (!isset($useragent['properties']['Parent'])) { throw new \UnexpectedValueException('the "Parent" property is missing for key "' . $useragent['userAgent'] . '"'); } if ('DefaultProperties' !== $useragent['properties']['Parent']) { throw new \UnexpectedValueException('the "Parent" property is not linked to the "DefaultProperties" for key "' . $useragent['userAgent'] . '"'); } if (!isset($useragent['properties']['Comment'])) { throw new \UnexpectedValueException('the "Comment" property is missing for key "' . $useragent['userAgent'] . '"'); } $this->checkPlatformData($useragent['properties'], 'the properties array contains platform data for key "' . $useragent['userAgent'] . '", please use the "platform" keyword'); $this->checkEngineData($useragent['properties'], 'the properties array contains engine data for key "' . $useragent['userAgent'] . '", please use the "engine" keyword'); $this->checkDeviceData($useragent['properties'], 'the properties array contains device data for key "' . $useragent['userAgent'] . '", please use the "device" keyword'); $this->allDivision[] = $useragent['userAgent']; if (isset($useragent['children']) && is_array($useragent['children'])) { if (isset($useragent['children']['match'])) { throw new \UnexpectedValueException('the children property shall not have the "match" entry for key "' . $useragent['userAgent'] . '"'); } foreach ($useragent['children'] as $child) { if (!is_array($child)) { throw new \UnexpectedValueException('each entry of the children property has to be an array for key "' . $useragent['userAgent'] . '"'); } if (!isset($child['match'])) { throw new \UnexpectedValueException('each entry of the children property requires an "match" entry for key "' . $useragent['userAgent'] . '", missing for child data: ' . json_encode($child)); } if (isset($child['properties'])) { if (!is_array($child['properties'])) { throw new \UnexpectedValueException('the properties entry has to be an array for key "' . $child['match'] . '"'); } if (isset($child['properties']['Parent'])) { throw new \UnexpectedValueException('the Parent property must not set inside the children array for key "' . $child['match'] . '"'); } $this->checkPlatformData($child['properties'], 'the properties array contains platform data for key "' . $child['match'] . '", please use the "platforms" keyword'); $this->checkEngineData($child['properties'], 'the properties array contains engine data for key "' . $child['match'] . '", please use the "engine" keyword'); $this->checkDeviceData($child['properties'], 'the properties array contains device data for key "' . $child['match'] . '", please use the "device" keyword'); } } } } $division->setUserAgents($divisionData['userAgents']); } $this->divisions[] = $division; $this->divisionsHaveBeenSorted = false; return $this; }