public function testImplicitCreationOfRootPackage()
 {
     $graph = new DependencyGraph();
     $packages = $graph->getPackages();
     $this->assertCount(1, $packages);
     $this->assertTrue($graph->isRootPackage($packages['__root']));
 }
Exemplo n.º 2
0
 private function processLockedData(DependencyGraph $graph, array $lockedPackageData)
 {
     $packageName = null;
     if (isset($lockedPackageData['name'])) {
         $packageName = $lockedPackageData['name'];
     } elseif (isset($lockedPackageData['package'])) {
         $packageName = $lockedPackageData['package'];
     }
     if (null === $packageName) {
         return;
     }
     $package = $graph->getPackage($packageName);
     if (null === $package) {
         return;
     }
     $package->setVersion($lockedPackageData['version']);
     if (isset($lockedPackageData['installation-source']) && isset($lockedPackageData[$lockedPackageData['installation-source']]['reference']) && $lockedPackageData['version'] !== $lockedPackageData[$lockedPackageData['installation-source']]['reference']) {
         $package->setSourceReference($lockedPackageData[$lockedPackageData['installation-source']]['reference']);
     }
 }
 private function dumpGraph(DependencyGraph $graph)
 {
     $packages = $graph->getPackages();
     usort($packages, function (PackageNode $a, PackageNode $b) use($graph) {
         if ($graph->isRootPackage($a)) {
             return -1;
         }
         if ($graph->isRootPackage($b)) {
             return 1;
         }
         return strcmp($a->getName(), $b->getName());
     });
     $txt = '';
     foreach ($packages as $package) {
         if ('' !== $txt) {
             $txt .= "\n\n";
         }
         $name = $package->getName();
         if ($graph->isRootPackage($package)) {
             $name .= ' (Root)';
         }
         $txt .= $name . "\n" . str_repeat('=', strlen($name)) . "\n";
         $txt .= "Version: " . ($package->getVersion() ?: '<null>') . "\n";
         if (null !== ($ref = $package->getSourceReference())) {
             $txt .= "Source-Reference: " . $ref . "\n";
         }
         if (count($outEdges = $package->getOutEdges()) > 0) {
             usort($outEdges, function (DependencyEdge $a, DependencyEdge $b) {
                 return strcmp($a->getDestPackage()->getName(), $b->getDestPackage()->getName());
             });
             foreach ($outEdges as $edge) {
                 assert($edge instanceof DependencyEdge);
                 $txt .= "-> " . $edge->getDestPackage()->getName() . "\n";
             }
         }
     }
     return $txt;
 }