public function testClear()
 {
     $packageFile1 = new PackageFile('vendor/package1');
     $package1 = new Package($packageFile1, '/path1');
     $packageFile2 = new PackageFile('vendor/package2');
     $package2 = new Package($packageFile2, '/path2');
     $rootPackageFile = new RootPackageFile('vendor/root');
     $rootPackage = new RootPackage($rootPackageFile, '/path3');
     $this->collection->add($package1);
     $this->collection->add($rootPackage);
     $this->collection->add($package2);
     $this->collection->clear();
     $this->assertFalse($this->collection->contains('vendor/root'));
     $this->assertFalse($this->collection->contains('vendor/package1'));
     $this->assertFalse($this->collection->contains('vendor/package2'));
     $this->assertTrue($this->collection->isEmpty());
 }
Exemple #2
0
 private function makeAbsolute($relativePath, Package $containingPackage, PackageCollection $packages)
 {
     // Reference to install path of other package
     if ('@' !== $relativePath[0] || false === ($pos = strpos($relativePath, ':'))) {
         return $containingPackage->getInstallPath() . '/' . $relativePath;
     }
     $refPackageName = substr($relativePath, 1, $pos - 1);
     if (!$packages->contains($refPackageName)) {
         throw new NoSuchPackageException(sprintf('The package "%s" referenced in the resource path "%s" was not ' . 'found. Maybe the package is not installed?', $refPackageName, $relativePath));
     }
     $refPackage = $packages->get($refPackageName);
     return $refPackage->getInstallPath() . '/' . substr($relativePath, $pos + 1);
 }
 /**
  * {@inheritdoc}
  */
 public function hasPackage($name)
 {
     Assert::string($name, 'The package name must be a string. Got: %s');
     $this->assertPackagesLoaded();
     return $this->packages->contains($name);
 }