Skip to content

Commit

Permalink
Fix provider and dist removal (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
karniv00l authored May 21, 2020
1 parent a2481e8 commit ba6ac23
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function __invoke(RemoveOrganization $message): void
foreach ($organization->synchronizedPackages() as $package) {
$this
->packageManager
->removeProvider($package->organizationAlias(), (string) $package->name());
->removeProvider($package->organizationAlias(), (string) $package->name())
->removeDist($package->organizationAlias(), (string) $package->name());
}

$this->packageManager->removeOrganizationDir($organization->alias());
Expand Down
3 changes: 2 additions & 1 deletion src/MessageHandler/Organization/RemovePackageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function __invoke(RemovePackage $message): void
if ($package->isSynchronized()) {
$this
->packageManager
->removeProvider($package->organizationAlias(), (string) $package->name());
->removeProvider($package->organizationAlias(), (string) $package->name())
->removeDist($package->organizationAlias(), (string) $package->name());
}
}
}
11 changes: 7 additions & 4 deletions src/Service/Organization/PackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ public function saveProvider(array $json, string $organizationAlias, string $pac
public function removeProvider(string $organizationAlias, string $packageName): self
{
$file = $this->filepath($organizationAlias, $packageName);
$names = explode('/', $packageName);
$distDir = $this->baseDir.'/'.$organizationAlias.'/dist/'.$names[0];

if (is_file($file)) {
$this->filesystem->remove(dirname($file));
$this->filesystem->remove($file);
}

return $this;
}

public function removeDist(string $organizationAlias, string $packageName): self
{
$distDir = $this->baseDir.'/'.$organizationAlias.'/dist/'.$packageName;
if (is_dir($distDir)) {
$this->filesystem->remove($distDir);
}
Expand Down
38 changes: 33 additions & 5 deletions tests/Unit/Service/Organization/PackageManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,44 @@ public function testRemoveProvider(): void
);

$org = 'buddy';
$package = 'hello/world';
$package1 = 'vendor/package1';
$package2 = 'vendor/package2';

$manager->saveProvider([], $org, $package);
$manager->saveProvider([], $org, $package1);
$manager->saveProvider([], $org, $package2);

self::assertTrue(is_dir($this->baseDir.'/buddy/p/hello'));
self::assertTrue(file_exists($this->baseDir.'/buddy/p/'.$package1.'.json'));
self::assertTrue(file_exists($this->baseDir.'/buddy/p/'.$package2.'.json'));

$manager->removeProvider($org, $package1);

self::assertTrue(is_dir($this->baseDir.'/buddy'));
self::assertTrue(is_dir(dirname($this->baseDir.'/buddy/p/'.$package1)));
self::assertFalse(file_exists($this->baseDir.'/buddy/p/'.$package1.'.json'));
self::assertTrue(file_exists($this->baseDir.'/buddy/p/'.$package2.'.json'));
}

public function testRemoveDist(): void
{
$manager = new PackageManager(
new FileStorage($this->baseDir, new FakeDownloader()),
$this->baseDir,
$this->filesystem
);

$org = 'buddy';
$package1 = 'vendor/package1';
$package2 = 'vendor/package2';

@mkdir($this->baseDir.'/buddy/dist/'.$package1, 0777, true);
@mkdir($this->baseDir.'/buddy/dist/'.$package2, 0777, true);

$manager->removeProvider($org, $package);
$manager->removeDist($org, $package1);

self::assertTrue(is_dir($this->baseDir.'/buddy'));
self::assertFalse(is_dir($this->baseDir.'/buddy/p/hello'));
self::assertTrue(is_dir($this->baseDir.'/buddy/dist/vendor'));
self::assertFalse(is_dir($this->baseDir.'/buddy/dist/'.$package1));
self::assertTrue(is_dir($this->baseDir.'/buddy/dist/'.$package2));
}

public function testRemoveOrganizationDir(): void
Expand Down

0 comments on commit ba6ac23

Please sign in to comment.