uuid: - value: 49f2d11b-a2fd-4f79-930d-a0d97fd0c7fc 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:24+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: | Should you run static analysis on your tests? created: - value: '2023-12-18T00:00:00+00:00' changed: - value: '2025-05-11T09:00:24+00:00' promote: - value: false sticky: - value: false default_langcode: - value: true revision_translation_affected: - value: true path: - alias: /daily/2023/12/18/static-analysis-on-tests langcode: en body: - value: |

I'm an advocate of both automated testing and static analysis but have mostly kept the two separate.

I've typically not run PHPStan on my automated test files - ignoring them in my PHPStan configuration.

As tests aren't production/implementation code, what's the benefit of analysing them?

Recently, though, I've challenged this and, on some projects, started to run PHPStan on my test classes.

Depending on what level PHPStan is running, the more changes you're likely to have to make to get your test classes to pass the static analysis, and whilst it results in more verbose and explicit code, I prefer that and being able to easily understand what it does rather than implicit.

If you have a bug in your test, static analysis will potentially find that, too, making your test suite more robust.

Looking at some large open-source PHP projects, they run static analysis on their test code.

Presumably, they're benefiting from it, so I'll try it and see if I get the same.

format: full_html processed: |

I'm an advocate of both automated testing and static analysis but have mostly kept the two separate.

I've typically not run PHPStan on my automated test files - ignoring them in my PHPStan configuration.

As tests aren't production/implementation code, what's the benefit of analysing them?

Recently, though, I've challenged this and, on some projects, started to run PHPStan on my test classes.

Depending on what level PHPStan is running, the more changes you're likely to have to make to get your test classes to pass the static analysis, and whilst it results in more verbose and explicit code, I prefer that and being able to easily understand what it does rather than implicit.

If you have a bug in your test, static analysis will potentially find that, too, making your test suite more robust.

Looking at some large open-source PHP projects, they run static analysis on their test code.

Presumably, they're benefiting from it, so I'll try it and see if I get the same.

summary: null field_daily_email_cta: { }