Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

StatementWithoutSideEffectsRule with expected exception shouldn't raise error

Open
#86 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start with the provided PHPUnit reproducer and inspect the StatementWithoutSideEffectsRule behavior for iterator_to_array(). Confirm that the call still reports a diagnostic in production code but not when PHPUnit expects the thrown RuntimeException; done means the example passes without the false-positive error.

Written by the indexing model from the issue text.

Description

final class MyTest extends \PHPUnit\Framework\TestCase
{
    public function testMe(): void
    {
        $foo = new class([1]) extends ArrayIterator {
            public function current(): void
            {
                throw new RuntimeException('foo');
            }
        };
        
        $this->expectException(\RuntimeException::class);

        iterator_to_array($foo);
    }
}

This code reports Call to function iterator_to_array() on a separate line has no effect., but while it's ok on production code (like in https://phpstan.org/r/ee6218f3-4d37-4b5a-9a85-bc6d6ab44d2b) , with PHPUnit is legit as for expectException expectation.

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.