1.3.16 throwing errors on arrays after assertCount

Open
#206 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
testing

Research direction

Start by comparing the 1.3.15 and 1.3.16 changes linked in the report, then reproduce the interaction between assertCount(), reset(), and the array offset access shown. Done means the valid pattern no longer reports that the result may be false, with a regression test covering the example.

Written by the indexing model from the issue text.

Description

Our automated updates updated to 1.3.16 today and started failing phpstan. Based on the changes from 1.3.15 it's obvious what the issue is.

Our tests do something like this:

    $mails = $this->getMails();
    $this->assertCount(1, $mails);
    $mail = \reset($mails);
    $this->assertStringContainsString('foo', $mail['subject']);

Where getMails returns an array.

And this is throwing errors like Cannot access offset 'subject' on false.

Dominant language
PHP
Stars
544
Forks
58
Avg merge
2d 1h
Merged PRs (30d)
5

Contributor guide

No contributing guide indexed for this repository

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 phpstan/phpstan-phpunit

All issues in phpstan/phpstan-phpunit

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.