public function testArrayAccess() { $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->assertFalse(isset($this->collection['vendor/package1'])); $this->assertFalse(isset($this->collection['vendor/package2'])); $this->assertFalse(isset($this->collection['vendor/root'])); $this->collection[] = $package1; $this->collection[] = $package2; $this->collection[] = $rootPackage; $this->assertTrue(isset($this->collection['vendor/package1'])); $this->assertTrue(isset($this->collection['vendor/package2'])); $this->assertTrue(isset($this->collection['vendor/root'])); $this->assertSame($rootPackage, $this->collection['vendor/root']); $this->assertSame($rootPackage, $this->collection->getRootPackage()); $this->assertSame($package1, $this->collection['vendor/package1']); $this->assertSame($package2, $this->collection['vendor/package2']); unset($this->collection['vendor/package1']); $this->assertFalse(isset($this->collection['vendor/package1'])); $this->assertTrue(isset($this->collection['vendor/package2'])); $this->assertTrue(isset($this->collection['vendor/root'])); }
/** * @expectedException \RuntimeException */ public function testUpdateTypeFailsIfNoChanges() { $args = self::$updateCommand->parseArgs(new StringArgs('my/type')); $typeDescriptor = new BindingTypeDescriptor('my/type'); $typeDescriptor->load($this->packages->getRootPackage()); $this->discoveryManager->expects($this->once())->method('getRootBindingType')->with('my/type')->willReturn($typeDescriptor); $this->discoveryManager->expects($this->never())->method('addRootBindingType'); $this->handler->handleUpdate($args); }
/** * @expectedException \RuntimeException * @expectedExceptionMessage Cannot disable bindings in the package "vendor/root". */ public function testDisableBindingFailsIfRoot() { $args = self::$disableCommand->parseArgs(new StringArgs('ab12')); $descriptor = new BindingDescriptor('/path', 'my/type', array(), 'glob'); $descriptor->load($this->packages->getRootPackage()); $this->discoveryManager->expects($this->once())->method('findBindings')->with($this->uuid('ab12'))->willReturn(array($descriptor)); $this->discoveryManager->expects($this->never())->method('disableBinding'); $this->handler->handleDisable($args, $this->io); }
/** * Returns the packages selected in the console arguments. * * @param Args $args The console arguments. * @param PackageCollection $packages The available packages. * * @return string[] The package names. */ public static function getPackageNames(Args $args, PackageCollection $packages) { // Display all packages if "all" is set if ($args->isOptionSet('all')) { return $packages->getPackageNames(); } $packageNames = array(); if ($args->isOptionSet('root')) { $packageNames[] = $packages->getRootPackage()->getName(); } foreach ($args->getOption('package') as $packageName) { $packageNames[] = $packageName; } return $packageNames ?: $packages->getPackageNames(); }
private function initDefaultManager() { $conflictMappingRoot1 = new PathMapping('/conflict1', array('res', 'assets')); $conflictMappingPackage11 = new PathMapping('/conflict1', array('res', '@vendor/package2:res')); $conflictMappingPackage12 = new PathMapping('/conflict2', 'res'); $conflictMappingPackage21 = new PathMapping('/conflict1', 'res'); $conflictMappingPackage22 = new PathMapping('/conflict2', 'res'); $conflictMappingRoot1->load($this->packages->getRootPackage(), $this->packages); $conflictMappingPackage11->load($this->packages->get('vendor/package1'), $this->packages); $conflictMappingPackage12->load($this->packages->get('vendor/package1'), $this->packages); $conflictMappingPackage21->load($this->packages->get('vendor/package2'), $this->packages); $conflictMappingPackage22->load($this->packages->get('vendor/package2'), $this->packages); $conflict1 = new PathConflict('/conflict1'); $conflict1->addMappings(array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage21)); $conflict2 = new PathConflict('/conflict2/sub/path'); $conflict2->addMappings(array($conflictMappingPackage12, $conflictMappingPackage22)); $this->repoManager->expects($this->any())->method('findPathMappings')->willReturnCallback($this->returnFromMap(array(array($this->packageAndState('vendor/root', PathMappingState::ENABLED), array(new PathMapping('/root/enabled', array('res', 'assets')))), array($this->packageAndState('vendor/package1', PathMappingState::ENABLED), array(new PathMapping('/package1/enabled', array('res', '@vendor/package2:res')))), array($this->packageAndState('vendor/package2', PathMappingState::ENABLED), array(new PathMapping('/package2/enabled', 'res'))), array($this->packageAndState('vendor/root', PathMappingState::NOT_FOUND), array(new PathMapping('/root/not-found', 'res'))), array($this->packageAndState('vendor/package1', PathMappingState::NOT_FOUND), array(new PathMapping('/package1/not-found', 'res'))), array($this->packageAndState('vendor/package2', PathMappingState::NOT_FOUND), array(new PathMapping('/package2/not-found', 'res'))), array($this->packagesAndState(array('vendor/root'), PathMappingState::CONFLICT), array($conflictMappingRoot1)), array($this->packagesAndState(array('vendor/package1'), PathMappingState::CONFLICT), array($conflictMappingPackage11, $conflictMappingPackage12)), array($this->packagesAndState(array('vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/root', 'vendor/package1'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage12)), array($this->packagesAndState(array('vendor/root', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/package1', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingPackage11, $conflictMappingPackage12, $conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/root', 'vendor/package1', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage12, $conflictMappingPackage21, $conflictMappingPackage22))))); }
/** * Creates a tag manager. * * @param ProjectEnvironment $environment * @param EditableDiscovery $discovery * @param PackageCollection $packages * @param PackageFileStorage $packageFileStorage * @param LoggerInterface $logger */ public function __construct(ProjectEnvironment $environment, EditableDiscovery $discovery, PackageCollection $packages, PackageFileStorage $packageFileStorage, LoggerInterface $logger = null) { $this->environment = $environment; $this->discovery = $discovery; $this->packages = $packages; $this->packageFileStorage = $packageFileStorage; $this->rootPackage = $packages->getRootPackage(); $this->rootPackageFile = $environment->getRootPackageFile(); $this->logger = $logger ?: new NullLogger(); }
/** * Creates a repository manager. * * @param ProjectEnvironment $environment * @param EditableRepository $repo * @param PackageCollection $packages * @param PackageFileStorage $packageFileStorage */ public function __construct(ProjectEnvironment $environment, EditableRepository $repo, PackageCollection $packages, PackageFileStorage $packageFileStorage) { $this->environment = $environment; $this->dispatcher = $environment->getEventDispatcher(); $this->repo = $repo; $this->config = $environment->getConfig(); $this->rootDir = $environment->getRootDirectory(); $this->rootPackage = $packages->getRootPackage(); $this->rootPackageFile = $environment->getRootPackageFile(); $this->packages = $packages; $this->packageFileStorage = $packageFileStorage; }
/** * Creates an override graph for the given packages. * * @param PackageCollection $packages The packages to load. * * @return static The created override graph. */ public static function forPackages(PackageCollection $packages) { $graph = new static($packages->getPackageNames()); foreach ($packages as $package) { foreach ($package->getPackageFile()->getOverriddenPackages() as $overriddenPackage) { if ($graph->hasPackageName($overriddenPackage)) { $graph->addEdge($overriddenPackage, $package->getName()); } } } // Make sure we have numeric, ascending keys here $packageOrder = array_values($packages->getRootPackage()->getPackageFile()->getOverrideOrder()); // Each package overrides the previous one in the list for ($i = 1, $l = count($packageOrder); $i < $l; ++$i) { $overriddenPackage = $packageOrder[$i - 1]; $overridingPackage = $packageOrder[$i]; if ($graph->hasPackageName($overriddenPackage)) { $graph->addEdge($overriddenPackage, $overridingPackage); } } return $graph; }
/** * {@inheritdoc} */ public function getRootPackage() { $this->assertPackagesLoaded(); return $this->packages->getRootPackage(); }
public function __construct(RootPackageFileManager $rootPackageFileManager, PackageCollection $packages) { $this->rootPackageFileManager = $rootPackageFileManager; $this->packages = $packages; $this->rootPackage = $packages->getRootPackage(); }