/** * Returns the non-root 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 getPackageNamesWithoutRoot(Args $args, PackageCollection $packages) { // Display all packages if "all" is set if ($args->isOptionSet('all')) { return $packages->getInstalledPackageNames(); } $packageNames = array(); foreach ($args->getOption('package') as $packageName) { $packageNames[] = $packageName; } return $packageNames ?: $packages->getInstalledPackageNames(); }
public function testGetInstalledPackageNames() { $packageFile1 = new PackageFile('vendor/package1'); $package1 = new Package($packageFile1, '/path1'); $packageFile2 = new PackageFile('vendor/package2'); $package2 = new Package($packageFile2, '/path2'); $this->collection->add($package1); $this->collection->add($package2); $this->assertSame(array('vendor/package1', 'vendor/package2'), $this->collection->getInstalledPackageNames()); }