Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Fakes/WindowManagerFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class WindowManagerFake implements WindowManagerContract

public array $hidden = [];

public array $shown = [];

public array $forcedWindowReturnValues = [];

public function __construct(
Expand Down Expand Up @@ -64,6 +66,11 @@ public function hide($id = null)
$this->hidden[] = $id;
}

public function show($id = null)
{
$this->shown[] = $id;
}

public function current(): Window
{
$this->ensureForceReturnWindowsProvided();
Expand Down Expand Up @@ -156,6 +163,27 @@ public function assertHidden(string|Closure $id): void
PHPUnit::assertTrue($hit);
}

/**
* @param string|Closure(string): bool $id
*/
public function assertShown(string|Closure $id): void
{
if (is_callable($id) === false) {
PHPUnit::assertContains($id, $this->shown);

return;
}

$hit = empty(
array_filter(
$this->shown,
fn (mixed $shownId) => $id($shownId) === true
)
) === false;

PHPUnit::assertTrue($hit);
}

public function assertOpenedCount(int $expected): void
{
PHPUnit::assertCount($expected, $this->opened);
Expand All @@ -171,6 +199,11 @@ public function assertHiddenCount(int $expected): void
PHPUnit::assertCount($expected, $this->hidden);
}

public function assertShownCount(int $expected): void
{
PHPUnit::assertCount($expected, $this->shown);
}

private function ensureForceReturnWindowsProvided(): void
{
Assert::notEmpty($this->forcedWindowReturnValues, 'No windows were provided to return');
Expand Down
7 changes: 7 additions & 0 deletions src/Windows/WindowManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public function hide($id = null)
]);
}

public function show($id = null)
{
$this->client->post('window/show', [
'id' => $id ?? $this->detectId(),
]);
}

public function current(): Window
{
$window = (object) $this->client->get('window/current')->json();
Expand Down
36 changes: 36 additions & 0 deletions tests/Fakes/FakeWindowManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@
$this->fail('Expected assertion to fail');
});

it('asserts that a window was shown', function () {
swap(WindowManagerContract::class, $fake = app(WindowManagerFake::class));

app(WindowManagerContract::class)->show('main');
app(WindowManagerContract::class)->show('secondary');

$fake->assertShown('main');
$fake->assertShown('secondary');

try {
$fake->assertShown('tertiary');
} catch (AssertionFailedError) {
return;
}

$this->fail('Expected assertion to fail');
});

it('asserts opened count', function () {
Http::fake(['*' => Http::response(status: 200)]);

Expand Down Expand Up @@ -196,6 +214,24 @@
$this->fail('Expected assertion to fail');
});

it('asserts shown count', function () {
swap(WindowManagerContract::class, $fake = app(WindowManagerFake::class));

app(WindowManagerContract::class)->show('main');
app(WindowManagerContract::class)->show();
app(WindowManagerContract::class)->show();

$fake->assertShownCount(3);

try {
$fake->assertShownCount(4);
} catch (AssertionFailedError) {
return;
}

$this->fail('Expected assertion to fail');
});

it('forces the return value of current window', function () {
swap(WindowManagerContract::class, $fake = app(WindowManagerFake::class));

Expand Down
Loading