From feb93810bc8cbe80c9bbf973decf824f928297a0 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 24 Oct 2024 12:43:32 +0100 Subject: [PATCH] Add daily email for 2024-10-22 How would you write this test name? --- source/_daily_emails/2024-10-22.md | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 source/_daily_emails/2024-10-22.md diff --git a/source/_daily_emails/2024-10-22.md b/source/_daily_emails/2024-10-22.md new file mode 100644 index 000000000..c91794c32 --- /dev/null +++ b/source/_daily_emails/2024-10-22.md @@ -0,0 +1,50 @@ +--- +title: How would you write this test name? +date: 2024-10-22 +permalink: daily/2024/10/22/how-would-you-write-this-test-name +tags: + - software-development + - php + - phpunit + - automated-testing + - test-driven-development +cta: ~ +snippet: | + How would you write this test name? +--- + +There are multiple ways I've seen people write their test method names. + +This is the standard PSR-compliant camel-case method name: + +```php +public function testSomethingHappensWhenYouGoToThePage() +``` + +Some people find long camel-case names hard to read and prefer to use snake-case names: + +```php +public function test_something_happens_when_you_go_to_the_page() +``` + +This still works as the method name still starts with the word `test`, but you'd need to add some overrides to phpcs for it not to complain about using snake-case words. + +Another option is to remove the `test` prefix and use an annotation: + +```php +/** @test */ +public function something_happens_when_you_go_to_the_page() +``` + +And in newer PHPUnit versions, you can also use an attribute: + +```php +#[Test] +public function something_happens_when_you_go_to_the_page() +``` + +Whilst this makes the method name shorter, you need to add an additional line before each test method for the annotation or attribute. + +Each has pros and cons, and people have their own preferences. + +Which do you do?