@@ -544,10 +544,12 @@ public static function route() {
544544 */
545545 class WP_UnitTestCase_Base extends PHPUnit \Framework \TestCase {
546546 /**
547- * FrmUnitTest::setUp() replaces this with a FrmUnitTestFactory, which is what every
548- * plugin test actually sees, so it is typed as that rather than the core WP_UnitTest_Factory.
547+ * FrmUnitTest::setUp() actually replaces this with a FrmUnitTestFactory, but that class
548+ * lives under tests/, which phpstan.neon excludes from the analysis paths - PHPStan would
549+ * report "unknown class" for a type it can never load. WP_UnitTest_Factory is the real
550+ * base type and is declared below, so it resolves.
549551 *
550- * @var FrmUnitTestFactory
552+ * @var WP_UnitTest_Factory
551553 */
552554 protected $ factory ;
553555
@@ -560,24 +562,37 @@ class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
560562 */
561563 protected static function stub_check ( $ passed , $ message = '' ) {
562564 if ( ! $ passed ) {
563- throw new Exception ( ( string ) $ message );
565+ throw new Exception ( $ message );
564566 }
565567 }
566568
569+ /**
570+ * The parent parameter is array|ArrayAccess. Any concrete spelling of that PHPStan can
571+ * check - including a fully generic ArrayAccess<mixed,mixed> - reads as narrower than the
572+ * parent's bare, unparameterized ArrayAccess and trips the contravariance rule, so this is
573+ * typed mixed: the widest possible type, trivially at least as wide as the parent's.
574+ *
575+ * @param mixed $key
576+ * @param mixed $array
577+ */
567578 public static function assertArrayHasKey ( $ key , $ array , string $ message = '' ): void {
568579 self ::stub_check ( is_array ( $ array ) && array_key_exists ( $ key , $ array ), $ message );
569580 }
570581
582+ /**
583+ * @param mixed $key
584+ * @param mixed $array
585+ */
571586 public static function assertArrayNotHasKey ( $ key , $ array , string $ message = '' ): void {
572587 self ::stub_check ( ! ( is_array ( $ array ) && array_key_exists ( $ key , $ array ) ), $ message );
573588 }
574589
575590 public static function assertContains ( $ needle , iterable $ haystack , string $ message = '' ): void {
576- self ::stub_check ( in_array ( $ needle , is_array ( $ haystack ) ? $ haystack : iterator_to_array ( $ haystack ), false ), $ message );
591+ self ::stub_check ( in_array ( $ needle , is_array ( $ haystack ) ? $ haystack : iterator_to_array ( $ haystack ), true ), $ message );
577592 }
578593
579594 public static function assertNotContains ( $ needle , iterable $ haystack , string $ message = '' ): void {
580- self ::stub_check ( ! in_array ( $ needle , is_array ( $ haystack ) ? $ haystack : iterator_to_array ( $ haystack ), false ), $ message );
595+ self ::stub_check ( ! in_array ( $ needle , is_array ( $ haystack ) ? $ haystack : iterator_to_array ( $ haystack ), true ), $ message );
581596 }
582597
583598 public static function assertCount ( int $ expected_count , $ haystack , string $ message = '' ): void {
0 commit comments