chore: code refactor via rector
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
test('that true is true', function () {
|
||||
test('that true is true', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user