diff --git a/src/content/daily-email/2023-08-17.md b/src/content/daily-email/2023-08-17.md new file mode 100644 index 00000000..91aadf2e --- /dev/null +++ b/src/content/daily-email/2023-08-17.md @@ -0,0 +1,29 @@ +--- +title: > + Writing custom assertions in your tests +pubDate: 2023-08-17 +permalink: > + archive/2023/08/17/writing-custom-assertions-in-your-tests +tags: + - automated-testing + - test-driven-development +--- + +Writing custom assertions is a great way to clean up your test code. + +Here's an example from one of my client Drupal projects: + +```php +private static function assertProductVariationHasPrice(ProductVariationInterface $productVariation, string $expectedPrice): void { + self::assertSame( + actual: $productVariation->getPrice()->getNumber(), + expected: $expectedPrice, + ); +} +``` + +This one wraps a single assertion, but they could also include multiple assertions or additional steps. + +## Here's the thing + +A custom assertion is a simple function but it makes the test code more readable and less repetitive.