Skip to content

Commit 90967b7

Browse files
authored
Merge pull request #703 from code16/fix-testing-dynamic-entity-keys
Fix testing with dynamic entity keys
2 parents bc02c4d + eb7eb55 commit 90967b7

5 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/Utils/Testing/EntityList/PendingEntityList.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ public function instanceCommand(string $commandKeyOrClassName, int|string $insta
182182

183183
protected function entityListShowField(): ?SharpShowEntityListField
184184
{
185-
/** @noinspection PhpIncompatibleReturnTypeInspection */
186-
return $this->parent instanceof PendingShow
187-
? $this->parent->show->getBuiltFields()
185+
if ($this->parent instanceof PendingShow) {
186+
/** @noinspection PhpIncompatibleReturnTypeInspection */
187+
return $this->parent->show->getBuiltFields()
188188
->first(fn (SharpShowField $field) => $field instanceof SharpShowEntityListField
189189
&& $field->toArray()['entityListKey'] === $this->entityKey
190-
)
191-
: null;
190+
);
191+
}
192+
193+
return null;
192194
}
193195

194196
protected function entityListQueryParams(): array

src/Utils/Testing/GeneratesCurrentPageUrl.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
namespace Code16\Sharp\Utils\Testing;
44

5-
use Code16\Sharp\Utils\Links\BreadcrumbBuilder;
6-
75
trait GeneratesCurrentPageUrl
86
{
9-
private function buildCurrentPageUrl(BreadcrumbBuilder $builder): string
7+
private function buildCurrentPageUrl(string $breadcrumbUri): string
108
{
119
return url(
1210
sprintf(
1311
'/%s/%s/%s',
1412
sharp()->config()->get('custom_url_segment'),
1513
sharp()->context()->globalFilterUrlSegmentValue(),
16-
$builder->generateUri()
14+
$breadcrumbUri
1715
)
1816
);
1917
}

src/Utils/Testing/IsPendingComponent.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ protected function getParentUri(): string
1818
return $this->breadcrumbBuilder($this->parents())->generateUri();
1919
}
2020

21+
protected function getCurrentUri(): string
22+
{
23+
return $this->breadcrumbBuilder([...$this->parents(), $this])->generateUri();
24+
}
25+
2126
protected function getCurrentPageUrlFromParents(): string
2227
{
23-
return $this->buildCurrentPageUrl($this->breadcrumbBuilder([...$this->parents(), $this]));
28+
return $this->buildCurrentPageUrl($this->getCurrentUri());
2429
}
2530

2631
protected function breadcrumbBuilder(array $components): BreadcrumbBuilder

src/Utils/Testing/SharpAssertions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function deleteFromSharpList(string $entityClassNameOrKey, mixed $instanc
103103
->withHeader(
104104
SharpBreadcrumb::CURRENT_PAGE_URL_HEADER,
105105
$this->buildCurrentPageUrl(
106-
$this->breadcrumbBuilder($entityKey)
106+
$this->breadcrumbBuilder($entityKey)->generateUri()
107107
),
108108
)
109109
->delete(
@@ -253,7 +253,7 @@ public function callSharpInstanceCommandFromList(
253253
->withHeader(
254254
SharpBreadcrumb::CURRENT_PAGE_URL_HEADER,
255255
$this->buildCurrentPageUrl(
256-
$this->breadcrumbBuilder($entityKey)
256+
$this->breadcrumbBuilder($entityKey)->generateUri()
257257
),
258258
)
259259
->postJson(
@@ -284,7 +284,7 @@ public function callSharpInstanceCommandFromShow(
284284
->withHeader(
285285
SharpBreadcrumb::CURRENT_PAGE_URL_HEADER,
286286
$this->buildCurrentPageUrl(
287-
$this->breadcrumbBuilder($entityKey, $instanceId)
287+
$this->breadcrumbBuilder($entityKey, $instanceId)->generateUri()
288288
),
289289
)
290290
->postJson(
@@ -313,7 +313,7 @@ public function callSharpEntityCommandFromList(
313313
return $this
314314
->withHeader(
315315
SharpBreadcrumb::CURRENT_PAGE_URL_HEADER,
316-
$this->buildCurrentPageUrl($this->breadcrumbBuilder($entityKey))
316+
$this->buildCurrentPageUrl($this->breadcrumbBuilder($entityKey)->generateUri())
317317
)
318318
->postJson(
319319
route('code16.sharp.api.list.command.entity', compact('entityKey', 'commandKey')),

src/Utils/Testing/Show/PendingShow.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function __construct(
3232
) {
3333
$this->entityKey = app(SharpEntityManager::class)->entityKeyFor($entityKey);
3434
$this->show = app(SharpEntityManager::class)->entityFor($this->entityKey)->getShowOrFail();
35+
sharp()->context()->breadcrumb()->forceRequestSegments(
36+
explode('/', $this->getCurrentUri())
37+
);
3538
}
3639

3740
public function sharpForm(string $entityClassNameOrKey): PendingForm

0 commit comments

Comments
 (0)