Suggest assertCount() over assertSame(n, count(...))

Open
#186 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

A pull request for this has already been merged.

  • #198 by @alies-dev — merged

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
php
Domain
testing

Research direction

Read the plugin’s existing checks for assertSame(null|true|false, ...) and the referenced AssertSameWithCountRule in phpstan-phpunit. The issue proposes adding detection in afterMethodCallAnalysis for assertSame/assertEquals with count() or Countable::count() as the second argument, using the shared helper. Add tests for the new issue and confirm they cover both count forms.

Written by the indexing model from the issue text.

Description

enhancement

$this->assertSame(3, count($lines)) is clearer as $this->assertCount(3, $lines), and the failure message shows the collection.

phpstan-phpunit reports it (AssertSameWithCountRule).

Idea: in afterMethodCallAnalysis, detect assertSame/assertEquals whose second argument is a count() call (or ->count() on a Countable) and emit a plugin issue. It shares the helper with the assertSame(null|true|false, ...) checks. Roughly 55 lines with tests.

Idea borrowed from phpstan/phpstan-phpunit.

Dominant language
Gherkin
Stars
79
Forks
38
Avg merge
6h 52m
Merged PRs (30d)
28

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from psalm/psalm-plugin-phpunit

All issues in psalm/psalm-plugin-phpunit

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.