/**
  * @dataProvider providesInfoXml
  */
 public function testParsingValidXml($expectedJson, $xmlFile)
 {
     $expectedData = null;
     if (!is_null($expectedJson)) {
         $expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/{$expectedJson}"), true);
     }
     $data = $this->parser->parse(OC::$SERVERROOT . "/tests/data/app/{$xmlFile}");
     $this->assertEquals($expectedData, $data);
 }
 /**
  * @param string $appId
  * @return array
  */
 public function analyse($appId)
 {
     $appPath = \OC_App::getAppPath($appId);
     if ($appPath === false) {
         throw new \RuntimeException("No app with given id <{$appId}> known.");
     }
     $errors = [];
     $info = $this->infoParser->parse($appPath . '/appinfo/info.xml');
     foreach ($info as $key => $value) {
         if (is_array($value)) {
             $value = json_encode($value);
         }
         if (in_array($key, $this->mandatoryFields)) {
             $this->emit('InfoChecker', 'mandatoryFieldFound', [$key, $value]);
             continue;
         }
         if (in_array($key, $this->optionalFields)) {
             $this->emit('InfoChecker', 'optionalFieldFound', [$key, $value]);
             continue;
         }
         if (in_array($key, $this->deprecatedFields)) {
             // skip empty arrays - empty arrays for remote and public are always added
             if ($value === '[]' && in_array($key, ['public', 'remote', 'info'])) {
                 continue;
             }
             $this->emit('InfoChecker', 'deprecatedFieldFound', [$key, $value]);
             continue;
         }
         $this->emit('InfoChecker', 'unusedFieldFound', [$key, $value]);
     }
     foreach ($this->mandatoryFields as $key) {
         if (!isset($info[$key])) {
             $this->emit('InfoChecker', 'mandatoryFieldMissing', [$key]);
             $errors[] = ['type' => 'mandatoryFieldMissing', 'field' => $key];
         }
     }
     $versionFile = $appPath . '/appinfo/version';
     if (is_file($versionFile)) {
         $version = trim(file_get_contents($versionFile));
         if (isset($info['version'])) {
             if ($info['version'] !== $version) {
                 $this->emit('InfoChecker', 'differentVersions', [$version, $info['version']]);
                 $errors[] = ['type' => 'differentVersions', 'message' => 'appinfo/version: ' . $version . ' - appinfo/info.xml: ' . $info['version']];
             } else {
                 $this->emit('InfoChecker', 'sameVersions', [$versionFile]);
             }
         } else {
             $this->emit('InfoChecker', 'migrateVersion', [$version]);
         }
     } else {
         if (!isset($info['version'])) {
             $this->emit('InfoChecker', 'mandatoryFieldMissing', ['version']);
             $errors[] = ['type' => 'mandatoryFieldMissing', 'field' => 'version'];
         }
     }
     return $errors;
 }