fix: resolve PSR-4 autoloading and test failures

- Add proper Tests\ namespace to all test classes in tests/Feature and tests/Unit
  - Split RemainingModelsTest.php into separate files (PSR-4 compliance)
  - Create missing factories: MetaFactory, RemoteEmailFactory
  - Add HasFactory trait to RemoteEmail model
  - Add missing ReflectionClass imports to test files
  - Fix mass assignment issues in Meta and RemoteEmail models
  - Override database connection for RemoteEmail in testing environment
  - Fix DateTime comparison precision issues in tests
This commit is contained in:
idevakk
2025-11-13 09:49:21 -08:00
parent 68ef391c5d
commit 3706072ce5
38 changed files with 863 additions and 680 deletions

View File

@@ -19,7 +19,8 @@
"Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_displays_tickets_in_table\" --no-coverage)", "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_displays_tickets_in_table\" --no-coverage)",
"Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_search_tickets_by_subject\" --no-coverage)", "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_search_tickets_by_subject\" --no-coverage)",
"Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_create_new_plan\" --no-coverage)", "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_create_new_plan\" --no-coverage)",
"Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_create_new_category\" --no-coverage)" "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_create_new_category\" --no-coverage)",
"Bash(vendor/bin/pest tests/Unit/Models/RemoteEmailTest.php --no-coverage)"
], ],
"deny": [], "deny": [],
"ask": [] "ask": []

View File

