oliverdavies.uk/content/node.daaf3365-9511-4f12-a744-2a8c37a655b9.json
2025-05-14 00:36:23 +01:00

100 lines
No EOL
5.7 KiB
JSON

{
"uuid": [
{
"value": "daaf3365-9511-4f12-a744-2a8c37a655b9"
}
],
"langcode": [
{
"value": "en"
}
],
"type": [
{
"target_id": "daily_email",
"target_type": "node_type",
"target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7"
}
],
"revision_timestamp": [
{
"value": "2025-05-11T09:00:51+00:00"
}
],
"revision_uid": [
{
"target_type": "user",
"target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849"
}
],
"revision_log": [],
"status": [
{
"value": true
}
],
"uid": [
{
"target_type": "user",
"target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849"
}
],
"title": [
{
"value": "Camel-case or snake-case for test methods?\n"
}
],
"created": [
{
"value": "2022-11-14T00:00:00+00:00"
}
],
"changed": [
{
"value": "2025-05-11T09:00:51+00:00"
}
],
"promote": [
{
"value": false
}
],
"sticky": [
{
"value": false
}
],
"default_langcode": [
{
"value": true
}
],
"revision_translation_affected": [
{
"value": true
}
],
"path": [
{
"alias": "\/daily\/2022\/11\/14\/camel-case-or-snake-case-for-test-methods",
"langcode": "en"
}
],
"body": [
{
"value": "\n <p>When writing object-orientated code, particularly in PHP, you usually write method names using camel-case letters - such as:<\/p>\n\n<pre><code class=\"language-php\">public function doSomething(): void {\n \/\/ ...\n}\n<\/code><\/pre>\n\n<p>This is also true when writing methods within a test class - only that the method name is prefixed with the word <code>test<\/code>:<\/p>\n\n<pre><code class=\"language-php\">public function testSomething(): void {\n}\n<\/code><\/pre>\n\n<p>This is probably expected and complies with the PSR code style standards like PSR-12.<\/p>\n\n<p>Something that I've seen some PHP developers and some frameworks prefer is to write their test methods using snake-case letters and commonly removing the <code>test<\/code> prefix in favour of using an annotation:<\/p>\n\n<pre><code class=\"language-php\">\/** @test *\/\npublic function the_api_should_return_a_200_response_code_if_everything_is_ok(): void {\n \/\/ ...\n}\n<\/code><\/pre>\n\n<p>This is something that I've done myself for a while, but now I'm starting to reconsider both options.<\/p>\n\n<p>Whilst it's more readable, especially for longer test names (which I like to write), it's not consistent with method names in non-test files or non-test methods in test files; it looks odd if I need to add another annotation (do I keep a single annotation on one line, or just those with multiple annotations on the separate lines), and to do this, I need to disable some code sniffer rules for code to pass the PHPCS checks.<\/p>\n\n<p>If I used camel-cased names, I wouldn't need the PHPCS overrides, the annotations would be simpler, and the code would be more consistent - so I think I'll try that way again in the next tests that I write and see how it feels.<\/p>\n\n<p>Which do you prefer, and which would you expect to see in your project?<\/p>\n\n ",
"format": "full_html",
"processed": "\n <p>When writing object-orientated code, particularly in PHP, you usually write method names using camel-case letters - such as:<\/p>\n\n<pre><code class=\"language-php\">public function doSomething(): void {\n \/\/ ...\n}\n<\/code><\/pre>\n\n<p>This is also true when writing methods within a test class - only that the method name is prefixed with the word <code>test<\/code>:<\/p>\n\n<pre><code class=\"language-php\">public function testSomething(): void {\n}\n<\/code><\/pre>\n\n<p>This is probably expected and complies with the PSR code style standards like PSR-12.<\/p>\n\n<p>Something that I've seen some PHP developers and some frameworks prefer is to write their test methods using snake-case letters and commonly removing the <code>test<\/code> prefix in favour of using an annotation:<\/p>\n\n<pre><code class=\"language-php\">\/** @test *\/\npublic function the_api_should_return_a_200_response_code_if_everything_is_ok(): void {\n \/\/ ...\n}\n<\/code><\/pre>\n\n<p>This is something that I've done myself for a while, but now I'm starting to reconsider both options.<\/p>\n\n<p>Whilst it's more readable, especially for longer test names (which I like to write), it's not consistent with method names in non-test files or non-test methods in test files; it looks odd if I need to add another annotation (do I keep a single annotation on one line, or just those with multiple annotations on the separate lines), and to do this, I need to disable some code sniffer rules for code to pass the PHPCS checks.<\/p>\n\n<p>If I used camel-cased names, I wouldn't need the PHPCS overrides, the annotations would be simpler, and the code would be more consistent - so I think I'll try that way again in the next tests that I write and see how it feels.<\/p>\n\n<p>Which do you prefer, and which would you expect to see in your project?<\/p>\n\n ",
"summary": null
}
],
"feeds_item": [
{
"imported": "1970-01-01T00:33:45+00:00",
"guid": null,
"hash": "142789ac0ec97b452b470ffc7dfb962c",
"target_type": "feeds_feed",
"target_uuid": "90c85284-7ca8-4074-9178-97ff8384fe76"
}
]
}