create(); $this->assertDatabaseHas('rides', [ 'id' => $ride->id, 'name' => $ride->name, ]); } /** * Test model factory. */ public function test_ride_factory_works(): void { $ride = Ride::factory()->create(); $this->assertInstanceOf(Ride::class, $ride); $this->assertNotEmpty($ride->name); $this->assertIsBool($ride->is_active); } /** * Test active scope. */ public function test_active_scope_filters_correctly(): void { Ride::factory()->active()->create(); Ride::factory()->inactive()->create(); $activeCount = Ride::active()->count(); $totalCount = Ride::count(); $this->assertEquals(1, $activeCount); $this->assertEquals(2, $totalCount); } /** * Test cache key generation. */ public function test_cache_key_generation(): void { $ride = Ride::factory()->create(); $cacheKey = $ride->getCacheKey(); $expectedKey = strtolower('ride') . '.' . $ride->id; $this->assertEquals($expectedKey, $cacheKey); } /** * Test cache key with suffix. */ public function test_cache_key_with_suffix(): void { $ride = Ride::factory()->create(); $cacheKey = $ride->getCacheKey('details'); $expectedKey = strtolower('ride') . '.' . $ride->id . '.details'; $this->assertEquals($expectedKey, $cacheKey); } /** * Test soft deletes. */ public function test_soft_deletes_work(): void { $ride = Ride::factory()->create(); $ride->delete(); $this->assertSoftDeleted($ride); // Test that it's excluded from normal queries $this->assertEquals(0, Ride::count()); // Test that it's included in withTrashed queries $this->assertEquals(1, Ride::withTrashed()->count()); } }