Load a JSON file, parse it's JSON and add it to our divisions list
public addSourceFile ( string $src ) : |
||
$src | string | Name of the file |
return |
/** * checks if a source file is added successful * * @group data * @group sourcetest */ public function testAddSourceFileOkWithLiteAndVersions() { $this->object->addSourceFile(__DIR__ . '/../../fixtures/ua/test2.json'); $divisions = $this->object->getDivisions(); self::assertInternalType('array', $divisions); self::assertArrayHasKey(0, $divisions); self::assertInstanceOf('\\Browscap\\Data\\Division', $divisions[0]); }
/** * Create and populate a data collection object from a resource folder * * @param string $resourceFolder * * @throws \LogicException * @return \Browscap\Data\DataCollection */ public function createDataCollection($resourceFolder) { if (null === $this->collection) { throw new \LogicException('An instance of \\Browscap\\Data\\DataCollection is required for this function. ' . 'Please set it with setDataCollection'); } $this->getLogger()->debug('add platform file'); $this->collection->addDevicesFile($resourceFolder . '/devices.json')->addPlatformsFile($resourceFolder . '/platforms.json')->addEnginesFile($resourceFolder . '/engines.json')->addDefaultProperties($resourceFolder . '/core/default-properties.json')->addDefaultBrowser($resourceFolder . '/core/default-browser.json'); $uaSourceDirectory = $resourceFolder . '/user-agents'; $iterator = new \RecursiveDirectoryIterator($uaSourceDirectory); foreach (new \RecursiveIteratorIterator($iterator) as $file) { /** @var $file \SplFileInfo */ if (!$file->isFile() || $file->getExtension() != 'json') { continue; } $this->getLogger()->debug('add source file ' . $file->getPathname()); $this->collection->addSourceFile($file->getPathname()); } return $this->collection; }
/** * checks if a exception is thrown if the sortindex property is missing * * @expectedException \LogicException * @expectedExceptionMessage the properties array contains engine data for key "cde", please use the "engine" keyword * * @group data * @group sourcetest */ public function testAddSourceFileThrowsExceptionIfChildrenHasEngineProperties() { $this->object->addSourceFile(__DIR__ . '/../../fixtures/ua/ua-with-children-with-engine-properties.json'); }