mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-09 12:39:30 +00:00
Added tests for new DTO objects
This commit is contained in:
parent
b94e28a961
commit
5b71d68179
5 changed files with 186 additions and 7 deletions
|
|
@ -41,21 +41,27 @@ readonly class BulkSearchResponseDTO implements \ArrayAccess, \IteratorAggregate
|
|||
|
||||
/**
|
||||
* Replaces the search results for a specific part, and returns a new instance.
|
||||
* @param Part|int $part
|
||||
* The part to replaced, is identified by the part property of the new_results parameter.
|
||||
* The original instance remains unchanged.
|
||||
* @param BulkSearchPartResultsDTO $new_results
|
||||
* @return BulkSearchResponseDTO
|
||||
*/
|
||||
public function replaceResultsForPart(Part|int $part, BulkSearchPartResultsDTO $new_results): self
|
||||
public function replaceResultsForPart(BulkSearchPartResultsDTO $new_results): self
|
||||
{
|
||||
$array = $this->partResults;
|
||||
$replaced = false;
|
||||
foreach ($array as $index => $partResult) {
|
||||
if (($part instanceof Part && $partResult->part->getId() === $part->getId()) ||
|
||||
($partResult->part->getId() === $part)) {
|
||||
if ($partResult->part === $new_results->part) {
|
||||
$array[$index] = $new_results;
|
||||
$replaced = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$replaced) {
|
||||
throw new \InvalidArgumentException("Part not found in existing results.");
|
||||
}
|
||||
|
||||
return new self($array);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue