Skip to content

Commit

Permalink
TASK: Improve asset usage test match error
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 29, 2024
1 parent 98a7cb1 commit f8ca75f
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions Neos.Neos/Tests/Behavior/Features/Bootstrap/AssetUsageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,10 @@ public function iExpectTheAssetUsageServiceToHaveTheFollowingAssetUsages(TableNo
}
}

// echo json_encode($tableRows, JSON_PRETTY_PRINT);
// echo json_encode($assetUsages, JSON_PRETTY_PRINT);
Assert::assertEmpty($tableRows, "Not all given asset usages where found: " . json_encode($tableRows, JSON_PRETTY_PRINT));
Assert::assertSame(count($assetUsages), count($table->getHash()), "More asset usages found as given.");

}

public function fewfw(TableNode $table)
{
$assetUsageService = $this->getObject(AssetUsageService::class);
$assetUsages = $assetUsageService->findByFilter($this->currentContentRepository->id, AssetUsageFilter::create());

$actual = [];
foreach ($assetUsages as $assetUsage) {
$actual[] = [
'assetId' => $assetUsage->assetId,
'propertyName' => $assetUsage->propertyName,
'workspaceName' => $assetUsage->workspaceName->value,
'nodeAggregateId' => $assetUsage->nodeAggregateId->value,
'originDimensionSpacePoint' => str_replace('":"', '": "', $assetUsage->originDimensionSpacePoint->toJson()),
];
}

$expected = $table->getHash();

$sorter = fn ($a, $b) => $a <=> $b;

usort($expected, $sorter);
usort($actual, $sorter);

Assert::assertSame($expected, $actual, "Not all given asset usages where found.");
Assert::assertTrue(
$tableRows === [] && count($assetUsages) === count($table->getHash()),
sprintf('Mismatch between all actual asset usages %s and leftover asset usages to match %s', json_encode($assetUsages, JSON_PRETTY_PRINT), json_encode($tableRows, JSON_PRETTY_PRINT))
);
}

/**
Expand Down

0 comments on commit f8ca75f

Please sign in to comment.