Add unit test to cover device URLs edition, and fix bug thanks to it

This commit is contained in:
Alejandro Celaya
2023-01-22 12:15:29 +01:00
parent 5aa8de11f4
commit b0b9902f40
3 changed files with 48 additions and 3 deletions

View File

@@ -174,12 +174,13 @@ class ShortUrl extends AbstractEntity
$this->deviceLongUrls->remove($deviceType->value);
}
foreach ($shortUrlEdit->deviceLongUrls as $deviceLongUrlPair) {
$deviceLongUrl = $this->deviceLongUrls->get($deviceLongUrlPair->deviceType->value);
$key = $deviceLongUrlPair->deviceType->value;
$deviceLongUrl = $this->deviceLongUrls->get($key);
if ($deviceLongUrl !== null) {
$deviceLongUrl->updateLongUrl($deviceLongUrlPair->longUrl);
} else {
$this->deviceLongUrls->add(DeviceLongUrl::fromShortUrlAndPair($this, $deviceLongUrlPair));
$this->deviceLongUrls->set($key, DeviceLongUrl::fromShortUrlAndPair($this, $deviceLongUrlPair));
}
}
}