Courses

Testing in Laravel 11: Advanced Level

Assertion Error Messages

Summary of this lesson:
- Select appropriate assertion methods
- Understand importance of clear error messages
- Avoid using generic assertions
- Compare different assertion approaches

This lesson is a "quick tip" to emphasize that you need to pick the proper assertion to get the correct assertion error.


For example, we have a simple Service for converting currencies.

app/Services/CurrencyService.php:

class CurrencyService
{
const RATES = [
'usd' => [
'eur' => 0.98
],
];
 
public function convert(float $amount, string $currencyFrom, string $currencyTo): float
{
$rate = self::RATES[$currencyFrom][$currencyTo] ?? 0;
 
return round($amount * $rate, 2);
}
}

Then, in the unit test, we expect the...

The full lesson is only for Premium Members.
Want to access all 31 lessons of this course? (74 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord