Skip to content

Commit

Permalink
Minor progress
Browse files Browse the repository at this point in the history
Add a Livewire and Volt helpers for quickly checking that components can mount.

Also discovering there's something wrong with finding the database. Sometimes it's there, sometimes the necessary tables are there...other times, not.
  • Loading branch information
JSn1nj4 committed Jul 7, 2024
1 parent 26d328a commit 4999752
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
3 changes: 2 additions & 1 deletion tests/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ trait CreatesApplication
*/
public function createApplication(): Application
{
$app = require __DIR__.'/../bootstrap/app.php';
/** @var Application $app */
$app = require __DIR__ . '/../bootstrap/app.php';

$app->make(Kernel::class)->bootstrap();

Expand Down
8 changes: 1 addition & 7 deletions tests/Feature/Livewire/BlogIndexTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<?php

use Livewire\Volt\Volt;

it('can render', function () {
$component = Volt::test('blog-index');

$component->assertSee('');
});
voltMountable('blog-index');
8 changes: 1 addition & 7 deletions tests/Feature/Livewire/BlogPostTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<?php

use Livewire\Volt\Volt;

it('can render', function () {
$component = Volt::test('blog-post');

$component->assertSee('');
});
voltMountable('blog-post', ['post' => createPost()]);
22 changes: 19 additions & 3 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
|
*/

use App\Actions\HashPassword;
use App\Models\Image;
use App\Models\Post;
use App\Models\Project;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Livewire\Livewire;
use Livewire\Volt\Volt;

uses(Tests\TestCase::class, DatabaseMigrations::class)
->in('Feature', 'Unit');
->in('Feature');

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -56,6 +59,7 @@ function createPost(): Post
return Post::factory()->createOne();
}


function createProject(): Project
{
return Project::factory()->createOne();
Expand All @@ -66,9 +70,9 @@ function createUser(): User
return User::factory()->createOne();
}

function hashPassword(#[\SensitiveParameter] string $password): string
function hashPassword(#[SensitiveParameter] string $password): string
{
$hashPassword = new \App\Actions\HashPassword();
$hashPassword = new HashPassword();

return $hashPassword($password);
}
Expand Down Expand Up @@ -99,3 +103,15 @@ function makeUser(): User
{
return User::factory()->makeOne();
}

// borrowed from Ryan Chandler:
// https://x.com/ryangjchandler/status/1808796458260341189
function livewireMountable(string $class, array $params = []): void
{
it('can be mounted', fn () => Livewire::test($class, $params)->assertOk());
}

function voltMountable(string $component, array $params = []): void
{
it('can be mounted', fn () => Volt::test($component, $params)->assertOk());
}

0 comments on commit 4999752

Please sign in to comment.