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:
59
tests/Unit/Models/MenuTest.php
Normal file
59
tests/Unit/Models/MenuTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user