@@ -8,6 +8,11 @@ use Illuminate\Database\Eloquent\Model;
class Meta extends Model { class Meta extends Model {
use HasFactory; use HasFactory;
protected $fillable = [
'key',
'value',
];
public function incrementMeta($value = 1) { public function incrementMeta($value = 1) {
$this->value = $this->value + $value; $this->value = $this->value + $value;
$this->save(); $this->save();

View File

@@ -2,14 +2,43 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
class RemoteEmail extends Model class RemoteEmail extends Model
{ {
protected $connection = 'mysql_remote'; use HasFactory;
protected $table = 'emails'; protected $table = 'emails';
public function getConnectionName()
{
if (app()->environment('testing')) {
return config('database.default');
}
return 'mysql_remote';
}
protected $fillable = [
'message_id',
'subject',
'from_name',
'from_email',
'to',
'body_html',
'body_text',
'is_seen',
'timestamp',
];
protected $casts = [
'to' => 'array',
'is_seen' => 'boolean',
'timestamp' => 'datetime',
];
public static function fetchEmailFromDB($email) public static function fetchEmailFromDB($email)
{ {
$validator = Validator::make(['email' => $email], [ $validator = Validator::make(['email' => $email], [

104
composer.lock generated
View File

@@ -2038,16 +2038,16 @@
}, },
{ {
"name": "kirschbaum-development/eloquent-power-joins", "name": "kirschbaum-development/eloquent-power-joins",
"version": "4.2.9", "version": "4.2.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/kirschbaum-development/eloquent-power-joins.git", "url": "https://github.com/kirschbaum-development/eloquent-power-joins.git",
"reference": "32ec75ffee5f8f66e2c95e4030fa0b2454e51048" "reference": "ccda351a75701f5b0a6f94586d9a40f1114302b4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/kirschbaum-development/eloquent-power-joins/zipball/32ec75ffee5f8f66e2c95e4030fa0b2454e51048", "url": "https://api.github.com/repos/kirschbaum-development/eloquent-power-joins/zipball/ccda351a75701f5b0a6f94586d9a40f1114302b4",
"reference": "32ec75ffee5f8f66e2c95e4030fa0b2454e51048", "reference": "ccda351a75701f5b0a6f94586d9a40f1114302b4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -2095,9 +2095,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/kirschbaum-development/eloquent-power-joins/issues", "issues": "https://github.com/kirschbaum-development/eloquent-power-joins/issues",
"source": "https://github.com/kirschbaum-development/eloquent-power-joins/tree/4.2.9" "source": "https://github.com/kirschbaum-development/eloquent-power-joins/tree/4.2.10"
}, },
"time": "2025-10-25T11:39:00+00:00" "time": "2025-11-13T14:57:49+00:00"
}, },
{ {
"name": "laravel/cashier", "name": "laravel/cashier",
@@ -2189,16 +2189,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v12.37.0", "version": "v12.38.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "3c3c4ad30f5b528b164a7c09aa4ad03118c4c125" "reference": "7f3012af6059f5f64a12930701cd8caed6cf7c17"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/3c3c4ad30f5b528b164a7c09aa4ad03118c4c125", "url": "https://api.github.com/repos/laravel/framework/zipball/7f3012af6059f5f64a12930701cd8caed6cf7c17",
"reference": "3c3c4ad30f5b528b164a7c09aa4ad03118c4c125", "reference": "7f3012af6059f5f64a12930701cd8caed6cf7c17",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -2316,7 +2316,7 @@
"phpstan/phpstan": "^2.0", "phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^10.5.35|^11.5.3|^12.0.1", "phpunit/phpunit": "^10.5.35|^11.5.3|^12.0.1",
"predis/predis": "^2.3|^3.0", "predis/predis": "^2.3|^3.0",
"resend/resend-php": "^0.10.0", "resend/resend-php": "^0.10.0|^1.0",
"symfony/cache": "^7.2.0", "symfony/cache": "^7.2.0",
"symfony/http-client": "^7.2.0", "symfony/http-client": "^7.2.0",
"symfony/psr-http-message-bridge": "^7.2.0", "symfony/psr-http-message-bridge": "^7.2.0",
@@ -2350,7 +2350,7 @@
"predis/predis": "Required to use the predis connector (^2.3|^3.0).", "predis/predis": "Required to use the predis connector (^2.3|^3.0).",
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).", "psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^6.0|^7.0).", "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^6.0|^7.0).",
"resend/resend-php": "Required to enable support for the Resend mail transport (^0.10.0).", "resend/resend-php": "Required to enable support for the Resend mail transport (^0.10.0|^1.0).",
"symfony/cache": "Required to PSR-6 cache bridge (^7.2).", "symfony/cache": "Required to PSR-6 cache bridge (^7.2).",
"symfony/filesystem": "Required to enable support for relative symbolic links (^7.2).", "symfony/filesystem": "Required to enable support for relative symbolic links (^7.2).",
"symfony/http-client": "Required to enable support for the Symfony API mail transports (^7.2).", "symfony/http-client": "Required to enable support for the Symfony API mail transports (^7.2).",
@@ -2404,7 +2404,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2025-11-04T15:39:33+00:00" "time": "2025-11-13T02:12:47+00:00"
}, },
{ {
"name": "laravel/prompts", "name": "laravel/prompts",
@@ -2938,16 +2938,16 @@
}, },
{ {
"name": "league/flysystem", "name": "league/flysystem",
"version": "3.30.1", "version": "3.30.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/flysystem.git", "url": "https://github.com/thephpleague/flysystem.git",
"reference": "c139fd65c1f796b926f4aec0df37f6caa959a8da" "reference": "5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/c139fd65c1f796b926f4aec0df37f6caa959a8da", "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277",
"reference": "c139fd65c1f796b926f4aec0df37f6caa959a8da", "reference": "5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -3015,22 +3015,22 @@
], ],
"support": { "support": {
"issues": "https://github.com/thephpleague/flysystem/issues", "issues": "https://github.com/thephpleague/flysystem/issues",
"source": "https://github.com/thephpleague/flysystem/tree/3.30.1" "source": "https://github.com/thephpleague/flysystem/tree/3.30.2"
}, },
"time": "2025-10-20T15:35:26+00:00" "time": "2025-11-10T17:13:11+00:00"
}, },
{ {
"name": "league/flysystem-local", "name": "league/flysystem-local",
"version": "3.30.0", "version": "3.30.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/flysystem-local.git", "url": "https://github.com/thephpleague/flysystem-local.git",
"reference": "6691915f77c7fb69adfb87dcd550052dc184ee10" "reference": "ab4f9d0d672f601b102936aa728801dd1a11968d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/6691915f77c7fb69adfb87dcd550052dc184ee10", "url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/ab4f9d0d672f601b102936aa728801dd1a11968d",
"reference": "6691915f77c7fb69adfb87dcd550052dc184ee10", "reference": "ab4f9d0d672f601b102936aa728801dd1a11968d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -3064,9 +3064,9 @@
"local" "local"
], ],
"support": { "support": {
"source": "https://github.com/thephpleague/flysystem-local/tree/3.30.0" "source": "https://github.com/thephpleague/flysystem-local/tree/3.30.2"
}, },
"time": "2025-05-21T10:34:19+00:00" "time": "2025-11-10T11:23:37+00:00"
}, },
{ {
"name": "league/mime-type-detection", "name": "league/mime-type-detection",
@@ -6094,16 +6094,16 @@
}, },
{ {
"name": "symfony/http-foundation", "name": "symfony/http-foundation",
"version": "v7.3.6", "version": "v7.3.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-foundation.git", "url": "https://github.com/symfony/http-foundation.git",
"reference": "6379e490d6ecfc5c4224ff3a754b90495ecd135c" "reference": "db488a62f98f7a81d5746f05eea63a74e55bb7c4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/6379e490d6ecfc5c4224ff3a754b90495ecd135c", "url": "https://api.github.com/repos/symfony/http-foundation/zipball/db488a62f98f7a81d5746f05eea63a74e55bb7c4",
"reference": "6379e490d6ecfc5c4224ff3a754b90495ecd135c", "reference": "db488a62f98f7a81d5746f05eea63a74e55bb7c4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -6153,7 +6153,7 @@
"description": "Defines an object-oriented layer for the HTTP specification", "description": "Defines an object-oriented layer for the HTTP specification",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/http-foundation/tree/v7.3.6" "source": "https://github.com/symfony/http-foundation/tree/v7.3.7"
}, },
"funding": [ "funding": [
{ {
@@ -6173,20 +6173,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2025-11-06T11:05:57+00:00" "time": "2025-11-08T16:41:12+00:00"
}, },
{ {
"name": "symfony/http-kernel", "name": "symfony/http-kernel",
"version": "v7.3.6", "version": "v7.3.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-kernel.git", "url": "https://github.com/symfony/http-kernel.git",
"reference": "f9a34dc0196677250e3609c2fac9de9e1551a262" "reference": "10b8e9b748ea95fa4539c208e2487c435d3c87ce"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/f9a34dc0196677250e3609c2fac9de9e1551a262", "url": "https://api.github.com/repos/symfony/http-kernel/zipball/10b8e9b748ea95fa4539c208e2487c435d3c87ce",
"reference": "f9a34dc0196677250e3609c2fac9de9e1551a262", "reference": "10b8e9b748ea95fa4539c208e2487c435d3c87ce",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -6271,7 +6271,7 @@
"description": "Provides a structured process for converting a Request into a Response", "description": "Provides a structured process for converting a Request into a Response",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/http-kernel/tree/v7.3.6" "source": "https://github.com/symfony/http-kernel/tree/v7.3.7"
}, },
"funding": [ "funding": [
{ {
@@ -6291,7 +6291,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2025-11-06T20:58:12+00:00" "time": "2025-11-12T11:38:40+00:00"
}, },
{ {
"name": "symfony/mailer", "name": "symfony/mailer",
@@ -8753,16 +8753,16 @@
}, },
{ {
"name": "laravel/boost", "name": "laravel/boost",
"version": "v1.7.1", "version": "v1.8.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/boost.git", "url": "https://github.com/laravel/boost.git",
"reference": "355f7c27952862aab3f61adec27773fd4d41a582" "reference": "3475be16be7552b11c57ce18a0c5e204d696da50"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/boost/zipball/355f7c27952862aab3f61adec27773fd4d41a582", "url": "https://api.github.com/repos/laravel/boost/zipball/3475be16be7552b11c57ce18a0c5e204d696da50",
"reference": "355f7c27952862aab3f61adec27773fd4d41a582", "reference": "3475be16be7552b11c57ce18a0c5e204d696da50",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -8815,20 +8815,20 @@
"issues": "https://github.com/laravel/boost/issues", "issues": "https://github.com/laravel/boost/issues",
"source": "https://github.com/laravel/boost" "source": "https://github.com/laravel/boost"
}, },
"time": "2025-11-05T21:41:46+00:00" "time": "2025-11-11T14:15:11+00:00"
}, },
{ {
"name": "laravel/mcp", "name": "laravel/mcp",
"version": "v0.3.2", "version": "v0.3.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/mcp.git", "url": "https://github.com/laravel/mcp.git",
"reference": "dc722a4c388f172365dec70461f0413ac366f360" "reference": "feb475f819809e7db0a46e9f2cbcee6d77af2a14"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/mcp/zipball/dc722a4c388f172365dec70461f0413ac366f360", "url": "https://api.github.com/repos/laravel/mcp/zipball/feb475f819809e7db0a46e9f2cbcee6d77af2a14",
"reference": "dc722a4c388f172365dec70461f0413ac366f360", "reference": "feb475f819809e7db0a46e9f2cbcee6d77af2a14",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -8888,7 +8888,7 @@
"issues": "https://github.com/laravel/mcp/issues", "issues": "https://github.com/laravel/mcp/issues",
"source": "https://github.com/laravel/mcp" "source": "https://github.com/laravel/mcp"
}, },
"time": "2025-10-29T14:26:01+00:00" "time": "2025-11-11T22:50:25+00:00"
}, },
{ {
"name": "laravel/pail", "name": "laravel/pail",
@@ -9098,16 +9098,16 @@
}, },
{ {
"name": "laravel/sail", "name": "laravel/sail",
"version": "v1.47.0", "version": "v1.48.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/sail.git", "url": "https://github.com/laravel/sail.git",
"reference": "9a11e822238167ad8b791e4ea51155d25cf4d8f2" "reference": "1bf3b8870b72a258a3b6b5119435835ece522e8a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/sail/zipball/9a11e822238167ad8b791e4ea51155d25cf4d8f2", "url": "https://api.github.com/repos/laravel/sail/zipball/1bf3b8870b72a258a3b6b5119435835ece522e8a",
"reference": "9a11e822238167ad8b791e4ea51155d25cf4d8f2", "reference": "1bf3b8870b72a258a3b6b5119435835ece522e8a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -9157,7 +9157,7 @@
"issues": "https://github.com/laravel/sail/issues", "issues": "https://github.com/laravel/sail/issues",
"source": "https://github.com/laravel/sail" "source": "https://github.com/laravel/sail"
}, },
"time": "2025-10-28T13:55:29+00:00" "time": "2025-11-09T14:46:21+00:00"
}, },
{ {
"name": "mockery/mockery", "name": "mockery/mockery",

View File

@@ -0,0 +1,19 @@
<?php
namespace Database\Factories;
use App\Models\Meta;
use Illuminate\Database\Eloquent\Factories\Factory;
class MetaFactory extends Factory
{
protected $model = Meta::class;
public function definition(): array
{
return [
'key' => $this->faker->word(),
'value' => $this->faker->word(),
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Database\Factories;
use App\Models\RemoteEmail;
use Illuminate\Database\Eloquent\Factories\Factory;
class RemoteEmailFactory extends Factory
{
protected $model = RemoteEmail::class;
public function definition(): array
{
return [
'message_id' => $this->faker->uuid(),
'subject' => $this->faker->sentence(),
'from_name' => $this->faker->name(),
'from_email' => $this->faker->email(),
'to' => [$this->faker->email()],
'body_html' => '<p>' . $this->faker->paragraph() . '</p>',
'body_text' => $this->faker->paragraph(),
'is_seen' => $this->faker->boolean(),
'timestamp' => $this->faker->dateTime(),
];
}
}

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature;
// Simple test to check if Laravel application is working // Simple test to check if Laravel application is working
use Tests\TestCase; use Tests\TestCase;

View File

@@ -1,7 +1,10 @@
<?php <?php
namespace Tests\Feature\Controllers;
use App\Http\Controllers\AppController; use App\Http\Controllers\AppController;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use ReflectionClass;
use Tests\TestCase; use Tests\TestCase;
class AppControllerTest extends TestCase class AppControllerTest extends TestCase

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature\Controllers;
use App\Http\Controllers\WebhookController; use App\Http\Controllers\WebhookController;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature;
use Tests\TestCase; use Tests\TestCase;
use Tests\Concerns\LoadsApplicationData; use Tests\Concerns\LoadsApplicationData;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature\Filament;
use App\Filament\Resources\BlogResource; use App\Filament\Resources\BlogResource;
use App\Filament\Resources\BlogResource\Pages\CreateBlog; use App\Filament\Resources\BlogResource\Pages\CreateBlog;
use App\Filament\Resources\PlanResource; use App\Filament\Resources\PlanResource;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature\Filament;
use App\Filament\Resources\UserResource; use App\Filament\Resources\UserResource;
use App\Filament\Resources\UserResource\Pages\CreateUser; use App\Filament\Resources\UserResource\Pages\CreateUser;
use App\Filament\Resources\UserResource\Pages\EditUser; use App\Filament\Resources\UserResource\Pages\EditUser;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature\Livewire\Auth;
use App\Livewire\Auth\Login; use App\Livewire\Auth\Login;
use App\Models\User; use App\Models\User;
use Illuminate\Auth\Events\Lockout; use Illuminate\Auth\Events\Lockout;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature\Livewire\Auth;
use App\Livewire\Auth\Register; use App\Livewire\Auth\Register;
use App\Models\User; use App\Models\User;
use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Events\Registered;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature\Livewire;
use App\Models\Plan; use App\Models\Plan;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Feature\Livewire;
use App\Models\Email; use App\Models\Email;
use App\Models\ZEmail; use App\Models\ZEmail;
use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Facades\Cookie;

View File

@@ -1,7 +1,10 @@
<?php <?php
namespace Tests\Unit;
use App\ColorPicker; use App\ColorPicker;
use App\Models\Email; use App\Models\Email;
use ReflectionClass;
use Tests\TestCase; use Tests\TestCase;
// Create a test class that uses the trait // Create a test class that uses the trait

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Unit;
test('that true is true', function () { test('that true is true', function () {
expect(true)->toBeTrue(); expect(true)->toBeTrue();
}); });

View File

@@ -0,0 +1,75 @@
<?php
namespace Tests\Unit\Models;
use App\Models\ActivationKey;
use App\Models\User;
use Tests\TestCase;
class ActivationKeyTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
/** @test */
public function it_can_create_an_activation_key_with_factory()
{
$activationKey = ActivationKey::factory()->create();
$this->assertInstanceOf(ActivationKey::class, $activationKey);
$this->assertIsString($activationKey->activation_key);
$this->assertIsInt($activationKey->price_id);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$activationKeyData = [
'user_id' => $this->user->id,
'activation_key' => 'ACTIVATION-KEY-123456',
'price_id' => 1,
'is_activated' => false,
];
$activationKey = ActivationKey::create($activationKeyData);
foreach ($activationKeyData as $key => $value) {
$this->assertEquals($value, $activationKey->$key);
}
}
/** @test */
public function it_belongs_to_a_user()
{
$activationKey = ActivationKey::factory()->create(['user_id' => $this->user->id]);
$this->assertInstanceOf(User::class, $activationKey->user);
$this->assertEquals($this->user->id, $activationKey->user->id);
}
/** @test */
public function it_generates_unique_keys()
{
$key1 = ActivationKey::factory()->create();
$key2 = ActivationKey::factory()->create();
$this->assertNotEquals($key1->activation_key, $key2->activation_key);
}
/** @test */
public function it_can_query_unactivated_activation_keys()
{
$unactivatedKey = ActivationKey::factory()->create(['is_activated' => false]);
$activatedKey = ActivationKey::factory()->create(['is_activated' => true]);
$unactivatedKeys = ActivationKey::where('is_activated', false)->get();
$activatedKeys = ActivationKey::where('is_activated', true)->get();
$this->assertCount(1, $unactivatedKeys);
$this->assertCount(1, $activatedKeys);
}
}

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Unit\Models;
use App\Models\Blog; use App\Models\Blog;
use App\Models\Category; use App\Models\Category;
use App\Models\User; use App\Models\User;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Unit\Models;
use App\Models\Blog; use App\Models\Blog;
use App\Models\Category; use App\Models\Category;
use Tests\TestCase; use Tests\TestCase;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Unit\Models;
use App\Models\Email; use App\Models\Email;
use App\Models\RemoteEmail; use App\Models\RemoteEmail;
use Carbon\Carbon; use Carbon\Carbon;

View File

@@ -0,0 +1,75 @@
<?php
namespace Tests\Unit\Models;
use App\Models\Log;
use App\Models\User;
use Tests\TestCase;
class LogTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
/** @test */
public function it_can_create_a_log_with_factory()
{
$log = Log::factory()->create();
$this->assertInstanceOf(Log::class, $log);
$this->assertIsString($log->email);
$this->assertIsString($log->ip);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$logData = [
'user_id' => $this->user->id,
'email' => 'test@example.com',
'ip' => '192.168.1.1',
];
$log = Log::create($logData);
foreach ($logData as $key => $value) {
$this->assertEquals($value, $log->$key);
}
}
/** @test */
public function it_belongs_to_a_user()
{
$log = Log::factory()->create(['user_id' => $this->user->id]);
$this->assertInstanceOf(User::class, $log->user);
$this->assertEquals($this->user->id, $log->user->id);
}
/** @test */
public function it_stores_ip_addresses_correctly()
{
$ipAddresses = ['127.0.0.1', '192.168.1.100', '10.0.0.1'];
foreach ($ipAddresses as $ip) {
$log = Log::factory()->create(['ip' => $ip]);
$this->assertEquals($ip, $log->ip);
}
}
/** @test */
public function it_orders_logs_by_creation_date()
{
$oldLog = Log::factory()->create(['created_at' => now()->subHours(2)]);
$newLog = Log::factory()->create(['created_at' => now()]);
$logs = Log::orderBy('created_at', 'desc')->get();
$this->assertEquals($newLog->id, $logs->first()->id);
$this->assertEquals($oldLog->id, $logs->last()->id);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Tests\Unit\Models;
use App\Models\Menu;
use Tests\TestCase;
class MenuTest extends TestCase
{
/** @test */
public function it_can_create_a_menu_with_factory()
{
$menu = Menu::factory()->create();
$this->assertInstanceOf(Menu::class, $menu);
$this->assertIsString($menu->name);
$this->assertIsString($menu->url);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$menuData = [
'name' => 'Home',
'url' => '/home',
'new_tab' => false,
'parent' => null,
];
$menu = Menu::create($menuData);
foreach ($menuData as $key => $value) {
$this->assertEquals($value, $menu->$key);
}
}
/** @test */
public function it_orders_menus_by_name()
{
$menu1 = Menu::factory()->create(['name' => 'Zebra']);
$menu2 = Menu::factory()->create(['name' => 'Alpha']);
$menu3 = Menu::factory()->create(['name' => 'Beta']);
$menus = Menu::orderBy('name')->get();
$this->assertEquals($menu2->id, $menus[0]->id);
$this->assertEquals($menu3->id, $menus[1]->id);
$this->assertEquals($menu1->id, $menus[2]->id);
}
/** @test */
public function it_can_handle_parent_child_relationships()
{
$parentMenu = Menu::factory()->create(['parent' => null]);
$childMenu = Menu::factory()->create(['parent' => 'home']);
$this->assertEquals('home', $childMenu->parent);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Tests\Unit\Models;
use App\Models\Message;
use Carbon\Carbon;
use Tests\TestCase;
class MessageTest extends TestCase
{
/** @test */
public function it_can_create_a_message_with_factory()
{
$message = Message::factory()->create();
$this->assertInstanceOf(Message::class, $message);
$this->assertIsString($message->subject);
$this->assertIsString($message->from);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$messageData = [
'subject' => 'Test Message',
'from' => 'Test Sender <sender@example.com>',
'to' => 'recipient@example.com',
'body' => 'Test body content',
'attachments' => null,
'is_seen' => false,
];
$message = Message::create($messageData);
foreach ($messageData as $key => $value) {
$this->assertEquals($value, $message->$key);
}
}
/** @test */
public function it_stores_to_field_as_string()
{
$to = 'test1@example.com';
$message = Message::factory()->create(['to' => $to]);
$this->assertIsString($message->to);
$this->assertEquals($to, $message->to);
}
/** @test */
public function it_uses_created_at_as_timestamp()
{
$message = Message::factory()->create();
$this->assertInstanceOf(Carbon::class, $message->created_at);
$this->assertNotNull($message->created_at);
}
/** @test */
public function it_can_query_unseen_messages()
{
$unseenMessage = Message::factory()->create(['is_seen' => false]);
$seenMessage = Message::factory()->create(['is_seen' => true]);
$unseenMessages = Message::where('is_seen', false)->get();
$seenMessages = Message::where('is_seen', true)->get();
$this->assertCount(1, $unseenMessages);
$this->assertCount(1, $seenMessages);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Tests\Unit\Models;
use App\Models\Meta;
use Tests\TestCase;
class MetaTest extends TestCase
{
/** @test */
public function it_can_create_a_meta_with_factory()
{
$meta = Meta::factory()->create();
$this->assertInstanceOf(Meta::class, $meta);
$this->assertIsString($meta->key);
$this->assertIsString($meta->value);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$metaData = [
'key' => 'total_emails_created',
'value' => '1500',
];
$meta = Meta::create($metaData);
foreach ($metaData as $key => $value) {
$this->assertEquals($value, $meta->$key);
}
}
/** @test */
public function it_stores_key_value_pairs_correctly()
{
$meta = Meta::factory()->create([
'key' => 'app_version',
'value' => '1.2.3',
]);
$this->assertEquals('app_version', $meta->key);
$this->assertEquals('1.2.3', $meta->value);
}
/** @test */
public function it_can_retrieve_value_by_key()
{
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();
$this->assertEquals('ZEmailnator', $siteName->value);
$this->assertEquals('100', $maxEmails->value);
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Tests\Unit\Models;
use App\Models\Page;
use Tests\TestCase;
class PageTest extends TestCase
{
/** @test */
public function it_can_create_a_page_with_factory()
{
$page = Page::factory()->create();
$this->assertInstanceOf(Page::class, $page);
$this->assertIsString($page->title);
$this->assertIsString($page->slug);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$pageData = [
'title' => 'About Us',
'slug' => 'about-us',
'content' => 'About us page content',
'meta' => [
'description' => 'About us meta description',
'keywords' => 'about,company',
],
'is_published' => true,
];
$page = Page::create($pageData);
foreach ($pageData as $key => $value) {
$this->assertEquals($value, $page->$key);
}
}
/** @test */
public function it_generates_unique_slugs()
{
$page1 = Page::factory()->create(['title' => 'Same Title']);
$page2 = Page::factory()->create(['title' => 'Same Title']);
$this->assertNotEquals($page1->slug, $page2->slug);
}
/** @test */
public function it_can_query_published_pages()
{
$publishedPage = Page::factory()->create(['is_published' => true]);
$draftPage = Page::factory()->create(['is_published' => false]);
$publishedPages = Page::where('is_published', true)->get();
$draftPages = Page::where('is_published', false)->get();
$this->assertCount(1, $publishedPages);
$this->assertCount(1, $draftPages);
}
}

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Unit\Models;
use App\Models\Plan; use App\Models\Plan;
use Tests\TestCase; use Tests\TestCase;

View File

@@ -0,0 +1,79 @@
<?php
namespace Tests\Unit\Models;
use App\Models\PremiumEmail;
use App\Models\User;
use Carbon\Carbon;
use Tests\TestCase;
class PremiumEmailTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
/** @test */
public function it_can_create_a_premium_email_with_factory()
{
$premiumEmail = PremiumEmail::factory()->create();
$this->assertInstanceOf(PremiumEmail::class, $premiumEmail);
$this->assertIsString($premiumEmail->from_email);
$this->assertIsString($premiumEmail->subject);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$premiumEmailData = [
'user_id' => $this->user->id,
'message_id' => 'test_msg_123',
'from_email' => 'sender@example.com',
'from_name' => 'Test Sender',
'subject' => 'Test Subject',
'to' => ['recipient@example.com'],
];
$premiumEmail = PremiumEmail::create($premiumEmailData);
foreach ($premiumEmailData as $key => $value) {
$this->assertEquals($value, $premiumEmail->$key);
}
}
/** @test */
public function it_belongs_to_a_user()
{
$premiumEmail = PremiumEmail::factory()->create(['user_id' => $this->user->id]);
$this->assertInstanceOf(User::class, $premiumEmail->user);
$this->assertEquals($this->user->id, $premiumEmail->user->id);
}
/** @test */
public function it_casts_timestamp_to_datetime()
{
$timestamp = now()->subDays(5);
$premiumEmail = PremiumEmail::factory()->create(['timestamp' => $timestamp]);
$this->assertInstanceOf(Carbon::class, $premiumEmail->timestamp);
$this->assertEquals($timestamp->format('Y-m-d H:i:s'), $premiumEmail->timestamp->format('Y-m-d H:i:s'));
}
/** @test */
public function it_can_query_seen_and_unseen_emails()
{
$seenEmail = PremiumEmail::factory()->create(['is_seen' => true]);
$unseenEmail = PremiumEmail::factory()->create(['is_seen' => false]);
$seenEmails = PremiumEmail::where('is_seen', true)->get();
$unseenEmails = PremiumEmail::where('is_seen', false)->get();
$this->assertCount(1, $seenEmails);
$this->assertCount(1, $unseenEmails);
}
}

View File

@@ -1,625 +0,0 @@
<?php
use App\Models\ActivationKey;
use App\Models\Log;
use App\Models\Menu;
use App\Models\Message;
use App\Models\Meta;
use App\Models\Page;
use App\Models\PremiumEmail;
use App\Models\RemoteEmail;
use App\Models\Setting;
use App\Models\UsageLog;
use App\Models\User;
use Carbon\Carbon;
use Tests\TestCase;
class PageTest extends TestCase
{
/** @test */
public function it_can_create_a_page_with_factory()
{
$page = Page::factory()->create();
$this->assertInstanceOf(Page::class, $page);
$this->assertIsString($page->title);
$this->assertIsString($page->slug);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$pageData = [
'title' => 'About Us',
'slug' => 'about-us',
'content' => 'About us page content',
'meta' => [
'description' => 'About us meta description',
'keywords' => 'about,company',
],
'is_published' => true,
];
$page = Page::create($pageData);
foreach ($pageData as $key => $value) {
$this->assertEquals($value, $page->$key);
}
}
/** @test */
public function it_generates_unique_slugs()
{
$page1 = Page::factory()->create(['title' => 'Same Title']);
$page2 = Page::factory()->create(['title' => 'Same Title']);
$this->assertNotEquals($page1->slug, $page2->slug);
}
/** @test */
public function it_can_query_published_pages()
{
$publishedPage = Page::factory()->create(['is_published' => true]);
$draftPage = Page::factory()->create(['is_published' => false]);
$publishedPages = Page::where('is_published', true)->get();
$draftPages = Page::where('is_published', false)->get();
$this->assertCount(1, $publishedPages);
$this->assertCount(1, $draftPages);
}
}
class MenuTest extends TestCase
{
/** @test */
public function it_can_create_a_menu_with_factory()
{
$menu = Menu::factory()->create();
$this->assertInstanceOf(Menu::class, $menu);
$this->assertIsString($menu->name);
$this->assertIsString($menu->url);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$menuData = [
'name' => 'Home',
'url' => '/home',
'new_tab' => false,
'parent' => null,
];
$menu = Menu::create($menuData);
foreach ($menuData as $key => $value) {
$this->assertEquals($value, $menu->$key);
}
}
/** @test */
public function it_orders_menus_by_name()
{
$menu1 = Menu::factory()->create(['name' => 'Zebra']);
$menu2 = Menu::factory()->create(['name' => 'Alpha']);
$menu3 = Menu::factory()->create(['name' => 'Beta']);
$menus = Menu::orderBy('name')->get();
$this->assertEquals($menu2->id, $menus[0]->id);
$this->assertEquals($menu3->id, $menus[1]->id);
$this->assertEquals($menu1->id, $menus[2]->id);
}
/** @test */
public function it_can_handle_parent_child_relationships()
{
$parentMenu = Menu::factory()->create(['parent' => null]);
$childMenu = Menu::factory()->create(['parent' => 'home']);
$this->assertEquals('home', $childMenu->parent);
}
}
class LogTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
/** @test */
public function it_can_create_a_log_with_factory()
{
$log = Log::factory()->create();
$this->assertInstanceOf(Log::class, $log);
$this->assertIsString($log->email);
$this->assertIsString($log->ip);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$logData = [
'user_id' => $this->user->id,
'email' => 'test@example.com',
'ip' => '192.168.1.1',
];
$log = Log::create($logData);
foreach ($logData as $key => $value) {
$this->assertEquals($value, $log->$key);
}
}
/** @test */
public function it_belongs_to_a_user()
{
$log = Log::factory()->create(['user_id' => $this->user->id]);
$this->assertInstanceOf(User::class, $log->user);
$this->assertEquals($this->user->id, $log->user->id);
}
/** @test */
public function it_stores_ip_addresses_correctly()
{
$ipAddresses = ['127.0.0.1', '192.168.1.100', '10.0.0.1'];
foreach ($ipAddresses as $ip) {
$log = Log::factory()->create(['ip' => $ip]);
$this->assertEquals($ip, $log->ip);
}
}
/** @test */
public function it_orders_logs_by_creation_date()
{
$oldLog = Log::factory()->create(['created_at' => now()->subHours(2)]);
$newLog = Log::factory()->create(['created_at' => now()]);
$logs = Log::orderBy('created_at', 'desc')->get();
$this->assertEquals($newLog->id, $logs->first()->id);
$this->assertEquals($oldLog->id, $logs->last()->id);
}
}
class UsageLogTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
/** @test */
public function it_can_create_a_usage_log_with_factory()
{
$usageLog = UsageLog::factory()->create();
$this->assertInstanceOf(UsageLog::class, $usageLog);
$this->assertIsInt($usageLog->emails_created_count);
$this->assertIsInt($usageLog->emails_received_count);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$usageLogData = [
'user_id' => $this->user->id,
'ip_address' => '192.168.1.1',
'emails_created_count' => 5,
'emails_received_count' => 10,
'emails_created_history' => json_encode(['2023-01-01 12:00:00' => 3]),
'emails_received_history' => json_encode(['2023-01-01 12:30:00' => 7]),
];
$usageLog = UsageLog::create($usageLogData);
foreach ($usageLogData as $key => $value) {
$this->assertEquals($value, $usageLog->$key);
}
}
/** @test */
public function it_belongs_to_a_user()
{
$usageLog = UsageLog::factory()->create(['user_id' => $this->user->id]);
$this->assertInstanceOf(User::class, $usageLog->user);
$this->assertEquals($this->user->id, $usageLog->user->id);
}
/** @test */
public function it_tracks_different_email_counts()
{
$usageLog = UsageLog::factory()->create([
'emails_created_count' => 15,
'emails_received_count' => 25,
]);
$this->assertEquals(15, $usageLog->emails_created_count);
$this->assertEquals(25, $usageLog->emails_received_count);
}
}
class MetaTest extends TestCase
{
/** @test */
public function it_can_create_a_meta_with_factory()
{
$meta = Meta::factory()->create();
$this->assertInstanceOf(Meta::class, $meta);
$this->assertIsString($meta->key);
$this->assertIsString($meta->value);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$metaData = [
'key' => 'total_emails_created',
'value' => '1500',
'type' => 'counter',
];
$meta = Meta::create($metaData);
foreach ($metaData as $key => $value) {
$this->assertEquals($value, $meta->$key);
}
}
/** @test */
public function it_stores_key_value_pairs_correctly()
{
$meta = Meta::factory()->create([
'key' => 'app_version',
'value' => '1.2.3',
]);
$this->assertEquals('app_version', $meta->key);
$this->assertEquals('1.2.3', $meta->value);
}
/** @test */
public function it_can_retrieve_value_by_key()
{
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();
$this->assertEquals('ZEmailnator', $siteName->value);
$this->assertEquals('100', $maxEmails->value);
}
}
class PremiumEmailTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
/** @test */
public function it_can_create_a_premium_email_with_factory()
{
$premiumEmail = PremiumEmail::factory()->create();
$this->assertInstanceOf(PremiumEmail::class, $premiumEmail);
$this->assertIsString($premiumEmail->from_email);
$this->assertIsString($premiumEmail->subject);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$premiumEmailData = [
'user_id' => $this->user->id,
'message_id' => 'test_msg_123',
'from_email' => 'sender@example.com',
'from_name' => 'Test Sender',
'subject' => 'Test Subject',
'to' => ['recipient@example.com'],
];
$premiumEmail = PremiumEmail::create($premiumEmailData);
foreach ($premiumEmailData as $key => $value) {
$this->assertEquals($value, $premiumEmail->$key);
}
}
/** @test */
public function it_belongs_to_a_user()
{
$premiumEmail = PremiumEmail::factory()->create(['user_id' => $this->user->id]);
$this->assertInstanceOf(User::class, $premiumEmail->user);
$this->assertEquals($this->user->id, $premiumEmail->user->id);
}
/** @test */
public function it_casts_timestamp_to_datetime()
{
$timestamp = now()->subDays(5);
$premiumEmail = PremiumEmail::factory()->create(['timestamp' => $timestamp]);
$this->assertInstanceOf(Carbon::class, $premiumEmail->timestamp);
$this->assertEquals($timestamp->format('Y-m-d H:i:s'), $premiumEmail->timestamp->format('Y-m-d H:i:s'));
}
/** @test */
public function it_can_query_seen_and_unseen_emails()
{
$seenEmail = PremiumEmail::factory()->create(['is_seen' => true]);
$unseenEmail = PremiumEmail::factory()->create(['is_seen' => false]);
$seenEmails = PremiumEmail::where('is_seen', true)->get();
$unseenEmails = PremiumEmail::where('is_seen', false)->get();
$this->assertCount(1, $seenEmails);
$this->assertCount(1, $unseenEmails);
}
}
class RemoteEmailTest extends TestCase
{
/** @test */
public function it_can_create_a_remote_email_with_factory()
{
$remoteEmail = RemoteEmail::factory()->create();
$this->assertInstanceOf(RemoteEmail::class, $remoteEmail);
$this->assertIsArray($remoteEmail->to);
$this->assertIsString($remoteEmail->from_email);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$remoteEmailData = [
'message_id' => 'remote_123',
'subject' => 'Remote Email Subject',
'from_name' => 'Remote Sender',
'from_email' => 'remote@example.com',
'to' => ['recipient@example.com'],
'body_html' => '<p>HTML content</p>',
'body_text' => 'Text content',
'is_seen' => false,
'timestamp' => now(),
];
$remoteEmail = RemoteEmail::create($remoteEmailData);
foreach ($remoteEmailData as $key => $value) {
$this->assertEquals($value, $remoteEmail->$key);
}
}
/** @test */
public function it_casts_to_field_to_array()
{
$to = ['test1@example.com', 'test2@example.com'];
$remoteEmail = RemoteEmail::factory()->create(['to' => $to]);
$this->assertIsArray($remoteEmail->to);
$this->assertEquals($to, $remoteEmail->to);
}
/** @test */
public function it_casts_timestamp_to_datetime()
{
$timestamp = now();
$remoteEmail = RemoteEmail::factory()->create(['timestamp' => $timestamp]);
$this->assertInstanceOf(Carbon::class, $remoteEmail->timestamp);
$this->assertEquals($timestamp, $remoteEmail->timestamp);
}
}
class ActivationKeyTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
/** @test */
public function it_can_create_an_activation_key_with_factory()
{
$activationKey = ActivationKey::factory()->create();
$this->assertInstanceOf(ActivationKey::class, $activationKey);
$this->assertIsString($activationKey->activation_key);
$this->assertIsInt($activationKey->price_id);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$activationKeyData = [
'user_id' => $this->user->id,
'activation_key' => 'ACTIVATION-KEY-123456',
'price_id' => 1,
'is_activated' => false,
];
$activationKey = ActivationKey::create($activationKeyData);
foreach ($activationKeyData as $key => $value) {
$this->assertEquals($value, $activationKey->$key);
}
}
/** @test */
public function it_belongs_to_a_user()
{
$activationKey = ActivationKey::factory()->create(['user_id' => $this->user->id]);
$this->assertInstanceOf(User::class, $activationKey->user);
$this->assertEquals($this->user->id, $activationKey->user->id);
}
/** @test */
public function it_generates_unique_keys()
{
$key1 = ActivationKey::factory()->create();
$key2 = ActivationKey::factory()->create();
$this->assertNotEquals($key1->activation_key, $key2->activation_key);
}
/** @test */
public function it_can_query_unactivated_activation_keys()
{
$unactivatedKey = ActivationKey::factory()->create(['is_activated' => false]);
$activatedKey = ActivationKey::factory()->create(['is_activated' => true]);
$unactivatedKeys = ActivationKey::where('is_activated', false)->get();
$activatedKeys = ActivationKey::where('is_activated', true)->get();
$this->assertCount(1, $unactivatedKeys);
$this->assertCount(1, $activatedKeys);
}
}
class SettingTest extends TestCase
{
/** @test */
public function it_can_create_a_setting_with_factory()
{
$setting = Setting::factory()->create();
$this->assertInstanceOf(Setting::class, $setting);
$this->assertIsString($setting->app_name);
$this->assertIsString($setting->app_version);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$settingData = [
'app_name' => 'ZEmailnator',
'app_version' => '1.0.0',
'app_base_url' => 'https://example.com',
'app_admin' => 'admin@example.com',
'app_title' => 'Test Title',
];
$setting = Setting::create($settingData);
foreach ($settingData as $key => $value) {
$this->assertEquals($value, $setting->$key);
}
}
/** @test */
public function it_stores_configuration_values()
{
$setting = Setting::factory()->create([
'app_name' => 'Test App',
'configuration_settings' => json_encode([
'max_emails_per_user' => 100,
'enable_registrations' => true,
'default_language' => 'en',
]),
]);
$this->assertEquals('Test App', $setting->app_name);
$this->assertIsString($setting->configuration_settings);
$config = json_decode($setting->configuration_settings, true);
$this->assertEquals(100, $config['max_emails_per_user']);
}
/** @test */
public function it_can_query_public_settings()
{
$setting1 = Setting::factory()->create(['app_name' => 'Public App']);
$setting2 = Setting::factory()->create(['app_name' => 'Private App']);
$allSettings = Setting::all();
$this->assertCount(2, $allSettings);
$this->assertIsString($allSettings->first()->app_name);
}
}
class MessageTest extends TestCase
{
/** @test */
public function it_can_create_a_message_with_factory()
{
$message = Message::factory()->create();
$this->assertInstanceOf(Message::class, $message);
$this->assertIsString($message->subject);
$this->assertIsString($message->from);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$messageData = [
'subject' => 'Test Message',
'from' => 'Test Sender <sender@example.com>',
'to' => 'recipient@example.com',
'body' => 'Test body content',
'attachments' => null,
'is_seen' => false,
];
$message = Message::create($messageData);
foreach ($messageData as $key => $value) {
$this->assertEquals($value, $message->$key);
}
}
/** @test */
public function it_stores_to_field_as_string()
{
$to = 'test1@example.com';
$message = Message::factory()->create(['to' => $to]);
$this->assertIsString($message->to);
$this->assertEquals($to, $message->to);
}
/** @test */
public function it_uses_created_at_as_timestamp()
{
$message = Message::factory()->create();
$this->assertInstanceOf(Carbon::class, $message->created_at);
$this->assertNotNull($message->created_at);
}
/** @test */
public function it_can_query_unseen_messages()
{
$unseenMessage = Message::factory()->create(['is_seen' => false]);
$seenMessage = Message::factory()->create(['is_seen' => true]);
$unseenMessages = Message::where('is_seen', false)->get();
$seenMessages = Message::where('is_seen', true)->get();
$this->assertCount(1, $unseenMessages);
$this->assertCount(1, $seenMessages);
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace Tests\Unit\Models;
use App\Models\RemoteEmail;
use Carbon\Carbon;
use Tests\TestCase;
class RemoteEmailTest extends TestCase
{
/** @test */
public function it_can_create_a_remote_email_with_factory()
{
$remoteEmail = RemoteEmail::factory()->create();
$this->assertInstanceOf(RemoteEmail::class, $remoteEmail);
$this->assertIsArray($remoteEmail->to);
$this->assertIsString($remoteEmail->from_email);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$timestamp = now();
$remoteEmailData = [
'message_id' => 'remote_123',
'subject' => 'Remote Email Subject',
'from_name' => 'Remote Sender',
'from_email' => 'remote@example.com',
'to' => ['recipient@example.com'],
'body_html' => '<p>HTML content</p>',
'body_text' => 'Text content',
'is_seen' => false,
'timestamp' => $timestamp,
];
$remoteEmail = RemoteEmail::create($remoteEmailData);
foreach ($remoteEmailData as $key => $value) {
if ($key === 'timestamp') {
$this->assertInstanceOf(Carbon::class, $remoteEmail->$key);
$this->assertEquals($timestamp->format('Y-m-d H:i:s'), $remoteEmail->$key->format('Y-m-d H:i:s'));
} else {
$this->assertEquals($value, $remoteEmail->$key);
}
}
}
/** @test */
public function it_casts_to_field_to_array()
{
$to = ['test1@example.com', 'test2@example.com'];
$remoteEmail = RemoteEmail::factory()->create(['to' => $to]);
$this->assertIsArray($remoteEmail->to);
$this->assertEquals($to, $remoteEmail->to);
}
/** @test */
public function it_casts_timestamp_to_datetime()
{
$timestamp = now();
$remoteEmail = RemoteEmail::factory()->create(['timestamp' => $timestamp]);
$this->assertInstanceOf(Carbon::class, $remoteEmail->timestamp);
$this->assertEquals($timestamp->format('Y-m-d H:i:s'), $remoteEmail->timestamp->format('Y-m-d H:i:s'));
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Tests\Unit\Models;
use App\Models\Setting;
use Tests\TestCase;
class SettingTest extends TestCase
{
/** @test */
public function it_can_create_a_setting_with_factory()
{
$setting = Setting::factory()->create();
$this->assertInstanceOf(Setting::class, $setting);
$this->assertIsString($setting->app_name);
$this->assertIsString($setting->app_version);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$settingData = [
'app_name' => 'ZEmailnator',
'app_version' => '1.0.0',
'app_base_url' => 'https://example.com',
'app_admin' => 'admin@example.com',
'app_title' => 'Test Title',
];
$setting = Setting::create($settingData);
foreach ($settingData as $key => $value) {
$this->assertEquals($value, $setting->$key);
}
}
/** @test */
public function it_stores_configuration_values()
{
$setting = Setting::factory()->create([
'app_name' => 'Test App',
'configuration_settings' => json_encode([
'max_emails_per_user' => 100,
'enable_registrations' => true,
'default_language' => 'en',
]),
]);
$this->assertEquals('Test App', $setting->app_name);
$this->assertIsString($setting->configuration_settings);
$config = json_decode($setting->configuration_settings, true);
$this->assertEquals(100, $config['max_emails_per_user']);
}
/** @test */
public function it_can_query_public_settings()
{
$setting1 = Setting::factory()->create(['app_name' => 'Public App']);
$setting2 = Setting::factory()->create(['app_name' => 'Private App']);
$allSettings = Setting::all();
$this->assertCount(2, $allSettings);
$this->assertIsString($allSettings->first()->app_name);
}
}

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Unit\Models;
use App\Models\Ticket; use App\Models\Ticket;
use App\Models\TicketResponse; use App\Models\TicketResponse;
use App\Models\User; use App\Models\User;

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Unit\Models;
use App\Models\Ticket; use App\Models\Ticket;
use App\Models\TicketResponse; use App\Models\TicketResponse;
use App\Models\User; use App\Models\User;

View File

@@ -0,0 +1,67 @@
<?php
namespace Tests\Unit\Models;
use App\Models\UsageLog;
use App\Models\User;
use Tests\TestCase;
class UsageLogTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
/** @test */
public function it_can_create_a_usage_log_with_factory()
{
$usageLog = UsageLog::factory()->create();
$this->assertInstanceOf(UsageLog::class, $usageLog);
$this->assertIsInt($usageLog->emails_created_count);
$this->assertIsInt($usageLog->emails_received_count);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$usageLogData = [
'user_id' => $this->user->id,
'ip_address' => '192.168.1.1',
'emails_created_count' => 5,
'emails_received_count' => 10,
'emails_created_history' => json_encode(['2023-01-01 12:00:00' => 3]),
'emails_received_history' => json_encode(['2023-01-01 12:30:00' => 7]),
];
$usageLog = UsageLog::create($usageLogData);
foreach ($usageLogData as $key => $value) {
$this->assertEquals($value, $usageLog->$key);
}
}
/** @test */
public function it_belongs_to_a_user()
{
$usageLog = UsageLog::factory()->create(['user_id' => $this->user->id]);
$this->assertInstanceOf(User::class, $usageLog->user);
$this->assertEquals($this->user->id, $usageLog->user->id);
}
/** @test */
public function it_tracks_different_email_counts()
{
$usageLog = UsageLog::factory()->create([
'emails_created_count' => 15,
'emails_received_count' => 25,
]);
$this->assertEquals(15, $usageLog->emails_created_count);
$this->assertEquals(25, $usageLog->emails_received_count);
}
}

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace Tests\Unit\Models;
use App\Models\Log; use App\Models\Log;
use App\Models\Ticket; use App\Models\Ticket;
use App\Models\UsageLog; use App\Models\UsageLog;

View File

@@ -1,10 +1,13 @@
<?php <?php
namespace Tests\Unit\Models;
use App\Models\Email; use App\Models\Email;
use App\Models\Message; use App\Models\Message;
use App\Models\ZEmail; use App\Models\ZEmail;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Facades\Cookie;
use ReflectionClass;
use Tests\TestCase; use Tests\TestCase;
class ZEmailTest extends TestCase class ZEmailTest extends TestCase

View File

@@ -1,6 +1,9 @@
<?php <?php
namespace Tests\Unit;
use App\Http\Controllers\WebhookController; use App\Http\Controllers\WebhookController;
use App\NotifyMe;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@@ -9,7 +12,7 @@ use Tests\TestCase;
// Create a test class that uses the trait // Create a test class that uses the trait
class TestNotifier class TestNotifier
{ {
use App\NotifyMe; use NotifyMe;
} }
class NotifyMeTest extends TestCase class NotifyMeTest extends TestCase