mirror of
https://github.com/werkraum-media/thuecat.git
synced 2024-06-29 06:48:56 +02:00
Handle resources with missing containedInPlace
Check for situation and return empty array. Do not create unnecessary requests to database but directly return.
This commit is contained in:
parent
eac551e2bc
commit
6b19485a36
|
@ -94,6 +94,10 @@ class Parser
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($jsonLD['schema:containedInPlace']) === false) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return array_map(function (array $place) {
|
return array_map(function (array $place) {
|
||||||
return $place['@id'];
|
return $place['@id'];
|
||||||
}, $jsonLD['schema:containedInPlace']);
|
}, $jsonLD['schema:containedInPlace']);
|
||||||
|
|
|
@ -46,6 +46,10 @@ class TownRepository extends Repository
|
||||||
|
|
||||||
public function findOneByRemoteIds(array $remoteIds): ?Town
|
public function findOneByRemoteIds(array $remoteIds): ?Town
|
||||||
{
|
{
|
||||||
|
if ($remoteIds === []) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$query = $this->createQuery();
|
$query = $this->createQuery();
|
||||||
|
|
||||||
$query->in('remoteId', $remoteIds);
|
$query->in('remoteId', $remoteIds);
|
||||||
|
|
|
@ -211,6 +211,28 @@ class ParserTest extends TestCase
|
||||||
], $result);
|
], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function returnsContainedInPlaceIdsForNoEntry(): void
|
||||||
|
{
|
||||||
|
$genericFields = $this->prophesize(GenericFields::class);
|
||||||
|
$openingHours = $this->prophesize(OpeningHours::class);
|
||||||
|
$address = $this->prophesize(Address::class);
|
||||||
|
$media = $this->prophesize(Media::class);
|
||||||
|
|
||||||
|
$subject = new Parser(
|
||||||
|
$genericFields->reveal(),
|
||||||
|
$openingHours->reveal(),
|
||||||
|
$address->reveal(),
|
||||||
|
$media->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $subject->getContainedInPlaceIds([]);
|
||||||
|
|
||||||
|
self::assertSame([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue