8000 [Feature] Add fetched page in order assertion · AxonDivisionDev/laravel-json-api@0239e95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0239e95

Browse files
committed
[Feature] Add fetched page in order assertion
1 parent 652a179 commit 0239e95

File tree

1 file changed

+61
-12
lines changed

1 file changed

+61
-12
lines changed

src/Testing/TestResponse.php

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,30 @@ public function assertFetchedPage(
107107
bool $strict = true
108108
): self
109109
{
110-
if (empty($links) && empty($meta)) {
111-
throw new \InvalidArgumentException('Expecting links or meta to ensure response is a page.');
112-
}
113-
114-
$this->assertFetchedMany($expected, $strict);
110+
$this->assertPage($expected, $links, $meta, $metaKey, $strict);
115111

116-
if ($links) {
117-
$this->assertLinks($links, $strict);
118-
}
112+
return $this;
113+
}
119114

120-
if ($meta) {
121-
$meta = $metaKey ? [$metaKey => $meta] : $meta;
122-
$this->assertMeta($meta, $strict);
123-
}
115+
/**
116+
* Assert the response is a JSON API page with expected resources in the specified order.
117+
*
118+
* @param $expected
119+
* @param array|null $links
120+
* @param array|null $meta
121+
* @param string|null $metaKey
122+
* @param bool $strict
123+
* @return TestResponse
124+
*/
125+
public function assertFetchedPageInOrder(
126+
$expected,
127+
?array $links,
128+
?array $meta,
129+
string $metaKey = 'page',
130+
bool $strict = true
131+
): self
132+
{
133+
$this->assertPage($expected, $links, $meta, $metaKey, $strict, true);
124134

125135
return $this;
126136
}
@@ -449,4 +459,43 @@ protected function normalizeId($id)
449459
return (string) $id;
450460
}
451461

462+
/**
463+
* Assert the response is a JSON API page.
464+
*
465+
* @param $expected
466+
* @param array|null $links
467+
* @param array|null $meta
468+
* @param string|null $metaKey
469+
* @param bool $strict
470+
* @param bool $order
471+
* @return void
472+
*/
473+
private function assertPage(
474+
$expected,
475+
?array $links,
476+
?array $meta,
477+
string $metaKey = 'page',
478+
bool $strict = true,
479+
bool $order = false
480+
): void
481+
{
482+
if (empty($links) && empty($meta)) {
483+
throw new \InvalidArgumentException('Expecting links or meta to ensure response is a page.');
484+
}
485+
486+
if ($order) {
487+
$this->assertFetchedManyInOrder($expected, $strict);
488+
} else {
489+
$this->assertFetchedMany($expected, $strict);
490+
}
491+
492+
if ($links) {
493+
$this->assertLinks($links, $strict);
494+
}
495+
496+
if ($meta) {
497+
$meta = $metaKey ? [$metaKey => $meta] : $meta;
498+
$this->assertMeta($meta, $strict);
499+
}
500+
}
452501
}

0 commit comments

Comments
 (0)
0