1
0
Fork 0

Merge pull request #212 from stof/find_packages_tests

Find packages tests
pull/210/merge
Jordi Boggiano 2012-01-16 13:50:54 -08:00
commit f273b436cc
2 changed files with 24 additions and 3 deletions

View File

@ -48,10 +48,15 @@ class ArrayRepository implements RepositoryInterface
{
// normalize name
$name = strtolower($name);
$packages = array();
return array_filter($this->getPackages(), function (PackageInterface $package) use ($name) {
return $package->getName() === $name;
});
foreach ($this->getPackages() as $package) {
if ($package->getName() === $name) {
$packages[] = $package;
}
}
return $packages;
}
/**

View File

@ -50,4 +50,20 @@ class ArrayRepositoryTest extends TestCase
$this->assertTrue($repo->hasPackage($this->getPackage('foo', '1')));
$this->assertFalse($repo->hasPackage($this->getPackage('bar', '1')));
}
public function testFindPackagesByName()
{
$repo = new ArrayRepository();
$repo->addPackage($this->getPackage('foo', '1'));
$repo->addPackage($this->getPackage('bar', '2'));
$repo->addPackage($this->getPackage('bar', '3'));
$foo = $repo->findPackagesByName('foo');
$this->assertCount(1, $foo);
$this->assertEquals('foo', $foo[0]->getName());
$bar = $repo->findPackagesByName('bar');
$this->assertCount(2, $bar);
$this->assertEquals('bar', $bar[0]->getName());
}
}