mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-09 20:49: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
|
|
@ -101,7 +101,7 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
return $job;
|
||||
}
|
||||
|
||||
private function updatePartSearchResults(BulkInfoProviderImportJob $job, int $partId, ?BulkSearchPartResultsDTO $newResults): void
|
||||
private function updatePartSearchResults(BulkInfoProviderImportJob $job, ?BulkSearchPartResultsDTO $newResults): void
|
||||
{
|
||||
if ($newResults === null) {
|
||||
return;
|
||||
|
|
@ -111,7 +111,7 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
$allResults = $job->getSearchResults($this->entityManager);
|
||||
|
||||
// Find and update the results for this specific part
|
||||
$allResults = $allResults->replaceResultsForPart($partId, $newResults);
|
||||
$allResults = $allResults->replaceResultsForPart($newResults);
|
||||
|
||||
// Save updated results back to job
|
||||
$job->setSearchResults($allResults);
|
||||
|
|
@ -482,7 +482,7 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
}
|
||||
|
||||
// Update the job's search results for this specific part efficiently
|
||||
$this->updatePartSearchResults($job, $partId, $searchResultsDto[0] ?? null);
|
||||
$this->updatePartSearchResults($job, $searchResultsDto[0] ?? null);
|
||||
|
||||
// Prefetch details if requested
|
||||
if ($prefetchDetails && $searchResultsDto !== null) {
|
||||
|
|
|
|||
|
|
@ -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