Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

assertNotContains appears to be messing something up.

オープン
#262 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
php
領域
testing

調査の方向性

Start with the shortened OmegaTag and testBasic examples in the issue, focusing on the interaction between assertNotContains() and the later assertCount() call. Compare the analysis with and without assertNotContains(); done when the collection is no longer inferred as NEVER and the impossibleType warning is resolved.

索引モデルが issue の本文から書いたものです。

説明

I've got a weird issue that I can't seem to figure out. I think it is a bug in PHPStan, but I'm not certain.
I appreciate if you can point me in a way on how to debug this or help you figure out what is wrong.

Some context first:

  • popped up after upgrading PHPStan yesterday, it was not there before. I update very often, so it was a recent change.
  • Happens on both PHP8.4 and PHP8.5alpha
  • It involves the PHPUnit method "assetNotContains", so I don't think I can create a playground example.
  • I tried creating a small repo with an example, but I can't reproduce the error there. I'm not sure why. I used the same phpstan.neon file (just paths changed) and the contents of the classes appear identical to me (except namespaces).

Given this (a bit shortened) test class:

class OmegaTag
{
    /**
     * @var Collection<array-key, OmegaProduct>
     */
    private Collection $products;

    public function __construct()
    {
        $this->products = new ArrayCollection();
    }

    /**
     * @return Collection<array-key, OmegaProduct>
     */
    public function getProducts(): Collection
    {
        return $this->products;
    }
}

This (shortened) test:

    public function testBasic(): void
    {
        $product = new OmegaProduct();
        $tag = new OmegaTag();

        self::assertNotContains($product, $tag->getProducts());
        self::assertCount(0, $tag->getProducts());
    }

This gives me this error:

Call to static method PHPUnit\Framework\Assert::assertCount() with 0 and *NEVER* will always evaluate to false.                                   
🪪  staticMethod.impossibleType

I'm not sure how PHPStan got to the type *NEVER*.

Observations:

  • When I remove the line with the method assertNotContains, the error goes away.
  • When I refactor the 2 $tag->getProducts() calls to a single variable and use that in the test, the error is still there.

It seems that assertNotContains narrows the type to never, while I think it should not do that.

Is there any direction you can point me in to find out what is wrong here?
Or is there any more info I can give if you think this is a bug?

主要言語
PHP
スター
544
フォーク
58
平均マージ
2日 1時間
マージ済み PR(30日)
5

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

phpstan/phpstan-phpunit のほかの issue

phpstan/phpstan-phpunit の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。