mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Behat] Refactor subresources removal
This commit is contained in:
parent
a6b8c46d0a
commit
9bd483ff25
6 changed files with 39 additions and 8 deletions
|
|
@ -73,7 +73,9 @@ interface ApiClientInterface
|
|||
|
||||
public function addSubResourceData(string $key, array $data): void;
|
||||
|
||||
public function removeSubResource(string $subResource, string $id): void;
|
||||
public function removeSubResourceIri(string $subResourceKey, string $iri): void;
|
||||
|
||||
public function removeSubResourceObject(string $subResourceKey, string $value, string $key = '@id'): void;
|
||||
|
||||
public function updateRequestData(array $data): void;
|
||||
|
||||
|
|
|
|||
|
|
@ -231,9 +231,14 @@ final class ApiPlatformClient implements ApiClientInterface
|
|||
$this->request->addSubResource($key, $data);
|
||||
}
|
||||
|
||||
public function removeSubResource(string $subResource, string $id): void
|
||||
public function removeSubResourceIri(string $subResourceKey, string $iri): void
|
||||
{
|
||||
$this->request->removeSubResource($subResource, $id);
|
||||
$this->request->removeSubResource($subResourceKey, $iri);
|
||||
}
|
||||
|
||||
public function removeSubResourceObject(string $subResourceKey, string $value, string $key = '@id'): void
|
||||
{
|
||||
$this->request->removeSubResource($subResourceKey, $value, $key);
|
||||
}
|
||||
|
||||
public function getContent(): array
|
||||
|
|
|
|||
|
|
@ -95,11 +95,19 @@ final class Request implements RequestInterface
|
|||
$this->content[$key][] = $subResource;
|
||||
}
|
||||
|
||||
public function removeSubResource(string $subResource, string $id): void
|
||||
public function removeSubResource(string $subResourceKey, string $value, string $key = '@id'): void
|
||||
{
|
||||
foreach ($this->content[$subResource] as $key => $resource) {
|
||||
if ($resource === $id) {
|
||||
unset($this->content[$subResource][$key]);
|
||||
foreach ($this->content[$subResourceKey] as $index => $objectOrIri) {
|
||||
if (is_array($objectOrIri)) {
|
||||
if (isset($objectOrIri[$key]) && $objectOrIri[$key] === $value) {
|
||||
unset($this->content[$subResourceKey][$index]);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($objectOrIri === $value) {
|
||||
unset($this->content[$subResourceKey][$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ interface RequestInterface
|
|||
|
||||
public function addSubResource(string $key, array $subResource): void;
|
||||
|
||||
public function removeSubResource(string $subResource, string $id): void;
|
||||
public function removeSubResource(string $subResourceKey, string $value, string $key = '@id'): void;
|
||||
|
||||
public function authorize(?string $token, string $authorizationHeader): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,6 +208,17 @@ final class ResponseChecker implements ResponseCheckerInterface
|
|||
return false;
|
||||
}
|
||||
|
||||
public function hasItemWithTranslationInCollection(array $items, string $locale, string $key, string $translation): bool
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
if (isset($item['translations'][$locale]) && $item['translations'][$locale][$key] === $translation) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasKey(Response $response, string $key): bool
|
||||
{
|
||||
$content = json_decode($response->getContent(), true);
|
||||
|
|
|
|||
|
|
@ -76,6 +76,11 @@ interface ResponseCheckerInterface
|
|||
|
||||
public function hasItemWithTranslation(Response $response, string $locale, string $key, string $translation): bool;
|
||||
|
||||
/**
|
||||
* @param array<array-key, array> $items
|
||||
*/
|
||||
public function hasItemWithTranslationInCollection(array $items, string $locale, string $key, string $translation): bool;
|
||||
|
||||
public function hasKey(Response $response, string $key): bool;
|
||||
|
||||
public function hasTranslation(Response $response, string $locale, string $key, string $translation): bool;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue