Generally, there's a thought that you should not test the framework itself because many tests inside Laravel already cover its features.
However, you may test some features to ensure they work correctly with your data set. A typical example is testing Eloquent Observers or Accessors/Mutators, checking the data before and after them. It could be Unit or Feature tests.
For example, you have an Attribute for the price
field to save the price in cents by multiplying by 100.
app/Models/Product.php:
use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Casts\Attribute;use Illuminate\Database\Eloquent\Factories\HasFactory; class Product extends Model{ use HasFactory; protected $fillable = [ 'name', 'price', 'published_at', ]; protected function price(): Attribute { return Attribute::make( set: fn ($value) => $value * 100, ); } }
The Unit test for this example could be like this:
use App\Models\Product; test('product price set successfully', function () { $product = new Product([ 'name' => 'Product 1', 'price' => 1.23, ]); expect($product->price) ->toEqual(123);});
This is a typical Unit test for the Eloquent model, which means you create the Model and then change its behavior in the background.
For example, with the Observer, Accessor/Mutator, and Events/Listeners, you assert that the actual value of the Eloquent object is different than what you initially set.