/**
  * @dataProvider getLibraries
  */
 public function testLibrary($zipFile)
 {
     $libName = basename($zipFile, '.zip');
     $config = array();
     if (is_file($configFile = __DIR__ . '/libraries/' . $libName . '-config.json')) {
         $config = json_decode(file_get_contents($configFile), true);
     }
     $files = FileCollection::createFromZipFile($zipFile, null, isset($config['filter']) ? $config['filter'] : array());
     $this->analyzer->analyze($files);
     $actualComments = $this->dumpComments($files);
     if (!is_file($commentFile = __DIR__ . '/libraries/' . $libName . '-comments.txt')) {
         file_put_contents($commentFile . '.tmp', $actualComments);
         $this->fail(sprintf('The comment file "%s" was not found.', $commentFile));
     }
     $this->assertEquals(file_get_contents($commentFile), $actualComments);
     $nonExistentFiles = array();
     foreach ($files as $file) {
         $fixedFilePath = __DIR__ . '/libraries/' . $libName . '-' . $file->getName();
         if (!$file->hasFixedFileWithChanges()) {
             $this->assertFileNotExists($fixedFilePath . '.diff');
             continue;
         }
         $diff = \Scrutinizer\Util\DiffUtils::generate($file->getContent(), $file->getFixedFile()->getContent());
         if (!is_file($fixedFilePath . '.diff')) {
             if (!is_dir($dir = dirname($fixedFilePath))) {
                 mkdir($dir, 0777, true);
             }
             file_put_contents($fixedFilePath . '.tmp.diff', $diff);
             $nonExistentFiles[] = $fixedFilePath . '.tmp.diff';
             continue;
         }
         $this->assertEquals(file_get_contents($fixedFilePath . '.diff'), $diff);
     }
     $this->assertCount(0, $nonExistentFiles, "Some files are missing:\n" . implode("\n", $nonExistentFiles));
 }
 public function scanZipFile(PackageVersion $rootPackageVersion, $zipFile)
 {
     $this->logger->info(sprintf('Scanning zip file "%s" for files', $zipFile));
     $files = FileCollection::createFromZipFile($zipFile, '*.php');
     $this->logger->info(sprintf('Found "%d" files.', count($files)));
     $this->scan($rootPackageVersion, $files);
 }
 public function testMergeCollections()
 {
     $col = FileCollection::createFromZipFile(__DIR__ . '/Fixture/zip-file.zip');
     $col2 = FileCollection::createFromDirectory(__DIR__ . '/Fixture/DirWithSomeFiles');
     $merged = $col->merge($col2);
     $this->assertCount(3, $col);
     $files = $col->all();
     $this->assertArrayHasKey('A.php', $files);
     $this->assertArrayHasKey('Sub-Dir/B.php', $files);
     $this->assertArrayHasKey('text.txt', $files);
 }