Skip to content

Commit

Permalink
Ammend getStaticPackages() to use PackageInterface
Browse files Browse the repository at this point in the history
When an instance of `\Composer\Package\AliasPackage` is found `getStaticPackages()` throws an exception.
All packages are required to implement `\Composer\Package\PackageInterface` so it makes more sense for the closure
arguement to require that instead.
  • Loading branch information
adam-paterson committed Oct 7, 2015
1 parent 79b6e89 commit 2b1c3fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/StaticsMergerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function getStaticPackages()
{
$packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();

return array_filter($packages, function (Package $package) {
return array_filter($packages, function (PackageInterface $package) {
return $package->getType() == static::PACKAGE_TYPE && $this->getStaticMaps($package->getName());
});
}
Expand Down
18 changes: 18 additions & 0 deletions test/StaticsMergerPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jh\StaticsMergerTest;

use Composer\Package\AliasPackage;
use Composer\Package\Package;
use Composer\Package\PackageInterface;
use Composer\Package\RootPackage;
Expand Down Expand Up @@ -974,4 +975,21 @@ public function relativePathTestDataProvider()
array('same/dir/assets/test', 'same/dir/assets/file', './file')
);
}

public function testGetStaticPackagesAllowsAliasPackageInstance()
{
$this->createRootPackage();
$staticPackage = $this->createStaticPackage();

$truePackage = new Package("package/package", "1.0.0", "package/package");
$aliasPackage = new AliasPackage($truePackage, '1.1.1', 'alias/package');

$this->localRepository->addPackage($aliasPackage);
$this->localRepository->addPackage($staticPackage);

$this->activatePlugin();
$staticPackages = $this->plugin->getStaticPackages();

$this->assertNotEmpty($staticPackages);
}
}

0 comments on commit 2b1c3fd

Please sign in to comment.