Skip to content

Commit

Permalink
delete bound storage
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot authored and Huxinator committed Dec 9, 2023
1 parent 9adfc9d commit c60bec3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/Module/Ship/Lib/Interaction/ShipTakeoverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,15 @@ private function changeShipOwner(ShipInterface $ship, UserInterface $user): void
$this->shipRepository->save($ship);

// change storage owner
foreach ($ship->getStorage() as $storage) {
$storage->setUser($user);
$this->storageRepository->save($storage);
foreach ($ship->getStorage() as $storage) { #

if ($storage->getCommodity()->isBoundToAccount()) {
$ship->getStorage()->removeElement($storage);
$this->storageRepository->delete($storage);
} else {
$storage->setUser($user);
$this->storageRepository->save($storage);
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion tests/Module/Ship/Lib/Interaction/ShipTakeoverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ public function testFinishTakeover(): void
$user = $this->mock(UserInterface::class);
$targetUser = $this->mock(UserInterface::class);
$storage = $this->mock(StorageInterface::class);
$boundStorage = $this->mock(StorageInterface::class);

$takeover->shouldReceive('getSourceShip')
->withNoArgs()
Expand Down Expand Up @@ -604,7 +605,7 @@ public function testFinishTakeover(): void
->andReturn($targetUser);
$this->target->shouldReceive('getStorage')
->withNoArgs()
->andReturn(new ArrayCollection([$storage]));
->andReturn(new ArrayCollection([$storage, $boundStorage]));
$this->target->shouldReceive('setUser')
->with($user)
->once();
Expand All @@ -628,6 +629,14 @@ public function testFinishTakeover(): void
$storage->shouldReceive('setUser')
->with($user)
->once();
$storage->shouldReceive('getCommodity->isBoundToAccount')
->withNoArgs()
->once()
->andReturnFalse();
$boundStorage->shouldReceive('getCommodity->isBoundToAccount')
->withNoArgs()
->once()
->andReturnTrue();

$this->shipTakeoverRepository->shouldReceive('delete')
->with($takeover)
Expand All @@ -643,6 +652,9 @@ public function testFinishTakeover(): void
$this->storageRepository->shouldReceive('save')
->with($storage)
->once();
$this->storageRepository->shouldReceive('delete')
->with($boundStorage)
->once();

$this->privateMessageSender->shouldReceive('send')
->with(
Expand Down

0 comments on commit c60bec3

Please sign in to comment.