Skip to content
Open
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
9 changes: 2 additions & 7 deletions src/Spotlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@ public function searchDependency(string $commandId, $dependency, $query, $resolv
$params = array_merge(['query' => $query], (array) $resolvedDependencies);

$this->dependencyQueryResults = collect(ImplicitlyBoundMethod::call(app(), [$command, $method], $params))
->map(function (SpotlightSearchResult $result) {
return [
'id' => $result->getId(),
'name' => $result->getName(),
'description' => $result->getDescription(),
];
})->toArray();
->map(fn (SpotlightSearchResult $result) => $result->toArray())
->toArray();
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/SpotlightSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public function getDescription(): ?string
{
return $this->description;
}

public function toArray(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
];
}
}
37 changes: 37 additions & 0 deletions tests/Commands/LogoutTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare(strict_types=1);

namespace LivewireUI\Spotlight\Tests\Commands;

use Illuminate\Contracts\Auth\StatefulGuard;
use LivewireUI\Spotlight\Commands\Logout;
use LivewireUI\Spotlight\Spotlight;
use PHPUnit\Framework\TestCase;

class LogoutTest extends TestCase
{
/** @test */
public function it_logs_out_the_current_user(): void
{
$spotlight = $this->createMock(Spotlight::class);
$guardMock = $this->createMock(StatefulGuard::class);
$guardMock->expects($this->once())->method('logout');

$command = new Logout();

$command->execute($spotlight, $guardMock);
}

/** @test */
public function it_redirects_after_logout(): void
{
$spotlight = $this->createMock(Spotlight::class);
$spotlight->expects($this->once())
->method('redirect')
->with('/');
$guardMock = $this->createMock(StatefulGuard::class);

$command = new Logout();

$command->execute($spotlight, $guardMock);
}
}
12 changes: 0 additions & 12 deletions tests/ExampleTest.php

This file was deleted.

62 changes: 62 additions & 0 deletions tests/SpotlightCommandDependenciesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php declare(strict_types=1);

namespace LivewireUI\Spotlight\Tests;

use LivewireUI\Spotlight\SpotlightCommandDependencies;
use LivewireUI\Spotlight\SpotlightCommandDependency;

class SpotlightCommandDependenciesTest extends \PHPUnit\Framework\TestCase
{
/** @test */
public function it_is_empty_by_default(): void
{
$dependencies = new SpotlightCommandDependencies();

self::assertEquals([], $dependencies->toArray());
}

/** @test */
public function it_correctly_serializes_for_a_single_dependency(): void
{
$dependencies = SpotlightCommandDependencies::collection()
->add(
SpotlightCommandDependency::make('::id-1::')
->setPlaceholder('::placeholder-1::')
);

self::assertEquals([
[
'id' => '::id-1::',
'placeholder' => '::placeholder-1::',
'type' => 'search',
]
], $dependencies->toArray());
}

/** @test */
public function it_returns_the_dependencies_in_reversed_order(): void
{
$dependencies = SpotlightCommandDependencies::collection()
->add(
SpotlightCommandDependency::make('::id-1::')
->setPlaceholder('::placeholder-1::')
)
->add(
SpotlightCommandDependency::make('::id-2::')
->setPlaceholder('::placeholder-2::')
);

self::assertEquals([
[
'id' => '::id-2::',
'placeholder' => '::placeholder-2::',
'type' => 'search',
],
[
'id' => '::id-1::',
'placeholder' => '::placeholder-1::',
'type' => 'search',
],
], $dependencies->toArray());
}
}
53 changes: 53 additions & 0 deletions tests/SpotlightCommandDependencyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);

namespace LivewireUI\Spotlight\Tests;

use Generator;
use LivewireUI\Spotlight\SpotlightCommandDependency;

class SpotlightCommandDependencyTest extends \PHPUnit\Framework\TestCase
{
/**
* @test
* @dataProvider dependencyProvider
*/
public function it_can_be_turned_into_an_array(string $identifier, callable $configureDependency, array $expected): void
{
$commandDependency = SpotlightCommandDependency::make($identifier);

$configureDependency($commandDependency);

self::assertEquals($expected, $commandDependency->toArray());
}

public function dependencyProvider(): Generator
{
yield from [
'no explicit type' => [
'::id::',
function (SpotlightCommandDependency $dependency) {
$dependency->setPlaceholder('::placeholder-1::');
},
[
'id' => '::id::',
'placeholder' => '::placeholder-1::',
'type' => SpotlightCommandDependency::SEARCH,
]
],

'provide explicit type' => [
'::id::',
function (SpotlightCommandDependency $dependency) {
$dependency
->setType(SpotlightCommandDependency::INPUT)
->setPlaceholder('::placeholder-2::');
},
[
'id' => '::id::',
'placeholder' => '::placeholder-2::',
'type' => SpotlightCommandDependency::INPUT,
]
]
];
}
}
43 changes: 43 additions & 0 deletions tests/SpotlightSearchResultTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace LivewireUI\Spotlight\Tests;

use LivewireUI\Spotlight\SpotlightSearchResult;

class SpotlightSearchResultTest extends \PHPUnit\Framework\TestCase
{
private SpotlightSearchResult $result;

protected function setUp(): void
{
$this->result = new SpotlightSearchResult('::id::', '::name::', '::description::');
}

/** @test */
public function it_can_be_turned_into_an_array(): void
{
self::assertEquals([
'id' => '::id::',
'name' => '::name::',
'description' => '::description::',
], $this->result->toArray());
}

/** @test */
public function it_returns_its_id(): void
{
self::assertEquals('::id::', $this->result->getId());
}

/** @test */
public function it_returns_its_description(): void
{
self::assertEquals('::description::', $this->result->getDescription());
}

/** @test */
public function it_returns_its_name(): void
{
self::assertEquals('::name::', $this->result->getName());
}
}
Loading