Author: Thomas Müller (t_mueller_stolzenhain@yahoo.de)
Ejemplo n.º 1
0
 /**
  * tests the creating of an platform factory
  *
  * @group data
  * @group sourcetest
  */
 public function testBuild()
 {
     $platformData = ['abc' => 'def', 'match' => 'test*', 'lite' => true, 'standard' => true];
     $json = [];
     $platformName = 'Test';
     $deviceData = ['Device_Name' => 'TestDevice'];
     $deviceMock = $this->getMockBuilder(\Browscap\Data\Device::class)->disableOriginalConstructor()->setMethods(['getProperties'])->getMock();
     $deviceMock->expects(self::any())->method('getProperties')->will(self::returnValue($deviceData));
     $collection = $this->getMockBuilder(\Browscap\Data\DataCollection::class)->disableOriginalConstructor()->setMethods(['getDevice'])->getMock();
     $collection->expects(self::any())->method('getDevice')->will(self::returnValue($deviceMock));
     self::assertInstanceOf('\\Browscap\\Data\\Platform', $this->object->build($platformData, $json, $platformName, $collection));
 }
Ejemplo n.º 2
0
 /**
  * tests the creating of an platform factory
  *
  * @group data
  * @group sourcetest
  */
 public function testBuild()
 {
     $platformData = array('abc' => 'def', 'match' => 'test*');
     $json = array();
     $platformName = 'Test';
     $deviceData = array('Device_Name' => 'TestDevice');
     $deviceMock = $this->getMock('\\Browscap\\Data\\Device', array('getProperties'), array(), '', false);
     $deviceMock->expects(self::any())->method('getProperties')->will(self::returnValue($deviceData));
     $datacollection = $this->getMock('\\Browscap\\Data\\DataCollection', array('getDevice'), array(), '', false);
     $datacollection->expects(self::any())->method('getDevice')->will(self::returnValue($deviceMock));
     self::assertInstanceOf('\\Browscap\\Data\\Platform', $this->object->build($platformData, $json, $platformName, $datacollection));
 }
Ejemplo n.º 3
0
 /**
  * Load a platforms.json file and parse it into the platforms data array
  *
  * @param string $src Name of the file
  *
  * @throws \RuntimeException             if the file does not exist or has invalid JSON
  * @throws \UnexpectedValueException
  * @return \Browscap\Data\DataCollection
  */
 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;
 }