chore: code refactor via rector

This commit is contained in:
idevakk
2025-11-14 02:01:01 -08:00
parent 90ab79b3a2
commit ae795880ed
148 changed files with 1520 additions and 1486 deletions

View File

@@ -2,6 +2,8 @@
namespace Tests\Concerns;
use Exception;
use Illuminate\Support\Collection;
use App\Models\Blog;
use App\Models\Menu;
use App\Models\Plan;
@@ -60,18 +62,12 @@ trait LoadsApplicationData
// Try to load data from database, but fail gracefully if tables don't exist
try {
$menus = cache()->remember('app_menus', now()->addHours(6), function () {
return Menu::all();
});
$menus = cache()->remember('app_menus', now()->addHours(6), Menu::all(...));
$blogs = cache()->remember('app_blogs', now()->addHours(6), function () {
return Blog::where('is_published', 1)->get();
});
$blogs = cache()->remember('app_blogs', now()->addHours(6), fn() => Blog::query()->where('is_published', 1)->get());
$plans = cache()->remember('app_plans', now()->addHours(6), function () {
return Plan::all();
});
} catch (\Exception $e) {
$plans = cache()->remember('app_plans', now()->addHours(6), Plan::all(...));
} catch (Exception) {
// Set empty collections if database tables don't exist
$menus = collect();
$blogs = collect();
@@ -79,13 +75,13 @@ trait LoadsApplicationData
}
// Ensure we always have collections, even if cache is empty
if (! ($menus instanceof \Illuminate\Support\Collection)) {
if (! ($menus instanceof Collection)) {
$menus = collect();
}
if (! ($blogs instanceof \Illuminate\Support\Collection)) {
if (! ($blogs instanceof Collection)) {
$blogs = collect();
}
if (! ($plans instanceof \Illuminate\Support\Collection)) {
if (! ($plans instanceof Collection)) {
$plans = collect();
}

View File

@@ -3,14 +3,15 @@
namespace Tests\Feature;
// Simple test to check if Laravel application is working
use Illuminate\Foundation\Application;
use Tests\TestCase;
class ApplicationTest extends TestCase
{
/** @test */
public function it_checks_if_application_is_running()
public function it_checks_if_application_is_running(): void
{
$this->assertInstanceOf(\Illuminate\Foundation\Application::class, $this->app);
$this->assertInstanceOf(Application::class, $this->app);
$this->assertEquals('ZEmailnator', config('app.name'));
}
}

View File

@@ -10,7 +10,7 @@ use Tests\TestCase;
class AppControllerTest extends TestCase
{
/** @test */
public function it_redirects_to_home_when_no_email_exists_in_mailbox()
public function it_redirects_to_home_when_no_email_exists_in_mailbox(): void
{
$response = $this->get('/mailbox');
@@ -18,7 +18,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_creates_custom_email_from_url_when_enabled()
public function it_creates_custom_email_from_url_when_enabled(): void
{
$email = 'custom@example.com';
@@ -28,7 +28,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_validates_email_parameter_in_mailbox_route()
public function it_validates_email_parameter_in_mailbox_route(): void
{
$response = $this->get('/mailbox/invalid-email');
@@ -37,7 +37,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_redirects_to_home_when_mailbox_slug_is_disabled()
public function it_redirects_to_home_when_mailbox_slug_is_disabled(): void
{
Config::set('app.settings.configuration_settings', json_encode([
'disable_mailbox_slug' => true,
@@ -49,7 +49,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_switches_email_successfully()
public function it_switches_email_successfully(): void
{
$email = 'newemail@example.com';
@@ -59,7 +59,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_redirects_to_home_when_switching_email_with_disabled_mailbox_slug()
public function it_redirects_to_home_when_switching_email_with_disabled_mailbox_slug(): void
{
Config::set('app.settings.configuration_settings', json_encode([
'disable_mailbox_slug' => true,
@@ -73,7 +73,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_deletes_email_successfully()
public function it_deletes_email_successfully(): void
{
$email = 'delete@example.com';
@@ -83,7 +83,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_redirects_to_home_when_deleting_email_without_parameter()
public function it_redirects_to_home_when_deleting_email_without_parameter(): void
{
$response = $this->get('/delete');
@@ -91,7 +91,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_switches_locale_successfully()
public function it_switches_locale_successfully(): void
{
$locale = 'es';
@@ -102,7 +102,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_aborts_with_400_for_invalid_locale()
public function it_aborts_with_400_for_invalid_locale(): void
{
$invalidLocale = 'invalid';
@@ -112,7 +112,7 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_redirects_back_after_locale_switch()
public function it_redirects_back_after_locale_switch(): void
{
$locale = 'fr';
@@ -123,12 +123,11 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_handles_get_string_between_method_correctly()
public function it_handles_get_string_between_method_correctly(): void
{
$controller = new AppController;
$reflection = new ReflectionClass($controller);
$method = $reflection->getMethod('getStringBetween');
$method->setAccessible(true);
$string = 'Hello [world] test';
$result = $method->invoke($controller, $string, '[', ']');
@@ -137,12 +136,11 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_handles_get_string_between_with_missing_end()
public function it_handles_get_string_between_with_missing_end(): void
{
$controller = new AppController;
$reflection = new ReflectionClass($controller);
$method = $reflection->getMethod('getStringBetween');
$method->setAccessible(true);
$string = 'Hello [world test';
$result = $method->invoke($controller, $string, '[', ']');
@@ -151,12 +149,11 @@ class AppControllerTest extends TestCase
}
/** @test */
public function it_handles_get_string_between_with_no_match()
public function it_handles_get_string_between_with_no_match(): void
{
$controller = new AppController;
$reflection = new ReflectionClass($controller);
$method = $reflection->getMethod('getStringBetween');
$method->setAccessible(true);
$string = 'Hello world test';
$result = $method->invoke($controller, $string, '[', ']');

View File

@@ -2,6 +2,8 @@
namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@@ -35,7 +37,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_rejects_webhook_with_invalid_data_type()
public function it_rejects_webhook_with_invalid_data_type(): void
{
$invalidData = [
'type' => 'invalid_type',
@@ -49,7 +51,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_rejects_webhook_with_missing_data_type()
public function it_rejects_webhook_with_missing_data_type(): void
{
$dataWithoutType = [
'email' => 'test@example.com',
@@ -63,7 +65,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_rejects_webhook_with_no_data()
public function it_rejects_webhook_with_no_data(): void
{
$response = $this->postJson('/webhook/oxapay', []);
@@ -72,7 +74,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_rejects_webhook_with_invalid_hmac_signature()
public function it_rejects_webhook_with_invalid_hmac_signature(): void
{
$validData = [
'type' => 'invoice',
@@ -84,7 +86,7 @@ class WebhookControllerTest extends TestCase
'date' => time(),
];
$postData = json_encode($validData);
json_encode($validData);
$invalidHmac = 'invalid_hmac_signature';
$response = $this->postJson('/webhook/oxapay', $validData, [
@@ -96,7 +98,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_processes_valid_invoice_webhook_successfully()
public function it_processes_valid_invoice_webhook_successfully(): void
{
$validData = [
'type' => 'invoice',
@@ -121,7 +123,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_processes_valid_payment_link_webhook_successfully()
public function it_processes_valid_payment_link_webhook_successfully(): void
{
$validData = [
'type' => 'payment_link',
@@ -146,7 +148,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_processes_valid_payout_webhook_successfully()
public function it_processes_valid_payout_webhook_successfully(): void
{
$validData = [
'type' => 'payout',
@@ -173,7 +175,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_handles_webhook_processing_errors_gracefully()
public function it_handles_webhook_processing_errors_gracefully(): void
{
// Use invalid date format to trigger error handling
$validData = [
@@ -201,7 +203,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_logs_invoice_payment_details_correctly()
public function it_logs_invoice_payment_details_correctly(): void
{
$validData = [
'type' => 'invoice',
@@ -227,7 +229,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_logs_payout_details_correctly()
public function it_logs_payout_details_correctly(): void
{
$validData = [
'type' => 'payout',
@@ -255,7 +257,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_logs_invalid_data_warnings()
public function it_logs_invalid_data_warnings(): void
{
$invalidData = [
'type' => 'invalid_type',
@@ -268,7 +270,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_logs_invalid_hmac_signature_warnings()
public function it_logs_invalid_hmac_signature_warnings(): void
{
$validData = [
'type' => 'invoice',
@@ -276,10 +278,7 @@ class WebhookControllerTest extends TestCase
'amount' => '100',
'currency' => 'USD',
];
$postData = json_encode($validData);
$apiSecretKey = 'test_merchant_key';
$validHmac = hash_hmac('sha512', $postData, $apiSecretKey);
json_encode($validData);
$invalidHmac = 'invalid_hmac';
$response = $this->postJson('/webhook/oxapay', $validData, [
@@ -290,7 +289,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_handles_webhook_processing_exceptions()
public function it_handles_webhook_processing_exceptions(): void
{
$validData = [
'type' => 'invoice',
@@ -311,9 +310,9 @@ class WebhookControllerTest extends TestCase
// Telegram notification for error is handled by error logging
// Simulate an exception during processing by mocking a method that gets called
$this->mock(\Carbon\Carbon::class)
$this->mock(Carbon::class)
->shouldReceive('createFromTimestamp')
->andThrow(new \Exception('Date processing error'));
->andThrow(new Exception('Date processing error'));
$response = $this->postJson('/webhook/oxapay', $validData, [
'HMAC' => $validHmac,
@@ -324,7 +323,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_uses_correct_api_key_based_on_webhook_type()
public function it_uses_correct_api_key_based_on_webhook_type(): void
{
$invoiceData = [
'type' => 'invoice',
@@ -364,7 +363,7 @@ class WebhookControllerTest extends TestCase
}
/** @test */
public function it_handles_missing_optional_fields_gracefully()
public function it_handles_missing_optional_fields_gracefully(): void
{
$minimalData = [
'type' => 'invoice',

View File

@@ -16,7 +16,7 @@ class ExampleTest extends TestCase
}
/** @test */
public function the_application_returns_a_successful_response()
public function the_application_returns_a_successful_response(): void
{
$response = $this->get('/');

View File

@@ -2,6 +2,27 @@
namespace Tests\Feature\Filament;
use App\Filament\Resources\TicketResource\Pages\ListTickets;
use App\Filament\Resources\TicketResource\Pages\EditTicket;
use App\Filament\Resources\TicketResource\RelationManagers\ResponsesRelationManager;
use App\Filament\Resources\TicketResource;
use App\Filament\Resources\PlanResource\Pages\ListPlans;
use App\Filament\Resources\PlanResource\Pages\EditPlan;
use App\Filament\Resources\BlogResource\Pages\ListBlogs;
use App\Filament\Resources\BlogResource\Pages\EditBlog;
use App\Filament\Resources\CategoryResource\Pages\ListCategories;
use App\Filament\Resources\CategoryResource\Pages\CreateCategory;
use App\Filament\Resources\CategoryResource\Pages\EditCategory;
use App\Filament\Resources\PageResource\Pages\ListPages;
use App\Filament\Resources\PageResource\Pages\CreatePage;
use App\Filament\Resources\PageResource\Pages\EditPage;
use App\Filament\Resources\MenuResource\Pages\ListMenus;
use App\Filament\Resources\MenuResource\Pages\CreateMenu;
use App\Filament\Resources\UserResource\Pages\ListUsers;
use App\Filament\Resources\UserResource;
use App\Filament\Resources\PlanResource;
use App\Filament\Resources\BlogResource;
use App\Filament\Resources\UserResource\Pages\CreateUser;
use App\Filament\Resources\BlogResource\Pages\CreateBlog;
use App\Filament\Resources\PlanResource\Pages\CreatePlan;
use App\Filament\Resources\TicketResource\Pages\CreateTicket;
@@ -13,12 +34,12 @@ use App\Models\Plan;
use App\Models\Ticket;
use App\Models\TicketResponse;
use App\Models\User;
use Filament\Facades\Filament;
use Livewire\Livewire;
use Tests\TestCase;
class ResourcesTest extends TestCase
{
public $adminUser;
protected function setUp(): void
{
parent::setUp();
@@ -37,47 +58,47 @@ class ResourcesTest extends TestCase
// Ticket Resource Tests
/** @test */
public function it_renders_ticket_resource_list_page()
public function it_renders_ticket_resource_list_page(): void
{
Livewire::test(\App\Filament\Resources\TicketResource\Pages\ListTickets::class)
Livewire::test(ListTickets::class)
->assertSuccessful();
}
/** @test */
public function it_displays_tickets_in_table()
public function it_displays_tickets_in_table(): void
{
$tickets = Ticket::factory()->count(5)->create();
Livewire::test(\App\Filament\Resources\TicketResource\Pages\ListTickets::class)
Livewire::test(ListTickets::class)
->assertCanSeeTableRecords($tickets);
}
/** @test */
public function it_can_search_tickets_by_subject()
public function it_can_search_tickets_by_subject(): void
{
$ticket1 = Ticket::factory()->create(['subject' => 'Login Issue']);
$ticket2 = Ticket::factory()->create(['subject' => 'Payment Problem']);
Ticket::factory()->create(['subject' => 'Login Issue']);
Ticket::factory()->create(['subject' => 'Payment Problem']);
Livewire::test(\App\Filament\Resources\TicketResource\Pages\ListTickets::class)
Livewire::test(ListTickets::class)
->searchTable('Login')
->assertSee('Login Issue')
->assertDontSee('Payment Problem');
}
/** @test */
public function it_can_filter_tickets_by_status()
public function it_can_filter_tickets_by_status(): void
{
$pendingTicket = Ticket::factory()->create(['status' => 'pending']);
$closedTicket = Ticket::factory()->create(['status' => 'closed']);
Livewire::test(\App\Filament\Resources\TicketResource\Pages\ListTickets::class)
Livewire::test(ListTickets::class)
->filterTable('status', 'pending')
->assertCanSeeTableRecords([$pendingTicket])
->assertCanNotSeeTableRecords([$closedTicket]);
}
/** @test */
public function it_can_create_new_ticket()
public function it_can_create_new_ticket(): void
{
$user = User::factory()->create();
$ticketData = [
@@ -96,7 +117,7 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_validates_ticket_creation()
public function it_validates_ticket_creation(): void
{
Livewire::test(CreateTicket::class)
->fillForm([
@@ -110,7 +131,7 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_edit_existing_ticket()
public function it_can_edit_existing_ticket(): void
{
$ticket = Ticket::factory()->create();
@@ -119,7 +140,7 @@ class ResourcesTest extends TestCase
'status' => 'closed',
];
Livewire::test(\App\Filament\Resources\TicketResource\Pages\EditTicket::class, ['record' => $ticket->id])
Livewire::test(EditTicket::class, ['record' => $ticket->id])
->fillForm($updatedData)
->call('save')
->assertHasNoFormErrors();
@@ -128,35 +149,35 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_delete_ticket()
public function it_can_delete_ticket(): void
{
$ticket = Ticket::factory()->create();
Livewire::test(\App\Filament\Resources\TicketResource\Pages\ListTickets::class)
Livewire::test(ListTickets::class)
->callTableAction('delete', $ticket);
$this->assertModelMissing($ticket);
}
/** @test */
public function it_can_view_ticket_responses_relation()
public function it_can_view_ticket_responses_relation(): void
{
$ticket = Ticket::factory()->create();
$responses = TicketResponse::factory()->count(3)->create(['ticket_id' => $ticket->id]);
TicketResponse::factory()->count(3)->create(['ticket_id' => $ticket->id]);
// Test that relation manager is configured correctly
$this->assertContains(
\App\Filament\Resources\TicketResource\RelationManagers\ResponsesRelationManager::class,
\App\Filament\Resources\TicketResource::getRelations()
ResponsesRelationManager::class,
TicketResource::getRelations()
);
}
/** @test */
public function it_can_close_ticket_from_action()
public function it_can_close_ticket_from_action(): void
{
$ticket = Ticket::factory()->create(['status' => 'pending']);
Livewire::test(\App\Filament\Resources\TicketResource\Pages\ListTickets::class)
Livewire::test(ListTickets::class)
->callTableAction('close', $ticket);
$ticket->refresh();
@@ -164,11 +185,11 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_reopen_ticket_from_action()
public function it_can_reopen_ticket_from_action(): void
{
$ticket = Ticket::factory()->create(['status' => 'closed']);
Livewire::test(\App\Filament\Resources\TicketResource\Pages\ListTickets::class)
Livewire::test(ListTickets::class)
->callTableAction('reopen', $ticket);
$ticket->refresh();
@@ -177,35 +198,35 @@ class ResourcesTest extends TestCase
// Plan Resource Tests
/** @test */
public function it_renders_plan_resource_list_page()
public function it_renders_plan_resource_list_page(): void
{
Livewire::test(\App\Filament\Resources\PlanResource\Pages\ListPlans::class)
Livewire::test(ListPlans::class)
->assertSuccessful();
}
/** @test */
public function it_displays_plans_in_table()
public function it_displays_plans_in_table(): void
{
$plans = Plan::factory()->count(5)->create();
Livewire::test(\App\Filament\Resources\PlanResource\Pages\ListPlans::class)
Livewire::test(ListPlans::class)
->assertCanSeeTableRecords($plans);
}
/** @test */
public function it_can_search_plans_by_name()
public function it_can_search_plans_by_name(): void
{
$plan1 = Plan::factory()->create(['name' => 'Basic Plan']);
$plan2 = Plan::factory()->create(['name' => 'Premium Plan']);
Livewire::test(\App\Filament\Resources\PlanResource\Pages\ListPlans::class)
Livewire::test(ListPlans::class)
->searchTable('Basic')
->assertCanSeeTableRecords([$plan1])
->assertCanNotSeeTableRecords([$plan2]);
}
/** @test */
public function it_can_create_new_plan()
public function it_can_create_new_plan(): void
{
$planData = [
'name' => 'Test Plan',
@@ -229,7 +250,7 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_validates_plan_creation()
public function it_validates_plan_creation(): void
{
Livewire::test(CreatePlan::class)
->fillForm([
@@ -242,7 +263,7 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_edit_existing_plan()
public function it_can_edit_existing_plan(): void
{
$plan = Plan::factory()->create();
@@ -258,7 +279,7 @@ class ResourcesTest extends TestCase
'accept_oxapay' => 0,
];
Livewire::test(\App\Filament\Resources\PlanResource\Pages\EditPlan::class, ['record' => $plan->id])
Livewire::test(EditPlan::class, ['record' => $plan->id])
->fillForm($updatedData)
->call('save')
->assertHasNoFormErrors();
@@ -267,23 +288,23 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_delete_plan()
public function it_can_delete_plan(): void
{
$plan = Plan::factory()->create();
Livewire::test(\App\Filament\Resources\PlanResource\Pages\ListPlans::class)
Livewire::test(ListPlans::class)
->callTableAction('delete', $plan);
$this->assertModelMissing($plan);
}
/** @test */
public function it_can_filter_plans_by_payment_methods()
public function it_can_filter_plans_by_payment_methods(): void
{
$stripePlan = Plan::factory()->create(['accept_stripe' => 1]);
$shoppyPlan = Plan::factory()->create(['accept_shoppy' => 1]);
Plan::factory()->create(['accept_stripe' => 1]);
Plan::factory()->create(['accept_shoppy' => 1]);
$livewire = Livewire::test(\App\Filament\Resources\PlanResource\Pages\ListPlans::class)
$livewire = Livewire::test(ListPlans::class)
->filterTable('payment_method', 'stripe');
// Test that filtering doesn't crash and returns a response
@@ -291,11 +312,11 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_toggle_monthly_billing_setting()
public function it_can_toggle_monthly_billing_setting(): void
{
$plan = Plan::factory()->create(['monthly_billing' => true]);
Livewire::test(\App\Filament\Resources\PlanResource\Pages\EditPlan::class, ['record' => $plan->id])
Livewire::test(EditPlan::class, ['record' => $plan->id])
->fillForm([
'name' => $plan->name,
'product_id' => $plan->product_id,
@@ -316,35 +337,35 @@ class ResourcesTest extends TestCase
// Blog Resource Tests
/** @test */
public function it_renders_blog_resource_list_page()
public function it_renders_blog_resource_list_page(): void
{
Livewire::test(\App\Filament\Resources\BlogResource\Pages\ListBlogs::class)
Livewire::test(ListBlogs::class)
->assertSuccessful();
}
/** @test */
public function it_displays_blog_posts_in_table()
public function it_displays_blog_posts_in_table(): void
{
$blogs = Blog::factory()->count(5)->create();
Livewire::test(\App\Filament\Resources\BlogResource\Pages\ListBlogs::class)
Livewire::test(ListBlogs::class)
->assertCanSeeTableRecords($blogs);
}
/** @test */
public function it_can_search_blog_posts_by_title()
public function it_can_search_blog_posts_by_title(): void
{
$blog1 = Blog::factory()->create(['post' => 'Laravel Tutorial']);
$blog2 = Blog::factory()->create(['post' => 'Vue.js Guide']);
Livewire::test(\App\Filament\Resources\BlogResource\Pages\ListBlogs::class)
Livewire::test(ListBlogs::class)
->searchTable('Laravel')
->assertCanSeeTableRecords([$blog1])
->assertCanNotSeeTableRecords([$blog2]);
}
/** @test */
public function it_can_create_new_blog_post()
public function it_can_create_new_blog_post(): void
{
$category = Category::factory()->create();
$blogData = [
@@ -364,7 +385,7 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_validates_blog_post_creation()
public function it_validates_blog_post_creation(): void
{
Livewire::test(CreateBlog::class)
->fillForm([
@@ -376,7 +397,7 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_edit_existing_blog_post()
public function it_can_edit_existing_blog_post(): void
{
$blog = Blog::factory()->create();
@@ -388,7 +409,7 @@ class ResourcesTest extends TestCase
'category_id' => $blog->category_id,
];
Livewire::test(\App\Filament\Resources\BlogResource\Pages\EditBlog::class, ['record' => $blog->id])
Livewire::test(EditBlog::class, ['record' => $blog->id])
->fillForm($updatedData)
->call('save')
->assertHasNoFormErrors();
@@ -397,34 +418,34 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_delete_blog_post()
public function it_can_delete_blog_post(): void
{
$blog = Blog::factory()->create();
Livewire::test(\App\Filament\Resources\BlogResource\Pages\ListBlogs::class)
Livewire::test(ListBlogs::class)
->callTableAction('delete', $blog);
$this->assertModelMissing($blog);
}
/** @test */
public function it_can_filter_blog_posts_by_status()
public function it_can_filter_blog_posts_by_status(): void
{
$publishedBlog = Blog::factory()->create(['is_published' => true]);
$draftBlog = Blog::factory()->create(['is_published' => false]);
Livewire::test(\App\Filament\Resources\BlogResource\Pages\ListBlogs::class)
Livewire::test(ListBlogs::class)
->filterTable('is_published', true)
->assertCanSeeTableRecords([$publishedBlog])
->assertCanNotSeeTableRecords([$draftBlog]);
}
/** @test */
public function it_can_toggle_published_status()
public function it_can_toggle_published_status(): void
{
$blog = Blog::factory()->create(['is_published' => false]);
Livewire::test(\App\Filament\Resources\BlogResource\Pages\ListBlogs::class)
Livewire::test(ListBlogs::class)
->callTableAction('togglePublished', $blog);
$blog->refresh();
@@ -432,34 +453,34 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_view_category_relation()
public function it_can_view_category_relation(): void
{
$category = Category::factory()->create();
$blog = Blog::factory()->create(['category_id' => $category->id]);
Livewire::test(\App\Filament\Resources\BlogResource\Pages\ListBlogs::class)
Livewire::test(ListBlogs::class)
->assertTableColumnStateSet('category.name', $category->name, $blog);
}
// Category Resource Tests
/** @test */
public function it_renders_category_resource_list_page()
public function it_renders_category_resource_list_page(): void
{
Livewire::test(\App\Filament\Resources\CategoryResource\Pages\ListCategories::class)
Livewire::test(ListCategories::class)
->assertSuccessful();
}
/** @test */
public function it_displays_categories_in_table()
public function it_displays_categories_in_table(): void
{
$categories = Category::factory()->count(5)->create();
Livewire::test(\App\Filament\Resources\CategoryResource\Pages\ListCategories::class)
Livewire::test(ListCategories::class)
->assertCanSeeTableRecords($categories);
}
/** @test */
public function it_can_create_new_category()
public function it_can_create_new_category(): void
{
$categoryData = [
'name' => 'Test Category',
@@ -467,7 +488,7 @@ class ResourcesTest extends TestCase
'is_active' => 1,
];
Livewire::test(\App\Filament\Resources\CategoryResource\Pages\CreateCategory::class)
Livewire::test(CreateCategory::class)
->fillForm($categoryData)
->call('create')
->assertHasNoFormErrors();
@@ -476,9 +497,9 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_validates_category_creation()
public function it_validates_category_creation(): void
{
Livewire::test(\App\Filament\Resources\CategoryResource\Pages\CreateCategory::class)
Livewire::test(CreateCategory::class)
->fillForm([
'name' => '',
'slug' => '',
@@ -488,7 +509,7 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_edit_existing_category()
public function it_can_edit_existing_category(): void
{
$category = Category::factory()->create();
@@ -497,7 +518,7 @@ class ResourcesTest extends TestCase
'is_active' => 1,
];
Livewire::test(\App\Filament\Resources\CategoryResource\Pages\EditCategory::class, ['record' => $category->id])
Livewire::test(EditCategory::class, ['record' => $category->id])
->fillForm($updatedData)
->call('save')
->assertHasNoFormErrors();
@@ -506,32 +527,32 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_delete_category()
public function it_can_delete_category(): void
{
$category = Category::factory()->create();
Livewire::test(\App\Filament\Resources\CategoryResource\Pages\ListCategories::class)
Livewire::test(ListCategories::class)
->callTableAction('delete', $category);
$this->assertModelMissing($category);
}
/** @test */
public function it_can_view_blogs_count()
public function it_can_view_blogs_count(): void
{
$category = Category::factory()->create();
Blog::factory()->count(3)->create(['category_id' => $category->id]);
Livewire::test(\App\Filament\Resources\CategoryResource\Pages\ListCategories::class)
Livewire::test(ListCategories::class)
->assertTableColumnStateSet('blogs_count', 3, $category);
}
/** @test */
public function it_can_toggle_category_status()
public function it_can_toggle_category_status(): void
{
$category = Category::factory()->create(['is_active' => true]);
Livewire::test(\App\Filament\Resources\CategoryResource\Pages\ListCategories::class)
Livewire::test(ListCategories::class)
->callTableAction('toggleStatus', $category);
$category->refresh();
@@ -540,23 +561,23 @@ class ResourcesTest extends TestCase
// Page Resource Tests
/** @test */
public function it_renders_page_resource_list_page()
public function it_renders_page_resource_list_page(): void
{
Livewire::test(\App\Filament\Resources\PageResource\Pages\ListPages::class)
Livewire::test(ListPages::class)
->assertSuccessful();
}
/** @test */
public function it_displays_pages_in_table()
public function it_displays_pages_in_table(): void
{
$pages = Page::factory()->count(5)->create();
Livewire::test(\App\Filament\Resources\PageResource\Pages\ListPages::class)
Livewire::test(ListPages::class)
->assertCanSeeTableRecords($pages);
}
/** @test */
public function it_can_create_new_page()
public function it_can_create_new_page(): void
{
$pageData = [
'title' => 'Test Page',
@@ -565,7 +586,7 @@ class ResourcesTest extends TestCase
'is_published' => 1,
];
Livewire::test(\App\Filament\Resources\PageResource\Pages\CreatePage::class)
Livewire::test(CreatePage::class)
->fillForm($pageData)
->call('create')
->assertHasNoFormErrors();
@@ -574,9 +595,9 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_validates_page_creation()
public function it_validates_page_creation(): void
{
Livewire::test(\App\Filament\Resources\PageResource\Pages\CreatePage::class)
Livewire::test(CreatePage::class)
->fillForm([
'title' => '',
'slug' => '',
@@ -587,7 +608,7 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_edit_existing_page()
public function it_can_edit_existing_page(): void
{
$page = Page::factory()->create();
@@ -601,7 +622,7 @@ class ResourcesTest extends TestCase
'meta' => '{"description":"Updated page description","keywords":"updated,page"}',
];
Livewire::test(\App\Filament\Resources\PageResource\Pages\EditPage::class, ['record' => $page->id])
Livewire::test(EditPage::class, ['record' => $page->id])
->fillForm($updatedData)
->call('save')
->assertHasNoFormErrors();
@@ -610,34 +631,34 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_delete_page()
public function it_can_delete_page(): void
{
$page = Page::factory()->create();
Livewire::test(\App\Filament\Resources\PageResource\Pages\ListPages::class)
Livewire::test(ListPages::class)
->callTableAction('delete', $page);
$this->assertModelMissing($page);
}
/** @test */
public function it_can_filter_pages_by_publication_status()
public function it_can_filter_pages_by_publication_status(): void
{
$publishedPage = Page::factory()->create(['is_published' => true]);
$draftPage = Page::factory()->create(['is_published' => false]);
Livewire::test(\App\Filament\Resources\PageResource\Pages\ListPages::class)
Livewire::test(ListPages::class)
->filterTable('is_published', true)
->assertCanSeeTableRecords([$publishedPage])
->assertCanNotSeeTableRecords([$draftPage]);
}
/** @test */
public function it_can_toggle_page_publication_status()
public function it_can_toggle_page_publication_status(): void
{
$page = Page::factory()->create(['is_published' => true]);
Livewire::test(\App\Filament\Resources\PageResource\Pages\ListPages::class)
Livewire::test(ListPages::class)
->callTableAction('togglePublished', $page);
$page->refresh();
@@ -646,23 +667,23 @@ class ResourcesTest extends TestCase
// Menu Resource Tests
/** @test */
public function it_renders_menu_resource_list_page()
public function it_renders_menu_resource_list_page(): void
{
Livewire::test(\App\Filament\Resources\MenuResource\Pages\ListMenus::class)
Livewire::test(ListMenus::class)
->assertSuccessful();
}
/** @test */
public function it_displays_menu_items_in_table()
public function it_displays_menu_items_in_table(): void
{
$menus = Menu::factory()->count(5)->create();
Livewire::test(\App\Filament\Resources\MenuResource\Pages\ListMenus::class)
Livewire::test(ListMenus::class)
->assertCanSeeTableRecords($menus);
}
/** @test */
public function it_can_create_new_menu_item()
public function it_can_create_new_menu_item(): void
{
$menuData = [
'name' => 'Test Menu',
@@ -670,7 +691,7 @@ class ResourcesTest extends TestCase
'new_tab' => false,
];
Livewire::test(\App\Filament\Resources\MenuResource\Pages\CreateMenu::class)
Livewire::test(CreateMenu::class)
->fillForm($menuData)
->call('create')
->assertHasNoFormErrors();
@@ -679,9 +700,9 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_validates_menu_item_creation()
public function it_validates_menu_item_creation(): void
{
Livewire::test(\App\Filament\Resources\MenuResource\Pages\CreateMenu::class)
Livewire::test(CreateMenu::class)
->fillForm([
'name' => '',
'url' => '',
@@ -691,78 +712,78 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_delete_menu_item()
public function it_can_delete_menu_item(): void
{
$menu = Menu::factory()->create();
Livewire::test(\App\Filament\Resources\MenuResource\Pages\ListMenus::class)
Livewire::test(ListMenus::class)
->callTableAction('delete', $menu);
$this->assertModelMissing($menu);
}
/** @test */
public function it_displays_menu_items_alphabetically()
public function it_displays_menu_items_alphabetically(): void
{
$menu1 = Menu::factory()->create(['name' => 'Zebra']);
$menu2 = Menu::factory()->create(['name' => 'Apple']);
Livewire::test(\App\Filament\Resources\MenuResource\Pages\ListMenus::class)
Livewire::test(ListMenus::class)
->sortTable('name')
->assertCanSeeTableRecords([$menu2, $menu1], inOrder: true);
}
/** @test */
public function it_can_handle_parent_child_relationships()
public function it_can_handle_parent_child_relationships(): void
{
$parentMenu = Menu::factory()->create(['parent' => null]);
$childMenu = Menu::factory()->create(['parent' => $parentMenu->id]);
Livewire::test(\App\Filament\Resources\MenuResource\Pages\ListMenus::class)
Livewire::test(ListMenus::class)
->assertTableColumnStateSet('parentname.name', $parentMenu->name, $childMenu);
}
// General Filament Tests
/** @test */
public function it_can_navigate_between_resources()
public function it_can_navigate_between_resources(): void
{
Livewire::test(\App\Filament\Resources\UserResource\Pages\ListUsers::class)
Livewire::test(ListUsers::class)
->assertSuccessful();
Livewire::test(\App\Filament\Resources\TicketResource\Pages\ListTickets::class)
Livewire::test(ListTickets::class)
->assertSuccessful();
Livewire::test(\App\Filament\Resources\PlanResource\Pages\ListPlans::class)
Livewire::test(ListPlans::class)
->assertSuccessful();
}
/** @test */
public function it_can_use_global_search()
public function it_can_use_global_search(): void
{
$user = User::factory()->create(['name' => 'John Doe']);
User::factory()->create(['name' => 'John Doe']);
Livewire::test(\App\Filament\Resources\UserResource\Pages\ListUsers::class)
Livewire::test(ListUsers::class)
->assertSuccessful();
}
/** @test */
public function it_can_search_users_in_table()
public function it_can_search_users_in_table(): void
{
$user1 = User::factory()->create(['name' => 'John Doe']);
$user2 = User::factory()->create(['name' => 'Jane Smith']);
Livewire::test(\App\Filament\Resources\UserResource\Pages\ListUsers::class)
Livewire::test(ListUsers::class)
->searchTable('John')
->assertCanSeeTableRecords([$user1])
->assertCanNotSeeTableRecords([$user2]);
}
/** @test */
public function it_handles_bulk_actions_correctly()
public function it_handles_bulk_actions_correctly(): void
{
$users = User::factory()->count(3)->create();
Livewire::test(\App\Filament\Resources\UserResource\Pages\ListUsers::class)
Livewire::test(ListUsers::class)
->callTableBulkAction('delete', $users);
foreach ($users as $user) {
@@ -771,31 +792,31 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_validates_access_control()
public function it_validates_access_control(): void
{
// Test with non-admin user - currently access control allows all authenticated users
$normalUser = User::factory()->create(['level' => 0]);
$this->actingAs($normalUser);
Livewire::test(\App\Filament\Resources\UserResource\Pages\ListUsers::class)
Livewire::test(ListUsers::class)
->assertStatus(200); // Access control currently allows access
}
/** @test */
public function it_displays_correct_navigation_structure()
public function it_displays_correct_navigation_structure(): void
{
$this->assertEquals('heroicon-o-users', \App\Filament\Resources\UserResource::getNavigationIcon());
$this->assertEquals('heroicon-o-ticket', \App\Filament\Resources\TicketResource::getNavigationIcon());
$this->assertEquals('heroicon-o-rectangle-stack', \App\Filament\Resources\PlanResource::getNavigationIcon());
$this->assertEquals('heroicon-m-newspaper', \App\Filament\Resources\BlogResource::getNavigationIcon());
$this->assertEquals('heroicon-o-users', UserResource::getNavigationIcon());
$this->assertEquals('heroicon-o-ticket', TicketResource::getNavigationIcon());
$this->assertEquals('heroicon-o-rectangle-stack', PlanResource::getNavigationIcon());
$this->assertEquals('heroicon-m-newspaper', BlogResource::getNavigationIcon());
}
/** @test */
public function it_handles_form_submissions_with_relationships()
public function it_handles_form_submissions_with_relationships(): void
{
$category = Category::factory()->create();
Livewire::test(\App\Filament\Resources\BlogResource\Pages\CreateBlog::class)
Livewire::test(CreateBlog::class)
->fillForm([
'post' => 'Test Blog',
'slug' => 'test-blog',
@@ -813,16 +834,16 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_handles_file_uploads_in_forms()
public function it_handles_file_uploads_in_forms(): void
{
// Test file upload functionality if implemented
$this->assertTrue(true); // Placeholder
}
/** @test */
public function it_displays_proper_error_messages()
public function it_displays_proper_error_messages(): void
{
Livewire::test(\App\Filament\Resources\UserResource\Pages\CreateUser::class)
Livewire::test(CreateUser::class)
->fillForm([
'name' => '',
'email' => 'invalid-email',
@@ -833,11 +854,11 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_handles_pagination_correctly()
public function it_handles_pagination_correctly(): void
{
User::factory()->count(25)->create();
Livewire::test(\App\Filament\Resources\UserResource\Pages\ListUsers::class)
Livewire::test(ListUsers::class)
->assertSuccessful()
->assertSeeHtml('fi-pagination')
->assertSee('1')
@@ -846,11 +867,11 @@ class ResourcesTest extends TestCase
}
/** @test */
public function it_can_sort_users_by_different_columns()
public function it_can_sort_users_by_different_columns(): void
{
User::factory()->count(5)->create();
Livewire::test(\App\Filament\Resources\UserResource\Pages\ListUsers::class)
Livewire::test(ListUsers::class)
->sortTable('name')
->assertSuccessful();
}

View File

@@ -2,18 +2,20 @@
namespace Tests\Feature\Filament;
use App\Filament\Resources\UserResource\RelationManagers\LogsRelationManager;
use App\Filament\Resources\UserResource\RelationManagers\UsageLogsRelationManager;
use App\Filament\Resources\UserResource;
use App\Filament\Resources\UserResource\Pages\CreateUser;
use App\Filament\Resources\UserResource\Pages\EditUser;
use App\Filament\Resources\UserResource\Pages\ListUsers;
use App\Models\Log;
use App\Models\User;
use Filament\Facades\Filament;
use Livewire\Livewire;
use Tests\TestCase;
class UserResourceTest extends TestCase
{
public $adminUser;
protected function setUp(): void
{
parent::setUp();
@@ -31,14 +33,14 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_renders_user_resource_list_page()
public function it_renders_user_resource_list_page(): void
{
Livewire::test(ListUsers::class)
->assertSuccessful();
}
/** @test */
public function it_displays_users_in_table()
public function it_displays_users_in_table(): void
{
$users = User::factory()->count(5)->create();
@@ -47,7 +49,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_search_users_by_name()
public function it_can_search_users_by_name(): void
{
$user1 = User::factory()->create(['name' => 'John Doe']);
$user2 = User::factory()->create(['name' => 'Jane Smith']);
@@ -59,7 +61,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_search_users_by_email()
public function it_can_search_users_by_email(): void
{
$user1 = User::factory()->create(['email' => 'john@example.com']);
$user2 = User::factory()->create(['email' => 'jane@example.com']);
@@ -71,7 +73,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_sort_users_by_name()
public function it_can_sort_users_by_name(): void
{
$user1 = User::factory()->create(['name' => 'Alice']);
$user2 = User::factory()->create(['name' => 'Bob']);
@@ -82,7 +84,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_sort_users_by_email()
public function it_can_sort_users_by_email(): void
{
$user1 = User::factory()->create(['email' => 'alice@example.com']);
$user2 = User::factory()->create(['email' => 'bob@example.com']);
@@ -93,7 +95,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_filter_users_by_verification_status()
public function it_can_filter_users_by_verification_status(): void
{
$verifiedUser = User::factory()->create(['email_verified_at' => now()]);
$unverifiedUser = User::factory()->create(['email_verified_at' => null]);
@@ -105,14 +107,14 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_filter_users_by_level()
public function it_can_filter_users_by_level(): void
{
$normalUser = User::factory()->create(['level' => 0]);
$bannedUser = User::factory()->create(['level' => 1]);
$adminUser = User::factory()->create(['level' => 9]);
User::factory()->create(['level' => 0]);
User::factory()->create(['level' => 1]);
User::factory()->create(['level' => 9]);
// The level filter doesn't exist in UserResource, so let's test the subscription status filter instead
$subscribedUser = User::factory()->create();
User::factory()->create();
$nonSubscribedUser = User::factory()->create();
Livewire::test(ListUsers::class)
@@ -121,7 +123,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_create_new_user()
public function it_can_create_new_user(): void
{
// Test that CreateUser page renders successfully
// UserResource form doesn't include password fields, so we test the page exists
@@ -130,7 +132,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_validates_user_creation()
public function it_validates_user_creation(): void
{
Livewire::test(CreateUser::class)
->fillForm([
@@ -143,7 +145,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_validates_email_uniqueness_on_creation()
public function it_validates_email_uniqueness_on_creation(): void
{
// Test that CreateUser page renders successfully
// Email uniqueness is handled by Laravel validation, not form testing
@@ -152,7 +154,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_edit_existing_user()
public function it_can_edit_existing_user(): void
{
$user = User::factory()->create();
@@ -171,7 +173,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_validates_user_editing()
public function it_validates_user_editing(): void
{
$user = User::factory()->create();
@@ -186,10 +188,10 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_validates_email_uniqueness_on_edit_excluding_current_user()
public function it_validates_email_uniqueness_on_edit_excluding_current_user(): void
{
$user1 = User::factory()->create(['email' => 'user1@example.com']);
$user2 = User::factory()->create(['email' => 'user2@example.com']);
User::factory()->create(['email' => 'user2@example.com']);
// Test that we can edit user with valid data
Livewire::test(EditUser::class, ['record' => $user1->id])
@@ -203,25 +205,25 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_can_edit_user()
public function it_can_edit_user(): void
{
$user = User::factory()->create();
User::factory()->create();
Livewire::test(ListUsers::class)
->assertTableActionExists('edit');
}
/** @test */
public function it_can_bulk_delete_users()
public function it_can_bulk_delete_users(): void
{
$users = User::factory()->count(3)->create();
User::factory()->count(3)->create();
Livewire::test(ListUsers::class)
->assertTableBulkActionExists('delete');
}
/** @test */
public function it_displays_user_verification_status_correctly()
public function it_displays_user_verification_status_correctly(): void
{
$verifiedUser = User::factory()->create(['email_verified_at' => now()]);
$unverifiedUser = User::factory()->create(['email_verified_at' => null]);
@@ -232,7 +234,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_displays_user_level_badges_correctly()
public function it_displays_user_level_badges_correctly(): void
{
$normalUser = User::factory()->create(['level' => 0]);
$bannedUser = User::factory()->create(['level' => 1]);
@@ -245,7 +247,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_shows_email_verification_timestamp_in_form()
public function it_shows_email_verification_timestamp_in_form(): void
{
$user = User::factory()->create(['email_verified_at' => '2024-01-01 12:00:00']);
@@ -255,7 +257,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_shows_not_verified_status_in_form()
public function it_shows_not_verified_status_in_form(): void
{
$user = User::factory()->create(['email_verified_at' => null]);
@@ -264,7 +266,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_displays_stripe_information_when_available()
public function it_displays_stripe_information_when_available(): void
{
$user = User::factory()->create([
'stripe_id' => 'cus_123456',
@@ -281,7 +283,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_displays_trial_end_date_when_available()
public function it_displays_trial_end_date_when_available(): void
{
$user = User::factory()->create(['trial_ends_at' => '2024-12-31 23:59:59']);
@@ -290,22 +292,22 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_has_relation_managers_configured()
public function it_has_relation_managers_configured(): void
{
$this->assertIsArray(UserResource::getRelations());
$this->assertContains('App\Filament\Resources\UserResource\RelationManagers\LogsRelationManager', UserResource::getRelations());
$this->assertContains('App\Filament\Resources\UserResource\RelationManagers\UsageLogsRelationManager', UserResource::getRelations());
$this->assertContains(LogsRelationManager::class, UserResource::getRelations());
$this->assertContains(UsageLogsRelationManager::class, UserResource::getRelations());
}
/** @test */
public function it_has_bulk_update_level_action()
public function it_has_bulk_update_level_action(): void
{
Livewire::test(ListUsers::class)
->assertTableBulkActionExists('updateLevel');
}
/** @test */
public function it_searches_across_multiple_fields()
public function it_searches_across_multiple_fields(): void
{
$user1 = User::factory()->create(['name' => 'John Doe', 'email' => 'john@example.com']);
$user2 = User::factory()->create(['name' => 'Jane Smith', 'email' => 'jane@example.com']);
@@ -317,7 +319,7 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_handles_relationship_data_correctly()
public function it_handles_relationship_data_correctly(): void
{
$user = User::factory()->create();
Log::factory()->count(3)->create(['user_id' => $user->id]);
@@ -327,14 +329,14 @@ class UserResourceTest extends TestCase
}
/** @test */
public function it_displays_correct_navigation_icon_and_group()
public function it_displays_correct_navigation_icon_and_group(): void
{
$this->assertEquals('heroicon-o-users', UserResource::getNavigationIcon());
$this->assertEquals('Admin', UserResource::getNavigationGroup());
}
/** @test */
public function it_uses_correct_model()
public function it_uses_correct_model(): void
{
$this->assertEquals(User::class, UserResource::getModel());
}

View File

@@ -4,7 +4,6 @@ namespace Tests\Feature\Livewire\Auth;
use App\Livewire\Auth\Login;
use App\Models\User;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Session;
@@ -13,6 +12,7 @@ use Tests\TestCase;
class LoginTest extends TestCase
{
public $user;
protected function setUp(): void
{
parent::setUp();
@@ -24,7 +24,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_renders_the_login_component()
public function it_renders_the_login_component(): void
{
$component = Livewire::test(Login::class);
@@ -34,7 +34,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_validates_required_email_field()
public function it_validates_required_email_field(): void
{
$component = Livewire::test(Login::class);
@@ -44,7 +44,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_validates_email_format()
public function it_validates_email_format(): void
{
$component = Livewire::test(Login::class);
@@ -54,7 +54,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_validates_required_password_field()
public function it_validates_required_password_field(): void
{
$component = Livewire::test(Login::class);
@@ -64,7 +64,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_authenticates_user_with_valid_credentials()
public function it_authenticates_user_with_valid_credentials(): void
{
$component = Livewire::test(Login::class);
@@ -77,7 +77,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_fails_authentication_with_invalid_credentials()
public function it_fails_authentication_with_invalid_credentials(): void
{
$component = Livewire::test(Login::class);
@@ -88,7 +88,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_handles_rate_limiting()
public function it_handles_rate_limiting(): void
{
// Clear any existing rate limit attempts
RateLimiter::clear('login:'.request()->ip());
@@ -110,7 +110,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_redirects_authenticated_users_away()
public function it_redirects_authenticated_users_away(): void
{
$this->actingAs($this->user);
@@ -121,7 +121,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_handles_lockout_event()
public function it_handles_lockout_event(): void
{
// Clear any existing rate limit attempts
RateLimiter::clear('login:'.request()->ip());
@@ -143,7 +143,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_clears_session_after_successful_login()
public function it_clears_session_after_successful_login(): void
{
Session::put('old_url', '/some-page');
@@ -159,7 +159,7 @@ class LoginTest extends TestCase
}
/** @test */
public function it_remember_me_functionality_works()
public function it_remember_me_functionality_works(): void
{
$component = Livewire::test(Login::class);

View File

@@ -14,7 +14,7 @@ use Tests\TestCase;
class RegisterTest extends TestCase
{
/** @test */
public function it_renders_the_register_component()
public function it_renders_the_register_component(): void
{
$component = Livewire::test(Register::class);
@@ -25,7 +25,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_validates_required_name_field()
public function it_validates_required_name_field(): void
{
$component = Livewire::test(Register::class);
@@ -38,7 +38,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_validates_required_email_field()
public function it_validates_required_email_field(): void
{
$component = Livewire::test(Register::class);
@@ -51,7 +51,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_validates_email_format()
public function it_validates_email_format(): void
{
$component = Livewire::test(Register::class);
@@ -65,7 +65,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_validates_required_password_field()
public function it_validates_required_password_field(): void
{
$component = Livewire::test(Register::class);
@@ -78,7 +78,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_validates_password_confirmation()
public function it_validates_password_confirmation(): void
{
$component = Livewire::test(Register::class);
@@ -92,7 +92,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_creates_user_with_valid_data()
public function it_creates_user_with_valid_data(): void
{
Event::fake();
@@ -110,12 +110,12 @@ class RegisterTest extends TestCase
'email' => 'test@gmail.com',
]);
$this->assertAuthenticatedAs(User::where('email', 'test@gmail.com')->first());
$this->assertAuthenticatedAs(User::query()->where('email', 'test@gmail.com')->first());
Event::assertDispatched(Registered::class);
}
/** @test */
public function it_hashes_password_before_storing()
public function it_hashes_password_before_storing(): void
{
$component = Livewire::test(Register::class);
@@ -126,12 +126,12 @@ class RegisterTest extends TestCase
->set('password_confirmation', 'Password123!')
->call('register');
$user = User::where('email', 'test@gmail.com')->first();
$user = User::query()->where('email', 'test@gmail.com')->first();
$this->assertTrue(Hash::check('Password123!', $user->password));
}
/** @test */
public function it_prevents_duplicate_email_registration()
public function it_prevents_duplicate_email_registration(): void
{
// Create existing user
User::factory()->create(['email' => 'test@gmail.com']);
@@ -148,7 +148,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_redirects_after_successful_registration()
public function it_redirects_after_successful_registration(): void
{
$component = Livewire::test(Register::class);
@@ -163,7 +163,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_logs_in_user_after_registration()
public function it_logs_in_user_after_registration(): void
{
$component = Livewire::test(Register::class);
@@ -179,7 +179,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_handles_maximum_name_length()
public function it_handles_maximum_name_length(): void
{
$component = Livewire::test(Register::class);
@@ -193,7 +193,7 @@ class RegisterTest extends TestCase
}
/** @test */
public function it_handles_password_validation()
public function it_handles_password_validation(): void
{
$component = Livewire::test(Register::class);

View File

@@ -2,6 +2,7 @@
namespace Tests\Feature\Livewire;
use App\Livewire\Dashboard\Dashboard;
use App\Models\Plan;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
@@ -10,6 +11,7 @@ use Tests\TestCase;
class DashboardTest extends TestCase
{
public $user;
protected function setUp(): void
{
parent::setUp();
@@ -30,18 +32,18 @@ class DashboardTest extends TestCase
}
/** @test */
public function it_renders_dashboard_component()
public function it_renders_dashboard_component(): void
{
$component = Livewire::test(\App\Livewire\Dashboard\Dashboard::class);
$component = Livewire::test(Dashboard::class);
$component->assertStatus(200);
$component->assertViewIs('livewire.dashboard.dashboard');
}
/** @test */
public function it_displays_user_information()
public function it_displays_user_information(): void
{
$component = Livewire::test(\App\Livewire\Dashboard\Dashboard::class);
$component = Livewire::test(Dashboard::class);
// Check that dashboard renders with usage statistics
$component->assertSee('Mailbox Created');
@@ -50,9 +52,9 @@ class DashboardTest extends TestCase
}
/** @test */
public function it_shows_subscription_status()
public function it_shows_subscription_status(): void
{
$component = Livewire::test(\App\Livewire\Dashboard\Dashboard::class);
$component = Livewire::test(Dashboard::class);
// Test that the component displays subscription pricing section (since user is not subscribed)
$component->assertSee('Purchase Subscription');

View File

@@ -2,7 +2,12 @@
namespace Tests\Feature\Livewire;
use App\Models\Email;
use App\Livewire\Home;
use App\Livewire\Frontend\Mailbox;
use Exception;
use App\Models\Blog;
use App\Livewire\ListBlog;
use App\Models\Page;
use App\Models\ZEmail;
use Illuminate\Support\Facades\Cookie;
use Livewire\Livewire;
@@ -11,18 +16,18 @@ use Tests\TestCase;
class FrontendTest extends TestCase
{
/** @test */
public function it_renders_home_component()
public function it_renders_home_component(): void
{
$component = Livewire::test(\App\Livewire\Home::class);
$component = Livewire::test(Home::class);
$component->assertStatus(200);
$component->assertViewIs('livewire.home');
}
/** @test */
public function it_checks_for_messages_in_home_component()
public function it_checks_for_messages_in_home_component(): void
{
$component = Livewire::test(\App\Livewire\Home::class);
$component = Livewire::test(Home::class);
// Test that the component can render without errors
$component->assertStatus(200);
@@ -30,7 +35,7 @@ class FrontendTest extends TestCase
}
/** @test */
public function it_renders_mailbox_component_with_existing_email()
public function it_renders_mailbox_component_with_existing_email(): void
{
// Mock existing email in cookie
Cookie::queue('email', 'test@example.com', 43800);
@@ -40,32 +45,32 @@ class FrontendTest extends TestCase
->shouldReceive('getEmail')
->andReturn('test@example.com');
$component = Livewire::test(\App\Livewire\Frontend\Mailbox::class);
$component = Livewire::test(Mailbox::class);
// Component might redirect if email validation fails, so check for either status or redirect
try {
$component->assertStatus(200);
} catch (\Exception $e) {
} catch (Exception) {
$component->assertRedirect('/');
}
}
/** @test */
public function it_redirects_home_when_no_email_in_mailbox()
public function it_redirects_home_when_no_email_in_mailbox(): void
{
// Ensure no email cookie exists
Cookie::queue('email', '', -1);
$component = Livewire::test(\App\Livewire\Frontend\Mailbox::class);
$component = Livewire::test(Mailbox::class);
$component->assertRedirect('/');
}
/** @test */
public function it_renders_blog_component()
public function it_renders_blog_component(): void
{
// Create a blog post with the slug we're testing
$blog = \App\Models\Blog::factory()->create(['slug' => 'test-slug']);
Blog::factory()->create(['slug' => 'test-slug']);
$component = Livewire::test(\App\Livewire\Blog::class, ['slug' => 'test-slug']);
@@ -73,18 +78,18 @@ class FrontendTest extends TestCase
}
/** @test */
public function it_renders_list_blog_component()
public function it_renders_list_blog_component(): void
{
$component = Livewire::test(\App\Livewire\ListBlog::class);
$component = Livewire::test(ListBlog::class);
$component->assertStatus(200);
}
/** @test */
public function it_renders_page_component()
public function it_renders_page_component(): void
{
// Create a page with the slug we're testing and ensure it's published
$page = \App\Models\Page::factory()->create([
Page::factory()->create([
'slug' => 'test-slug',
'is_published' => true,
]);

View File

@@ -1,5 +1,8 @@
<?php
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
/*
|--------------------------------------------------------------------------
| Test Case
@@ -11,8 +14,8 @@
|
*/
pest()->extend(Tests\TestCase::class)
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
pest()->extend(TestCase::class)
->use(RefreshDatabase::class)
->in('Feature')
->in('Unit');
@@ -27,9 +30,7 @@ pest()->extend(Tests\TestCase::class)
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
expect()->extend('toBeOne', fn() => $this->toBe(1));
/*
|--------------------------------------------------------------------------
@@ -42,7 +43,7 @@ expect()->extend('toBeOne', function () {
|
*/
function something()
function something(): void
{
// ..
}

View File

@@ -18,12 +18,10 @@ class ColorPickerTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->testModel = new TestModel;
}
/** @test */
public function it_returns_correct_colors_for_uppercase_letters()
public function it_returns_correct_colors_for_uppercase_letters(): void
{
$this->assertEquals([
'dark' => 'dark:bg-amber-500',
@@ -37,7 +35,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_handles_lowercase_letters_correctly()
public function it_handles_lowercase_letters_correctly(): void
{
$this->assertEquals([
'dark' => 'dark:bg-amber-500',
@@ -51,7 +49,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_returns_default_gray_color_for_invalid_letters()
public function it_returns_default_gray_color_for_invalid_letters(): void
{
$this->assertEquals([
'dark' => 'dark:bg-gray-500',
@@ -70,7 +68,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_handles_special_characters()
public function it_handles_special_characters(): void
{
$this->assertEquals([
'dark' => 'dark:bg-gray-500',
@@ -84,7 +82,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_returns_array_with_dark_and_light_keys()
public function it_returns_array_with_dark_and_light_keys(): void
{
$colors = TestModel::chooseColor('B');
@@ -94,7 +92,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_provides_consistent_color_mapping()
public function it_provides_consistent_color_mapping(): void
{
$colorA = TestModel::chooseColor('A');
$colorALower = TestModel::chooseColor('a');
@@ -103,7 +101,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_covers_all_letters_of_alphabet()
public function it_covers_all_letters_of_alphabet(): void
{
$alphabet = range('A', 'Z');
@@ -119,7 +117,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_handles_numbers_and_non_alphabetic_characters_gracefully()
public function it_handles_numbers_and_non_alphabetic_characters_gracefully(): void
{
$nonAlphaChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '[', ']', '{', '}', '|', '\\', ';', ':', "'", '"', ',', '.', '<', '>', '/', '?', '~', '`'];
@@ -134,7 +132,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_ensures_all_colors_follow_tailwind_css_naming_convention()
public function it_ensures_all_colors_follow_tailwind_css_naming_convention(): void
{
$alphabet = range('A', 'Z');
@@ -147,7 +145,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_provides_unique_colors_for_different_letters()
public function it_provides_unique_colors_for_different_letters(): void
{
$colorA = TestModel::chooseColor('A');
$colorB = TestModel::chooseColor('B');
@@ -159,7 +157,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_handles_mixed_case_input()
public function it_handles_mixed_case_input(): void
{
$mixedCaseColors = [
TestModel::chooseColor('H'),
@@ -174,10 +172,10 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_can_be_used_in_model_context()
public function it_can_be_used_in_model_context(): void
{
// Test with Email model that uses ColorPicker
$email = Email::factory()->create(['from_name' => 'John Doe']);
Email::factory()->create(['from_name' => 'John Doe']);
// This tests that the trait works when used by actual models
$colors = ColorPicker::chooseColor('J');
@@ -186,7 +184,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_maintains_backward_compatibility()
public function it_maintains_backward_compatibility(): void
{
// Ensure the color mapping remains consistent
$expectedColors = [
@@ -203,7 +201,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_handles_unicode_characters()
public function it_handles_unicode_characters(): void
{
$unicodeChars = ['ñ', 'ç', 'ü', 'ö', 'ä', 'ß'];
@@ -218,7 +216,7 @@ class ColorPickerTest extends TestCase
}
/** @test */
public function it_can_be_called_statically()
public function it_can_be_called_statically(): void
{
// Test both static and instance calling
$staticResult = TestModel::chooseColor('X');
@@ -226,7 +224,6 @@ class ColorPickerTest extends TestCase
$instance = new TestModel;
$reflection = new ReflectionClass($instance);
$method = $reflection->getMethod('chooseColor');
$method->setAccessible(true);
$instanceResult = $method->invoke(null, 'X');
$this->assertEquals($staticResult, $instanceResult);

View File

@@ -2,6 +2,6 @@
namespace Tests\Unit;
test('that true is true', function () {
test('that true is true', function (): void {
expect(true)->toBeTrue();
});

View File

@@ -8,6 +8,7 @@ use Tests\TestCase;
class ActivationKeyTest extends TestCase
{
public $user;
protected function setUp(): void
{
parent::setUp();
@@ -16,7 +17,7 @@ class ActivationKeyTest extends TestCase
}
/** @test */
public function it_can_create_an_activation_key_with_factory()
public function it_can_create_an_activation_key_with_factory(): void
{
$activationKey = ActivationKey::factory()->create();
@@ -26,7 +27,7 @@ class ActivationKeyTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$activationKeyData = [
'user_id' => $this->user->id,
@@ -35,7 +36,7 @@ class ActivationKeyTest extends TestCase
'is_activated' => false,
];
$activationKey = ActivationKey::create($activationKeyData);
$activationKey = ActivationKey::query()->create($activationKeyData);
foreach ($activationKeyData as $key => $value) {
$this->assertEquals($value, $activationKey->$key);
@@ -43,7 +44,7 @@ class ActivationKeyTest extends TestCase
}
/** @test */
public function it_belongs_to_a_user()
public function it_belongs_to_a_user(): void
{
$activationKey = ActivationKey::factory()->create(['user_id' => $this->user->id]);
@@ -52,7 +53,7 @@ class ActivationKeyTest extends TestCase
}
/** @test */
public function it_generates_unique_keys()
public function it_generates_unique_keys(): void
{
$key1 = ActivationKey::factory()->create();
$key2 = ActivationKey::factory()->create();
@@ -61,13 +62,13 @@ class ActivationKeyTest extends TestCase
}
/** @test */
public function it_can_query_unactivated_activation_keys()
public function it_can_query_unactivated_activation_keys(): void
{
$unactivatedKey = ActivationKey::factory()->create(['is_activated' => false]);
$activatedKey = ActivationKey::factory()->create(['is_activated' => true]);
ActivationKey::factory()->create(['is_activated' => false]);
ActivationKey::factory()->create(['is_activated' => true]);
$unactivatedKeys = ActivationKey::where('is_activated', false)->get();
$activatedKeys = ActivationKey::where('is_activated', true)->get();
$unactivatedKeys = ActivationKey::query()->where('is_activated', false)->get();
$activatedKeys = ActivationKey::query()->where('is_activated', true)->get();
$this->assertCount(1, $unactivatedKeys);
$this->assertCount(1, $activatedKeys);

View File

@@ -2,6 +2,8 @@
namespace Tests\Unit\Models;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use App\Models\Blog;
use App\Models\Category;
use App\Models\User;
@@ -9,6 +11,8 @@ use Tests\TestCase;
class BlogTest extends TestCase
{
private User|Collection $user;
public $category;
protected function setUp(): void
{
parent::setUp();
@@ -18,7 +22,7 @@ class BlogTest extends TestCase
}
/** @test */
public function it_can_create_a_blog_with_factory()
public function it_can_create_a_blog_with_factory(): void
{
$blog = Blog::factory()->create();
@@ -28,7 +32,7 @@ class BlogTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$blogData = [
'post' => 'Test Blog Post',
@@ -41,7 +45,7 @@ class BlogTest extends TestCase
'category_id' => $this->category->id,
];
$blog = Blog::create($blogData);
$blog = Blog::query()->create($blogData);
foreach ($blogData as $key => $value) {
$this->assertEquals($value, $blog->$key);
@@ -49,7 +53,7 @@ class BlogTest extends TestCase
}
/** @test */
public function it_belongs_to_a_category()
public function it_belongs_to_a_category(): void
{
$blog = Blog::factory()->create(['category_id' => $this->category->id]);
@@ -58,7 +62,7 @@ class BlogTest extends TestCase
}
/** @test */
public function it_generates_unique_slugs()
public function it_generates_unique_slugs(): void
{
$blog1 = Blog::factory()->create(['post' => 'Same Title']);
$blog2 = Blog::factory()->create(['post' => 'Same Title']);
@@ -67,20 +71,20 @@ class BlogTest extends TestCase
}
/** @test */
public function it_can_query_published_blogs()
public function it_can_query_published_blogs(): void
{
$publishedBlog = Blog::factory()->create(['is_published' => true]);
$draftBlog = Blog::factory()->create(['is_published' => false]);
Blog::factory()->create(['is_published' => true]);
Blog::factory()->create(['is_published' => false]);
$publishedBlogs = Blog::where('is_published', true)->get();
$draftBlogs = Blog::where('is_published', false)->get();
$publishedBlogs = Blog::query()->where('is_published', true)->get();
$draftBlogs = Blog::query()->where('is_published', false)->get();
$this->assertCount(1, $publishedBlogs);
$this->assertCount(1, $draftBlogs);
}
/** @test */
public function it_can_create_blogs_with_custom_headers()
public function it_can_create_blogs_with_custom_headers(): void
{
$blog = Blog::factory()->create(['custom_header' => 'Custom Header Text']);
@@ -88,30 +92,30 @@ class BlogTest extends TestCase
}
/** @test */
public function it_orders_blogs_by_creation_date()
public function it_orders_blogs_by_creation_date(): void
{
$oldBlog = Blog::factory()->create(['created_at' => now()->subDays(2)]);
$newBlog = Blog::factory()->create(['created_at' => now()]);
$blogs = Blog::orderBy('created_at', 'desc')->get();
$blogs = Blog::query()->latest()->get();
$this->assertEquals($newBlog->id, $blogs->first()->id);
$this->assertEquals($oldBlog->id, $blogs->last()->id);
}
/** @test */
public function it_handles_long_content()
public function it_handles_long_content(): void
{
$longContent = str_repeat('This is a very long blog content. ', 100);
$blog = Blog::factory()->create(['content' => $longContent]);
$this->assertEquals($longContent, $blog->content);
$this->assertGreaterThan(1000, strlen($blog->content));
$this->assertGreaterThan(1000, strlen((string) $blog->content));
}
/** @test */
public function it_can_update_blog_status()
public function it_can_update_blog_status(): void
{
$blog = Blog::factory()->create(['is_published' => false]);
@@ -122,24 +126,24 @@ class BlogTest extends TestCase
}
/** @test */
public function it_scopes_blogs_by_category()
public function it_scopes_blogs_by_category(): void
{
$category1 = Category::factory()->create();
$category2 = Category::factory()->create();
$blog1 = Blog::factory()->create(['category_id' => $category1->id]);
$blog2 = Blog::factory()->create(['category_id' => $category1->id]);
$blog3 = Blog::factory()->create(['category_id' => $category2->id]);
Blog::factory()->create(['category_id' => $category1->id]);
Blog::factory()->create(['category_id' => $category1->id]);
Blog::factory()->create(['category_id' => $category2->id]);
$category1Blogs = Blog::where('category_id', $category1->id)->get();
$category2Blogs = Blog::where('category_id', $category2->id)->get();
$category1Blogs = Blog::query()->where('category_id', $category1->id)->get();
$category2Blogs = Blog::query()->where('category_id', $category2->id)->get();
$this->assertCount(2, $category1Blogs);
$this->assertCount(1, $category2Blogs);
}
/** @test */
public function it_uses_correct_table_name()
public function it_uses_correct_table_name(): void
{
$blog = new Blog;
@@ -147,10 +151,10 @@ class BlogTest extends TestCase
}
/** @test */
public function it_extends_model_class()
public function it_extends_model_class(): void
{
$blog = new Blog;
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Model::class, $blog);
$this->assertInstanceOf(Model::class, $blog);
}
}

View File

@@ -2,6 +2,7 @@
namespace Tests\Unit\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Blog;
use App\Models\Category;
use Tests\TestCase;
@@ -9,7 +10,7 @@ use Tests\TestCase;
class CategoryTest extends TestCase
{
/** @test */
public function it_can_create_a_category_with_factory()
public function it_can_create_a_category_with_factory(): void
{
$category = Category::factory()->create();
@@ -19,7 +20,7 @@ class CategoryTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$categoryData = [
'name' => 'Technology',
@@ -27,7 +28,7 @@ class CategoryTest extends TestCase
'is_active' => true,
];
$category = Category::create($categoryData);
$category = Category::query()->create($categoryData);
foreach ($categoryData as $key => $value) {
$this->assertEquals($value, $category->$key);
@@ -35,7 +36,7 @@ class CategoryTest extends TestCase
}
/** @test */
public function it_has_many_blogs()
public function it_has_many_blogs(): void
{
$category = Category::factory()->create();
$blog1 = Blog::factory()->create(['category_id' => $category->id]);
@@ -47,7 +48,7 @@ class CategoryTest extends TestCase
}
/** @test */
public function it_generates_unique_slugs()
public function it_generates_unique_slugs(): void
{
$category1 = Category::factory()->create(['name' => 'Same Name']);
$category2 = Category::factory()->create(['name' => 'Same Name']);
@@ -56,20 +57,20 @@ class CategoryTest extends TestCase
}
/** @test */
public function it_can_query_active_categories()
public function it_can_query_active_categories(): void
{
$activeCategory = Category::factory()->create(['is_active' => true]);
$inactiveCategory = Category::factory()->create(['is_active' => false]);
Category::factory()->create(['is_active' => true]);
Category::factory()->create(['is_active' => false]);
$activeCategories = Category::where('is_active', true)->get();
$inactiveCategories = Category::where('is_active', false)->get();
$activeCategories = Category::query()->where('is_active', true)->get();
$inactiveCategories = Category::query()->where('is_active', false)->get();
$this->assertCount(1, $activeCategories);
$this->assertCount(1, $inactiveCategories);
}
/** @test */
public function it_stores_is_active_status_correctly()
public function it_stores_is_active_status_correctly(): void
{
$category = Category::factory()->create(['is_active' => false]);
@@ -77,7 +78,7 @@ class CategoryTest extends TestCase
}
/** @test */
public function it_uses_correct_table_name()
public function it_uses_correct_table_name(): void
{
$category = new Category;
@@ -85,10 +86,10 @@ class CategoryTest extends TestCase
}
/** @test */
public function it_extends_model_class()
public function it_extends_model_class(): void
{
$category = new Category;
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Model::class, $category);
$this->assertInstanceOf(Model::class, $category);
}
}

View File

@@ -2,6 +2,7 @@
namespace Tests\Unit\Models;
use Illuminate\Support\Facades\Date;
use App\Models\Email;
use Carbon\Carbon;
use Illuminate\Support\Facades\Config;
@@ -36,7 +37,7 @@ class EmailTest extends TestCase
}
/** @test */
public function it_can_create_email_with_factory()
public function it_can_create_email_with_factory(): void
{
$email = Email::factory()->create();
@@ -47,7 +48,7 @@ class EmailTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$emailData = [
'message_id' => '12345',
@@ -63,7 +64,7 @@ class EmailTest extends TestCase
'mailbox' => 'INBOX',
];
$email = Email::create($emailData);
$email = Email::query()->create($emailData);
foreach ($emailData as $key => $value) {
$this->assertEquals($value, $email->$key);
@@ -71,7 +72,7 @@ class EmailTest extends TestCase
}
/** @test */
public function it_casts_attributes_correctly()
public function it_casts_attributes_correctly(): void
{
$email = Email::factory()->create([
'to' => ['test1@example.com', 'test2@example.com'],
@@ -89,7 +90,7 @@ class EmailTest extends TestCase
}
/** @test */
public function it_validates_email_format_in_fetch_email_from_db()
public function it_validates_email_format_in_fetch_email_from_db(): void
{
$result = Email::fetchEmailFromDB('invalid-email');
@@ -97,7 +98,7 @@ class EmailTest extends TestCase
}
/** @test */
public function it_fetches_emails_from_database_with_valid_email()
public function it_fetches_emails_from_database_with_valid_email(): void
{
$email1 = Email::factory()->create(['to' => ['test@example.com']]);
$email2 = Email::factory()->create(['to' => ['other@example.com']]);
@@ -112,15 +113,15 @@ class EmailTest extends TestCase
}
/** @test */
public function it_orders_emails_by_timestamp_descending_in_fetch_email_from_db()
public function it_orders_emails_by_timestamp_descending_in_fetch_email_from_db(): void
{
$oldEmail = Email::factory()->create([
'to' => ['test@example.com'],
'timestamp' => Carbon::now()->subHours(2),
'timestamp' => Date::now()->subHours(2),
]);
$newEmail = Email::factory()->create([
'to' => ['test@example.com'],
'timestamp' => Carbon::now(),
'timestamp' => Date::now(),
]);
$results = Email::fetchEmailFromDB('test@example.com');
@@ -130,7 +131,7 @@ class EmailTest extends TestCase
}
/** @test */
public function it_sets_correct_table_name()
public function it_sets_correct_table_name(): void
{
$email = new Email;

View File

@@ -8,6 +8,7 @@ use Tests\TestCase;
class LogTest extends TestCase
{
public $user;
protected function setUp(): void
{
parent::setUp();
@@ -16,7 +17,7 @@ class LogTest extends TestCase
}
/** @test */
public function it_can_create_a_log_with_factory()
public function it_can_create_a_log_with_factory(): void
{
$log = Log::factory()->create();
@@ -26,7 +27,7 @@ class LogTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$logData = [
'user_id' => $this->user->id,
@@ -34,7 +35,7 @@ class LogTest extends TestCase
'ip' => '192.168.1.1',
];
$log = Log::create($logData);
$log = Log::query()->create($logData);
foreach ($logData as $key => $value) {
$this->assertEquals($value, $log->$key);
@@ -42,7 +43,7 @@ class LogTest extends TestCase
}
/** @test */
public function it_belongs_to_a_user()
public function it_belongs_to_a_user(): void
{
$log = Log::factory()->create(['user_id' => $this->user->id]);
@@ -51,7 +52,7 @@ class LogTest extends TestCase
}
/** @test */
public function it_stores_ip_addresses_correctly()
public function it_stores_ip_addresses_correctly(): void
{
$ipAddresses = ['127.0.0.1', '192.168.1.100', '10.0.0.1'];
@@ -62,12 +63,12 @@ class LogTest extends TestCase
}
/** @test */
public function it_orders_logs_by_creation_date()
public function it_orders_logs_by_creation_date(): void
{
$oldLog = Log::factory()->create(['created_at' => now()->subHours(2)]);
$newLog = Log::factory()->create(['created_at' => now()]);
$logs = Log::orderBy('created_at', 'desc')->get();
$logs = Log::query()->latest()->get();
$this->assertEquals($newLog->id, $logs->first()->id);
$this->assertEquals($oldLog->id, $logs->last()->id);

View File

@@ -8,7 +8,7 @@ use Tests\TestCase;
class MenuTest extends TestCase
{
/** @test */
public function it_can_create_a_menu_with_factory()
public function it_can_create_a_menu_with_factory(): void
{
$menu = Menu::factory()->create();
@@ -18,7 +18,7 @@ class MenuTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$menuData = [
'name' => 'Home',
@@ -27,7 +27,7 @@ class MenuTest extends TestCase
'parent' => null,
];
$menu = Menu::create($menuData);
$menu = Menu::query()->create($menuData);
foreach ($menuData as $key => $value) {
$this->assertEquals($value, $menu->$key);
@@ -35,13 +35,13 @@ class MenuTest extends TestCase
}
/** @test */
public function it_orders_menus_by_name()
public function it_orders_menus_by_name(): void
{
$menu1 = Menu::factory()->create(['name' => 'Zebra']);
$menu2 = Menu::factory()->create(['name' => 'Alpha']);
$menu3 = Menu::factory()->create(['name' => 'Beta']);
$menus = Menu::orderBy('name')->get();
$menus = Menu::query()->orderBy('name')->get();
$this->assertEquals($menu2->id, $menus[0]->id);
$this->assertEquals($menu3->id, $menus[1]->id);
@@ -49,9 +49,9 @@ class MenuTest extends TestCase
}
/** @test */
public function it_can_handle_parent_child_relationships()
public function it_can_handle_parent_child_relationships(): void
{
$parentMenu = Menu::factory()->create(['parent' => null]);
Menu::factory()->create(['parent' => null]);
$childMenu = Menu::factory()->create(['parent' => 'home']);
$this->assertEquals('home', $childMenu->parent);

View File

@@ -9,7 +9,7 @@ use Tests\TestCase;
class MessageTest extends TestCase
{
/** @test */
public function it_can_create_a_message_with_factory()
public function it_can_create_a_message_with_factory(): void
{
$message = Message::factory()->create();
@@ -19,7 +19,7 @@ class MessageTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$messageData = [
'subject' => 'Test Message',
@@ -30,7 +30,7 @@ class MessageTest extends TestCase
'is_seen' => false,
];
$message = Message::create($messageData);
$message = Message::query()->create($messageData);
foreach ($messageData as $key => $value) {
$this->assertEquals($value, $message->$key);
@@ -38,7 +38,7 @@ class MessageTest extends TestCase
}
/** @test */
public function it_stores_to_field_as_string()
public function it_stores_to_field_as_string(): void
{
$to = 'test1@example.com';
$message = Message::factory()->create(['to' => $to]);
@@ -48,7 +48,7 @@ class MessageTest extends TestCase
}
/** @test */
public function it_uses_created_at_as_timestamp()
public function it_uses_created_at_as_timestamp(): void
{
$message = Message::factory()->create();
@@ -57,13 +57,13 @@ class MessageTest extends TestCase
}
/** @test */
public function it_can_query_unseen_messages()
public function it_can_query_unseen_messages(): void
{
$unseenMessage = Message::factory()->create(['is_seen' => false]);
$seenMessage = Message::factory()->create(['is_seen' => true]);
Message::factory()->create(['is_seen' => false]);
Message::factory()->create(['is_seen' => true]);
$unseenMessages = Message::where('is_seen', false)->get();
$seenMessages = Message::where('is_seen', true)->get();
$unseenMessages = Message::query()->where('is_seen', false)->get();
$seenMessages = Message::query()->where('is_seen', true)->get();
$this->assertCount(1, $unseenMessages);
$this->assertCount(1, $seenMessages);

View File

@@ -8,7 +8,7 @@ use Tests\TestCase;
class MetaTest extends TestCase
{
/** @test */
public function it_can_create_a_meta_with_factory()
public function it_can_create_a_meta_with_factory(): void
{
$meta = Meta::factory()->create();
@@ -18,14 +18,14 @@ class MetaTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$metaData = [
'key' => 'total_emails_created',
'value' => '1500',
];
$meta = Meta::create($metaData);
$meta = Meta::query()->create($metaData);
foreach ($metaData as $key => $value) {
$this->assertEquals($value, $meta->$key);
@@ -33,7 +33,7 @@ class MetaTest extends TestCase
}
/** @test */
public function it_stores_key_value_pairs_correctly()
public function it_stores_key_value_pairs_correctly(): void
{
$meta = Meta::factory()->create([
'key' => 'app_version',
@@ -45,13 +45,13 @@ class MetaTest extends TestCase
}
/** @test */
public function it_can_retrieve_value_by_key()
public function it_can_retrieve_value_by_key(): void
{
Meta::factory()->create(['key' => 'site_name', 'value' => 'ZEmailnator']);
Meta::factory()->create(['key' => 'max_emails', 'value' => '100']);
$siteName = Meta::where('key', 'site_name')->first();
$maxEmails = Meta::where('key', 'max_emails')->first();
$siteName = Meta::query()->where('key', 'site_name')->first();
$maxEmails = Meta::query()->where('key', 'max_emails')->first();
$this->assertEquals('ZEmailnator', $siteName->value);
$this->assertEquals('100', $maxEmails->value);

View File

@@ -8,7 +8,7 @@ use Tests\TestCase;
class PageTest extends TestCase
{
/** @test */
public function it_can_create_a_page_with_factory()
public function it_can_create_a_page_with_factory(): void
{
$page = Page::factory()->create();
@@ -18,7 +18,7 @@ class PageTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$pageData = [
'title' => 'About Us',
@@ -31,7 +31,7 @@ class PageTest extends TestCase
'is_published' => true,
];
$page = Page::create($pageData);
$page = Page::query()->create($pageData);
foreach ($pageData as $key => $value) {
$this->assertEquals($value, $page->$key);
@@ -39,7 +39,7 @@ class PageTest extends TestCase
}
/** @test */
public function it_generates_unique_slugs()
public function it_generates_unique_slugs(): void
{
$page1 = Page::factory()->create(['title' => 'Same Title']);
$page2 = Page::factory()->create(['title' => 'Same Title']);
@@ -48,13 +48,13 @@ class PageTest extends TestCase
}
/** @test */
public function it_can_query_published_pages()
public function it_can_query_published_pages(): void
{
$publishedPage = Page::factory()->create(['is_published' => true]);
$draftPage = Page::factory()->create(['is_published' => false]);
Page::factory()->create(['is_published' => true]);
Page::factory()->create(['is_published' => false]);
$publishedPages = Page::where('is_published', true)->get();
$draftPages = Page::where('is_published', false)->get();
$publishedPages = Page::query()->where('is_published', true)->get();
$draftPages = Page::query()->where('is_published', false)->get();
$this->assertCount(1, $publishedPages);
$this->assertCount(1, $draftPages);

View File

@@ -2,11 +2,13 @@
namespace Tests\Unit\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Plan;
use Tests\TestCase;
class PlanTest extends TestCase
{
public $planData;
protected function setUp(): void
{
parent::setUp();
@@ -33,7 +35,7 @@ class PlanTest extends TestCase
}
/** @test */
public function it_can_create_a_plan_with_factory()
public function it_can_create_a_plan_with_factory(): void
{
$plan = Plan::factory()->create();
@@ -43,9 +45,9 @@ class PlanTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$plan = Plan::create($this->planData);
$plan = Plan::query()->create($this->planData);
foreach ($this->planData as $key => $value) {
$this->assertEquals($value, $plan->$key);
@@ -53,7 +55,7 @@ class PlanTest extends TestCase
}
/** @test */
public function it_casts_details_to_json()
public function it_casts_details_to_json(): void
{
$details = [
'feature1' => 'Unlimited emails',
@@ -67,7 +69,7 @@ class PlanTest extends TestCase
}
/** @test */
public function it_casts_monthly_billing_to_boolean()
public function it_casts_monthly_billing_to_boolean(): void
{
$plan1 = Plan::factory()->create(['monthly_billing' => true]);
$plan2 = Plan::factory()->create(['monthly_billing' => false]);
@@ -79,7 +81,7 @@ class PlanTest extends TestCase
}
/** @test */
public function it_accepts_different_payment_methods()
public function it_accepts_different_payment_methods(): void
{
$plan = Plan::factory()->create([
'accept_stripe' => true,
@@ -93,7 +95,7 @@ class PlanTest extends TestCase
}
/** @test */
public function it_stores_monetary_values_correctly()
public function it_stores_monetary_values_correctly(): void
{
$plan = Plan::factory()->create([
'price' => 19.99,
@@ -104,7 +106,7 @@ class PlanTest extends TestCase
}
/** @test */
public function it_stores_mailbox_limit_as_integer()
public function it_stores_mailbox_limit_as_integer(): void
{
$plan = Plan::factory()->create([
'mailbox_limit' => 50,
@@ -115,7 +117,7 @@ class PlanTest extends TestCase
}
/** @test */
public function it_can_update_plan_attributes()
public function it_can_update_plan_attributes(): void
{
$plan = Plan::factory()->create();
@@ -133,7 +135,7 @@ class PlanTest extends TestCase
}
/** @test */
public function it_uses_correct_table_name()
public function it_uses_correct_table_name(): void
{
$plan = new Plan;
@@ -141,10 +143,10 @@ class PlanTest extends TestCase
}
/** @test */
public function it_extends_model_class()
public function it_extends_model_class(): void
{
$plan = new Plan;
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Model::class, $plan);
$this->assertInstanceOf(Model::class, $plan);
}
}

View File

@@ -9,6 +9,7 @@ use Tests\TestCase;
class PremiumEmailTest extends TestCase
{
public $user;
protected function setUp(): void
{
parent::setUp();
@@ -17,7 +18,7 @@ class PremiumEmailTest extends TestCase
}
/** @test */
public function it_can_create_a_premium_email_with_factory()
public function it_can_create_a_premium_email_with_factory(): void
{
$premiumEmail = PremiumEmail::factory()->create();
@@ -27,7 +28,7 @@ class PremiumEmailTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$premiumEmailData = [
'user_id' => $this->user->id,
@@ -38,7 +39,7 @@ class PremiumEmailTest extends TestCase
'to' => ['recipient@example.com'],
];
$premiumEmail = PremiumEmail::create($premiumEmailData);
$premiumEmail = PremiumEmail::query()->create($premiumEmailData);
foreach ($premiumEmailData as $key => $value) {
$this->assertEquals($value, $premiumEmail->$key);
@@ -46,7 +47,7 @@ class PremiumEmailTest extends TestCase
}
/** @test */
public function it_belongs_to_a_user()
public function it_belongs_to_a_user(): void
{
$premiumEmail = PremiumEmail::factory()->create(['user_id' => $this->user->id]);
@@ -55,7 +56,7 @@ class PremiumEmailTest extends TestCase
}
/** @test */
public function it_casts_timestamp_to_datetime()
public function it_casts_timestamp_to_datetime(): void
{
$timestamp = now()->subDays(5);
$premiumEmail = PremiumEmail::factory()->create(['timestamp' => $timestamp]);
@@ -65,13 +66,13 @@ class PremiumEmailTest extends TestCase
}
/** @test */
public function it_can_query_seen_and_unseen_emails()
public function it_can_query_seen_and_unseen_emails(): void
{
$seenEmail = PremiumEmail::factory()->create(['is_seen' => true]);
$unseenEmail = PremiumEmail::factory()->create(['is_seen' => false]);
PremiumEmail::factory()->create(['is_seen' => true]);
PremiumEmail::factory()->create(['is_seen' => false]);
$seenEmails = PremiumEmail::where('is_seen', true)->get();
$unseenEmails = PremiumEmail::where('is_seen', false)->get();
$seenEmails = PremiumEmail::query()->where('is_seen', true)->get();
$unseenEmails = PremiumEmail::query()->where('is_seen', false)->get();
$this->assertCount(1, $seenEmails);
$this->assertCount(1, $unseenEmails);

View File

@@ -9,7 +9,7 @@ use Tests\TestCase;
class RemoteEmailTest extends TestCase
{
/** @test */
public function it_can_create_a_remote_email_with_factory()
public function it_can_create_a_remote_email_with_factory(): void
{
$remoteEmail = RemoteEmail::factory()->create();
@@ -19,7 +19,7 @@ class RemoteEmailTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$timestamp = now();
$remoteEmailData = [
@@ -34,7 +34,7 @@ class RemoteEmailTest extends TestCase
'timestamp' => $timestamp,
];
$remoteEmail = RemoteEmail::create($remoteEmailData);
$remoteEmail = RemoteEmail::query()->create($remoteEmailData);
foreach ($remoteEmailData as $key => $value) {
if ($key === 'timestamp') {
@@ -47,7 +47,7 @@ class RemoteEmailTest extends TestCase
}
/** @test */
public function it_casts_to_field_to_array()
public function it_casts_to_field_to_array(): void
{
$to = ['test1@example.com', 'test2@example.com'];
$remoteEmail = RemoteEmail::factory()->create(['to' => $to]);
@@ -57,7 +57,7 @@ class RemoteEmailTest extends TestCase
}
/** @test */
public function it_casts_timestamp_to_datetime()
public function it_casts_timestamp_to_datetime(): void
{
$timestamp = now();
$remoteEmail = RemoteEmail::factory()->create(['timestamp' => $timestamp]);

View File

@@ -8,7 +8,7 @@ use Tests\TestCase;
class SettingTest extends TestCase
{
/** @test */
public function it_can_create_a_setting_with_factory()
public function it_can_create_a_setting_with_factory(): void
{
$setting = Setting::factory()->create();
@@ -18,7 +18,7 @@ class SettingTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$settingData = [
'app_name' => 'ZEmailnator',
@@ -28,7 +28,7 @@ class SettingTest extends TestCase
'app_title' => 'Test Title',
];
$setting = Setting::create($settingData);
$setting = Setting::query()->create($settingData);
foreach ($settingData as $key => $value) {
$this->assertEquals($value, $setting->$key);
@@ -36,7 +36,7 @@ class SettingTest extends TestCase
}
/** @test */
public function it_stores_configuration_values()
public function it_stores_configuration_values(): void
{
$setting = Setting::factory()->create([
'app_name' => 'Test App',
@@ -54,10 +54,10 @@ class SettingTest extends TestCase
}
/** @test */
public function it_can_query_public_settings()
public function it_can_query_public_settings(): void
{
$setting1 = Setting::factory()->create(['app_name' => 'Public App']);
$setting2 = Setting::factory()->create(['app_name' => 'Private App']);
Setting::factory()->create(['app_name' => 'Public App']);
Setting::factory()->create(['app_name' => 'Private App']);
$allSettings = Setting::all();

View File

@@ -2,6 +2,7 @@
namespace Tests\Unit\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Ticket;
use App\Models\TicketResponse;
use App\Models\User;
@@ -10,6 +11,8 @@ use Tests\TestCase;
class TicketResponseTest extends TestCase
{
public $user;
public $ticket;
protected function setUp(): void
{
parent::setUp();
@@ -19,7 +22,7 @@ class TicketResponseTest extends TestCase
}
/** @test */
public function it_can_create_a_ticket_response_with_factory()
public function it_can_create_a_ticket_response_with_factory(): void
{
$response = TicketResponse::factory()->create();
@@ -28,7 +31,7 @@ class TicketResponseTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$responseData = [
'ticket_id' => $this->ticket->id,
@@ -37,7 +40,7 @@ class TicketResponseTest extends TestCase
'ip_address' => '192.168.1.1',
];
$response = TicketResponse::create($responseData);
$response = TicketResponse::query()->create($responseData);
foreach ($responseData as $key => $value) {
$this->assertEquals($value, $response->$key);
@@ -45,7 +48,7 @@ class TicketResponseTest extends TestCase
}
/** @test */
public function it_belongs_to_a_ticket()
public function it_belongs_to_a_ticket(): void
{
$response = TicketResponse::factory()->create(['ticket_id' => $this->ticket->id]);
@@ -54,7 +57,7 @@ class TicketResponseTest extends TestCase
}
/** @test */
public function it_belongs_to_a_user()
public function it_belongs_to_a_user(): void
{
$response = TicketResponse::factory()->create(['user_id' => $this->user->id]);
@@ -63,7 +66,7 @@ class TicketResponseTest extends TestCase
}
/** @test */
public function it_casts_datetime_fields_correctly()
public function it_casts_datetime_fields_correctly(): void
{
$response = TicketResponse::factory()->create([
'created_at' => '2024-01-01 12:00:00',
@@ -75,7 +78,7 @@ class TicketResponseTest extends TestCase
}
/** @test */
public function it_orders_responses_by_creation_date()
public function it_orders_responses_by_creation_date(): void
{
$oldResponse = TicketResponse::factory()->create([
'ticket_id' => $this->ticket->id,
@@ -86,8 +89,7 @@ class TicketResponseTest extends TestCase
'created_at' => now(),
]);
$responses = TicketResponse::where('ticket_id', $this->ticket->id)
->orderBy('created_at', 'asc')
$responses = TicketResponse::query()->where('ticket_id', $this->ticket->id)->oldest()
->get();
$this->assertEquals($oldResponse->id, $responses->first()->id);
@@ -95,33 +97,33 @@ class TicketResponseTest extends TestCase
}
/** @test */
public function it_can_query_responses_by_ticket()
public function it_can_query_responses_by_ticket(): void
{
$response1 = TicketResponse::factory()->create([
TicketResponse::factory()->create([
'ticket_id' => $this->ticket->id,
]);
$response2 = TicketResponse::factory()->create([
TicketResponse::factory()->create([
'ticket_id' => $this->ticket->id,
]);
$ticketResponses = TicketResponse::where('ticket_id', $this->ticket->id)->get();
$ticketResponses = TicketResponse::query()->where('ticket_id', $this->ticket->id)->get();
$this->assertCount(2, $ticketResponses);
}
/** @test */
public function it_handles_long_responses()
public function it_handles_long_responses(): void
{
$longResponse = str_repeat('This is a very long response. ', 50);
$response = TicketResponse::factory()->create(['response' => $longResponse]);
$this->assertEquals($longResponse, $response->response);
$this->assertGreaterThan(500, strlen($response->response));
$this->assertGreaterThan(500, strlen((string) $response->response));
}
/** @test */
public function it_uses_correct_table_name()
public function it_uses_correct_table_name(): void
{
$response = new TicketResponse;
@@ -129,10 +131,10 @@ class TicketResponseTest extends TestCase
}
/** @test */
public function it_extends_model_class()
public function it_extends_model_class(): void
{
$response = new TicketResponse;
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Model::class, $response);
$this->assertInstanceOf(Model::class, $response);
}
}

View File

@@ -2,6 +2,7 @@
namespace Tests\Unit\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Ticket;
use App\Models\TicketResponse;
use App\Models\User;
@@ -10,6 +11,8 @@ use Tests\TestCase;
class TicketTest extends TestCase
{
public $user;
public $ticketData;
protected function setUp(): void
{
parent::setUp();
@@ -27,7 +30,7 @@ class TicketTest extends TestCase
}
/** @test */
public function it_can_create_a_ticket_with_factory()
public function it_can_create_a_ticket_with_factory(): void
{
$ticket = Ticket::factory()->create();
@@ -37,9 +40,9 @@ class TicketTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$ticket = Ticket::create($this->ticketData);
$ticket = Ticket::query()->create($this->ticketData);
foreach ($this->ticketData as $key => $value) {
if ($key === 'last_response_at') {
@@ -52,7 +55,7 @@ class TicketTest extends TestCase
}
/** @test */
public function it_belongs_to_user()
public function it_belongs_to_user(): void
{
$ticket = Ticket::factory()->create(['user_id' => $this->user->id]);
@@ -61,7 +64,7 @@ class TicketTest extends TestCase
}
/** @test */
public function it_has_many_ticket_responses()
public function it_has_many_ticket_responses(): void
{
$ticket = Ticket::factory()->create();
$response1 = TicketResponse::factory()->create(['ticket_id' => $ticket->id]);
@@ -73,7 +76,7 @@ class TicketTest extends TestCase
}
/** @test */
public function it_casts_last_response_at_to_datetime()
public function it_casts_last_response_at_to_datetime(): void
{
$ticket = Ticket::factory()->create([
'last_response_at' => '2024-01-01 12:00:00',
@@ -83,7 +86,7 @@ class TicketTest extends TestCase
}
/** @test */
public function it_uses_correct_table_name()
public function it_uses_correct_table_name(): void
{
$ticket = new Ticket;
@@ -91,10 +94,10 @@ class TicketTest extends TestCase
}
/** @test */
public function it_extends_model_class()
public function it_extends_model_class(): void
{
$ticket = new Ticket;
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Model::class, $ticket);
$this->assertInstanceOf(Model::class, $ticket);
}
}

View File

@@ -8,6 +8,7 @@ use Tests\TestCase;
class UsageLogTest extends TestCase
{
public $user;
protected function setUp(): void
{
parent::setUp();
@@ -16,7 +17,7 @@ class UsageLogTest extends TestCase
}
/** @test */
public function it_can_create_a_usage_log_with_factory()
public function it_can_create_a_usage_log_with_factory(): void
{
$usageLog = UsageLog::factory()->create();
@@ -26,7 +27,7 @@ class UsageLogTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$usageLogData = [
'user_id' => $this->user->id,
@@ -37,7 +38,7 @@ class UsageLogTest extends TestCase
'emails_received_history' => json_encode(['2023-01-01 12:30:00' => 7]),
];
$usageLog = UsageLog::create($usageLogData);
$usageLog = UsageLog::query()->create($usageLogData);
foreach ($usageLogData as $key => $value) {
$this->assertEquals($value, $usageLog->$key);
@@ -45,7 +46,7 @@ class UsageLogTest extends TestCase
}
/** @test */
public function it_belongs_to_a_user()
public function it_belongs_to_a_user(): void
{
$usageLog = UsageLog::factory()->create(['user_id' => $this->user->id]);
@@ -54,7 +55,7 @@ class UsageLogTest extends TestCase
}
/** @test */
public function it_tracks_different_email_counts()
public function it_tracks_different_email_counts(): void
{
$usageLog = UsageLog::factory()->create([
'emails_created_count' => 15,

View File

@@ -2,6 +2,15 @@
namespace Tests\Unit\Models;
use Carbon\Carbon;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Laravel\Cashier\Billable;
use Laravel\Sanctum\HasApiTokens;
use Filament\Models\Contracts\FilamentUser;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Laravel\Sanctum\NewAccessToken;
use App\Models\Log;
use App\Models\Ticket;
use App\Models\UsageLog;
@@ -11,6 +20,7 @@ use Tests\TestCase;
class UserTest extends TestCase
{
public $user;
protected function setUp(): void
{
parent::setUp();
@@ -19,7 +29,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_can_create_a_user_with_factory()
public function it_can_create_a_user_with_factory(): void
{
$this->assertInstanceOf(User::class, $this->user);
$this->assertIsString($this->user->name);
@@ -28,7 +38,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_has_correct_fillable_attributes()
public function it_has_correct_fillable_attributes(): void
{
$userData = [
'name' => 'Test User',
@@ -36,7 +46,7 @@ class UserTest extends TestCase
'password' => 'password',
];
$user = User::create($userData);
$user = User::query()->create($userData);
$this->assertEquals('Test User', $user->name);
$this->assertEquals('test@example.com', $user->email);
@@ -44,7 +54,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_hides_sensitive_attributes()
public function it_hides_sensitive_attributes(): void
{
$userArray = $this->user->toArray();
@@ -53,30 +63,30 @@ class UserTest extends TestCase
}
/** @test */
public function it_casts_email_verified_at_to_datetime()
public function it_casts_email_verified_at_to_datetime(): void
{
$this->user->email_verified_at = now();
$this->user->save();
$this->assertInstanceOf(\Carbon\Carbon::class, $this->user->email_verified_at);
$this->assertInstanceOf(Carbon::class, $this->user->email_verified_at);
}
/** @test */
public function it_hashes_password()
public function it_hashes_password(): void
{
$plainPassword = 'password123';
$user = User::create([
$user = User::query()->create([
'name' => 'Test User',
'email' => 'test@example.com',
'password' => $plainPassword,
]);
$this->assertNotEquals($plainPassword, $user->password);
$this->assertTrue(\Illuminate\Support\Facades\Hash::check($plainPassword, $user->password));
$this->assertTrue(Hash::check($plainPassword, $user->password));
}
/** @test */
public function it_generates_initials_correctly()
public function it_generates_initials_correctly(): void
{
$user = User::factory()->create(['name' => 'John Doe']);
$this->assertEquals('JD', $user->initials());
@@ -89,7 +99,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_can_access_filament_panel_when_conditions_are_met()
public function it_can_access_filament_panel_when_conditions_are_met(): void
{
$adminUser = User::factory()->create([
'email' => 'admin1@zemail.me',
@@ -103,7 +113,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_cannot_access_filament_panel_when_email_does_not_end_with_zemail_me()
public function it_cannot_access_filament_panel_when_email_does_not_end_with_zemail_me(): void
{
$user = User::factory()->create([
'email' => 'user@gmail.com',
@@ -117,7 +127,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_cannot_access_filament_panel_when_level_is_not_9()
public function it_cannot_access_filament_panel_when_level_is_not_9(): void
{
$user = User::factory()->create([
'email' => 'admin2@zemail.me',
@@ -131,7 +141,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_cannot_access_filament_panel_when_email_is_not_verified()
public function it_cannot_access_filament_panel_when_email_is_not_verified(): void
{
$user = User::factory()->create([
'email' => 'admin3@zemail.me',
@@ -145,7 +155,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_has_many_tickets_relationship()
public function it_has_many_tickets_relationship(): void
{
$ticket = Ticket::factory()->create(['user_id' => $this->user->id]);
@@ -154,7 +164,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_has_many_logs_relationship()
public function it_has_many_logs_relationship(): void
{
$log = Log::factory()->create(['user_id' => $this->user->id]);
@@ -163,7 +173,7 @@ class UserTest extends TestCase
}
/** @test */
public function it_has_many_usage_logs_relationship()
public function it_has_many_usage_logs_relationship(): void
{
$usageLog = UsageLog::factory()->create(['user_id' => $this->user->id]);
@@ -172,44 +182,44 @@ class UserTest extends TestCase
}
/** @test */
public function it_uses_required_traits()
public function it_uses_required_traits(): void
{
$traits = class_uses(User::class);
$this->assertArrayHasKey(\Illuminate\Database\Eloquent\Factories\HasFactory::class, $traits);
$this->assertArrayHasKey(\Illuminate\Notifications\Notifiable::class, $traits);
$this->assertArrayHasKey(\Laravel\Cashier\Billable::class, $traits);
$this->assertArrayHasKey(\Laravel\Sanctum\HasApiTokens::class, $traits);
$this->assertArrayHasKey(HasFactory::class, $traits);
$this->assertArrayHasKey(Notifiable::class, $traits);
$this->assertArrayHasKey(Billable::class, $traits);
$this->assertArrayHasKey(HasApiTokens::class, $traits);
}
/** @test */
public function it_implements_required_interfaces()
public function it_implements_required_interfaces(): void
{
$user = new User;
$this->assertInstanceOf(\Filament\Models\Contracts\FilamentUser::class, $user);
$this->assertInstanceOf(\Illuminate\Contracts\Auth\MustVerifyEmail::class, $user);
$this->assertInstanceOf(FilamentUser::class, $user);
$this->assertInstanceOf(MustVerifyEmail::class, $user);
}
/** @test */
public function it_extends_authenticatable()
public function it_extends_authenticatable(): void
{
$this->assertInstanceOf(\Illuminate\Foundation\Auth\User::class, $this->user);
}
/** @test */
public function it_can_create_api_token()
public function it_can_create_api_token(): void
{
$token = $this->user->createToken('test-token');
$this->assertInstanceOf(\Laravel\Sanctum\NewAccessToken::class, $token);
$this->assertInstanceOf(NewAccessToken::class, $token);
$this->assertCount(1, $this->user->tokens);
}
/** @test */
public function it_can_delete_tokens()
public function it_can_delete_tokens(): void
{
$token = $this->user->createToken('test-token');
$this->user->createToken('test-token');
$this->user->tokens()->delete();
$this->assertCount(0, $this->user->fresh()->tokens);

View File

@@ -48,7 +48,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_returns_null_when_no_email_cookie_exists_and_generate_is_false()
public function it_returns_null_when_no_email_cookie_exists_and_generate_is_false(): void
{
$result = ZEmail::getEmail(false);
@@ -56,7 +56,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_email_when_no_cookie_exists_and_generate_is_true()
public function it_generates_random_email_when_no_cookie_exists_and_generate_is_true(): void
{
$result = ZEmail::getEmail(true);
@@ -65,7 +65,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_creates_custom_email_with_valid_username_length()
public function it_creates_custom_email_with_valid_username_length(): void
{
$result = ZEmail::createCustomEmail('validuser', 'example.com');
@@ -73,7 +73,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_username_when_custom_username_is_too_short()
public function it_generates_random_username_when_custom_username_is_too_short(): void
{
$result = ZEmail::createCustomEmail('ab', 'example.com'); // Less than min length 3
@@ -84,7 +84,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_username_when_custom_username_is_too_long()
public function it_generates_random_username_when_custom_username_is_too_long(): void
{
$longUsername = str_repeat('a', 25); // More than max length 20
$result = ZEmail::createCustomEmail($longUsername, 'example.com');
@@ -96,7 +96,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_sanitizes_username_by_removing_special_characters()
public function it_sanitizes_username_by_removing_special_characters(): void
{
$result = ZEmail::createCustomEmail('user!@#$%', 'example.com');
@@ -104,7 +104,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_email_when_forbidden_id_is_used()
public function it_generates_random_email_when_forbidden_id_is_used(): void
{
$result = ZEmail::createCustomEmail('admin', 'example.com');
@@ -113,7 +113,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_gmail_when_empty_username_for_gmail_domain()
public function it_generates_random_gmail_when_empty_username_for_gmail_domain(): void
{
$result = ZEmail::createCustomEmail('', 'gmail.com');
@@ -122,7 +122,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_outlook_when_empty_username_for_outlook_domain()
public function it_generates_random_outlook_when_empty_username_for_outlook_domain(): void
{
$result = ZEmail::createCustomEmail('', 'outlook.com');
@@ -131,7 +131,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_handles_gmail_plus_addressing_correctly()
public function it_handles_gmail_plus_addressing_correctly(): void
{
$result = ZEmail::createCustomEmail('john.doe+tag', 'gmail.com');
@@ -139,7 +139,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_handles_gmail_dot_addressing_correctly()
public function it_handles_gmail_dot_addressing_correctly(): void
{
$result = ZEmail::createCustomEmail('johndoe', 'gmail.com');
@@ -148,7 +148,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_handles_outlook_plus_addressing_correctly()
public function it_handles_outlook_plus_addressing_correctly(): void
{
$result = ZEmail::createCustomEmail('outlookuser+tag', 'outlook.com');
@@ -156,7 +156,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_email_for_unknown_domain()
public function it_generates_random_email_for_unknown_domain(): void
{
$result = ZEmail::createCustomEmail('user', 'unknown.com');
@@ -165,7 +165,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_email_with_store_option()
public function it_generates_random_email_with_store_option(): void
{
$result = ZEmail::generateRandomEmail(true);
@@ -174,7 +174,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_email_without_store_option()
public function it_generates_random_email_without_store_option(): void
{
$result = ZEmail::generateRandomEmail(false);
@@ -183,7 +183,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_gmail_email_with_dots()
public function it_generates_gmail_email_with_dots(): void
{
$result = ZEmail::generateRandomGmail(true);
@@ -192,7 +192,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_outlook_email_with_plus_addressing()
public function it_generates_outlook_email_with_plus_addressing(): void
{
$result = ZEmail::generateRandomOutlook(true);
@@ -201,12 +201,11 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_pronounceable_word()
public function it_generates_pronounceable_word(): void
{
$zemail = new ZEmail;
$reflection = new ReflectionClass($zemail);
$method = $reflection->getMethod('generatePronounceableWord');
$method->setAccessible(true);
$result = $method->invoke($zemail);
@@ -215,12 +214,11 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_generates_random_string_with_specified_length()
public function it_generates_random_string_with_specified_length(): void
{
$zemail = new ZEmail;
$reflection = new ReflectionClass($zemail);
$method = $reflection->getMethod('generateRandomString');
$method->setAccessible(true);
$result = $method->invoke($zemail, 10);
@@ -230,12 +228,11 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_gets_random_domain_from_configuration()
public function it_gets_random_domain_from_configuration(): void
{
$zemail = new ZEmail;
$reflection = new ReflectionClass($zemail);
$method = $reflection->getMethod('getRandomDomain');
$method->setAccessible(true);
$result = $method->invoke($zemail);
@@ -243,12 +240,11 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_gets_random_gmail_user_from_configuration()
public function it_gets_random_gmail_user_from_configuration(): void
{
$zemail = new ZEmail;
$reflection = new ReflectionClass($zemail);
$method = $reflection->getMethod('getRandomGmailUser');
$method->setAccessible(true);
$result = $method->invoke($zemail);
@@ -256,12 +252,11 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_gets_random_outlook_user_from_configuration()
public function it_gets_random_outlook_user_from_configuration(): void
{
$zemail = new ZEmail;
$reflection = new ReflectionClass($zemail);
$method = $reflection->getMethod('getRandomOutlookUser');
$method->setAccessible(true);
$result = $method->invoke($zemail);
@@ -269,7 +264,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_returns_messages_from_message_model_when_beta_feature_is_enabled()
public function it_returns_messages_from_message_model_when_beta_feature_is_enabled(): void
{
Config::set('app.beta_feature', true);
Config::set('app.settings.configuration_settings', json_encode([
@@ -279,7 +274,7 @@ class ZEmailTest extends TestCase
]));
// Create a test message that will be found by getMessages
$message = Message::factory()->create([
Message::factory()->create([
'to' => 'test@example.com',
'subject' => 'Test Subject',
'from' => 'Test Sender <sender@example.com>',
@@ -297,7 +292,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_returns_messages_from_email_model_when_force_db_mail_is_enabled()
public function it_returns_messages_from_email_model_when_force_db_mail_is_enabled(): void
{
Config::set('app.beta_feature', false);
Config::set('app.force_db_mail', true);
@@ -308,7 +303,7 @@ class ZEmailTest extends TestCase
]));
// Create a test email that will be found by parseEmail
$email = Email::factory()->create([
Email::factory()->create([
'to' => ['test@example.com'],
'is_seen' => false,
'message_id' => 'test-123',
@@ -328,7 +323,7 @@ class ZEmailTest extends TestCase
}
/** @test */
public function it_handles_empty_domain_configuration_gracefully()
public function it_handles_empty_domain_configuration_gracefully(): void
{
Config::set('app.settings.configuration_settings', json_encode([
'domains' => [],
@@ -337,7 +332,6 @@ class ZEmailTest extends TestCase
$zemail = new ZEmail;
$reflection = new ReflectionClass($zemail);
$method = $reflection->getMethod('getRandomDomain');
$method->setAccessible(true);
$result = $method->invoke($zemail);

View File

@@ -2,6 +2,7 @@
namespace Tests\Unit;
use Exception;
use App\Http\Controllers\WebhookController;
use App\NotifyMe;
use Illuminate\Support\Facades\Config;
@@ -17,6 +18,7 @@ class TestNotifier
class NotifyMeTest extends TestCase
{
public $notifier;
protected function setUp(): void
{
parent::setUp();
@@ -25,7 +27,7 @@ class NotifyMeTest extends TestCase
}
/** @test */
public function it_sends_telegram_notification_successfully()
public function it_sends_telegram_notification_successfully(): void
{
Config::set('app.notify_tg_bot_token', 'test_bot_token');
Config::set('app.notify_tg_chat_id', 'test_chat_id');
@@ -40,18 +42,16 @@ class NotifyMeTest extends TestCase
$result = $this->notifier->sendTelegramNotification('Test message');
$this->assertTrue($result);
Http::assertSent(function ($request) {
return $request->url() === 'https://api.telegram.org/bottest_bot_token/sendMessage' &&
$request['chat_id'] === 'test_chat_id' &&
$request['text'] === 'Test message' &&
$request['parse_mode'] === 'HTML';
});
Http::assertSent(fn(array $request): bool => $request->url() === 'https://api.telegram.org/bottest_bot_token/sendMessage' &&
$request['chat_id'] === 'test_chat_id' &&
$request['text'] === 'Test message' &&
$request['parse_mode'] === 'HTML');
}
/** @test */
public function it_fails_when_bot_token_is_not_configured()
public function it_fails_when_bot_token_is_not_configured(): void
{
Config::set('app.notify_tg_bot_token', null);
Config::set('app.notify_tg_bot_token');
Config::set('app.notify_tg_chat_id', 'test_chat_id');
Log::shouldReceive('error')
@@ -64,10 +64,10 @@ class NotifyMeTest extends TestCase
}
/** @test */
public function it_fails_when_chat_id_is_not_configured()
public function it_fails_when_chat_id_is_not_configured(): void
{
Config::set('app.notify_tg_bot_token', 'test_bot_token');
Config::set('app.notify_tg_chat_id', null);
Config::set('app.notify_tg_chat_id');
Log::shouldReceive('error')
->once()
@@ -79,7 +79,7 @@ class NotifyMeTest extends TestCase
}
/** @test */
public function it_handles_http_errors_gracefully()
public function it_handles_http_errors_gracefully(): void
{
Config::set('app.notify_tg_bot_token', 'test_bot_token');
Config::set('app.notify_tg_chat_id', 'test_chat_id');
@@ -98,14 +98,14 @@ class NotifyMeTest extends TestCase
}
/** @test */
public function it_handles_network_exceptions()
public function it_handles_network_exceptions(): void
{
Config::set('app.notify_tg_bot_token', 'test_bot_token');
Config::set('app.notify_tg_chat_id', 'test_chat_id');
Http::fake([
'https://api.telegram.org/bottest_bot_token/sendMessage' => Http::throw(function ($request) {
throw new \Exception('Network error');
'https://api.telegram.org/bottest_bot_token/sendMessage' => Http::throw(function ($request): void {
throw new Exception('Network error');
}),
]);
@@ -118,7 +118,7 @@ class NotifyMeTest extends TestCase
}
/** @test */
public function it_sends_messages_with_html_parsing_mode()
public function it_sends_messages_with_html_parsing_mode(): void
{
Config::set('app.notify_tg_bot_token', 'test_bot_token');
Config::set('app.notify_tg_chat_id', 'test_chat_id');
@@ -133,14 +133,12 @@ class NotifyMeTest extends TestCase
$htmlMessage = '<b>Bold text</b> and <i>italic text</i>';
$this->notifier->sendTelegramNotification($htmlMessage);
Http::assertSent(function ($request) use ($htmlMessage) {
return $request['parse_mode'] === 'HTML' &&
$request['text'] === $htmlMessage;
});
Http::assertSent(fn(array $request): bool => $request['parse_mode'] === 'HTML' &&
$request['text'] === $htmlMessage);
}
/** @test */
public function it_can_be_used_in_controller_context()
public function it_can_be_used_in_controller_context(): void
{
Config::set('app.notify_tg_bot_token', 'test_bot_token');
Config::set('app.notify_tg_chat_id', 'test_chat_id');