Skip to content

Commit

Permalink
Part 7. Success regression tests with UndefinedMixinClass
Browse files Browse the repository at this point in the history
  • Loading branch information
issidorov committed Sep 12, 2024
1 parent b206f1a commit 021c77b
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/MixinAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,14 @@ public function providerInvalidCodeParse(): iterable
{
return [
'undefinedMixinClass' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/** @mixin B */
class A {}',
'error_message' => 'UndefinedDocblockClass',
],
'undefinedMixinClassWithPropertyFetch' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/** @mixin B */
class A {}
Expand All @@ -617,6 +619,7 @@ class A {}
'error_message' => 'UndefinedPropertyFetch',
],
'undefinedMixinClassWithPropertyFetch_WithMagicMethod' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/**
* @property string $baz
Expand All @@ -632,6 +635,7 @@ public function __get(string $name): string {
'error_message' => 'UndefinedMagicPropertyFetch',
],
'undefinedMixinClassWithPropertyAssignment' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/** @mixin B */
class A {}
Expand All @@ -640,6 +644,7 @@ class A {}
'error_message' => 'UndefinedPropertyAssignment',
],
'undefinedMixinClassWithPropertyAssignment_WithMagicMethod' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/**
* @property string $baz
Expand All @@ -653,6 +658,7 @@ public function __set(string $name, string $value) {}
'error_message' => 'UndefinedMagicPropertyAssignment',
],
'undefinedMixinClassWithMethodCall' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/** @mixin B */
class A {}
Expand All @@ -661,6 +667,7 @@ class A {}
'error_message' => 'UndefinedMethod',
],
'undefinedMixinClassWithMethodCall_WithMagicMethod' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/**
* @method baz()
Expand All @@ -674,6 +681,7 @@ public function __call(string $name, array $arguments) {}
'error_message' => 'UndefinedMagicMethod',
],
'undefinedMixinClassWithStaticMethodCall' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/** @mixin B */
class A {}
Expand All @@ -682,6 +690,7 @@ class A {}
'error_message' => 'UndefinedMethod',
],
'undefinedMixinClassWithStaticMethodCall_WithMagicMethod' => [
// Similar test in MixinsDeepTest.php
'code' => '<?php
/**
* @method baz()
Expand Down
151 changes: 151 additions & 0 deletions tests/MixinsDeepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace Psalm\Tests;

use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\InvalidCodeAnalysisWithIssuesTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;

class MixinsDeepTest extends TestCase
{
use InvalidCodeAnalysisWithIssuesTestTrait;
use ValidCodeAnalysisTestTrait;
use InvalidCodeAnalysisTestTrait;

public function providerValidCodeParse(): iterable
{
Expand Down Expand Up @@ -494,4 +498,151 @@ public function __get(string $name) {}
],
];
}

public function providerInvalidCodeParse(): iterable
{
return [
'undefinedMixinClass' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/** @mixin B */
class A {}
/** @mixin C */
class B {}',
'error_message' => 'UndefinedDocblockClass',
],
'undefinedMixinClassWithPropertyFetch' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/** @mixin B */
class A {}
/** @mixin C */
class B {}
(new A)->foo;',
'error_message' => 'UndefinedPropertyFetch',
],
'undefinedMixinClassWithPropertyFetch_WithMagicMethod' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/**
* @property string $baz
* @mixin B
*/
class A {
public function __get(string $name): string {
return "";
}
}
/**
* @property string $bar
* @mixin C
*/
class B {
public function __get(string $name): string {
return "";
}
}
(new A)->foo;',
'error_message' => 'UndefinedMagicPropertyFetch',
],
'undefinedMixinClassWithPropertyAssignment' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/** @mixin B */
class A {}
/** @mixin C */
class B {}
(new A)->foo = "bar";',
'error_message' => 'UndefinedPropertyAssignment',
],
'undefinedMixinClassWithPropertyAssignment_WithMagicMethod' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/**
* @property string $baz
* @mixin B
*/
class A {
public function __set(string $name, string $value) {}
}
/**
* @property string $bar
* @mixin C
*/
class B {
public function __set(string $name, string $value) {}
}
(new A)->foo = "bar";',
'error_message' => 'UndefinedMagicPropertyAssignment',
],
'undefinedMixinClassWithMethodCall' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/** @mixin B */
class A {}
/** @mixin C */
class B {}
(new A)->foo();',
'error_message' => 'UndefinedMethod',
],
'undefinedMixinClassWithMethodCall_WithMagicMethod' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/**
* @method baz()
* @mixin B
*/
class A {
public function __call(string $name, array $arguments) {}
}
/**
* @method bar()
* @mixin C
*/
class B {
public function __call(string $name, array $arguments) {}
}
(new A)->foo();',
'error_message' => 'UndefinedMagicMethod',
],
'undefinedMixinClassWithStaticMethodCall' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/** @mixin B */
class A {}
/** @mixin C */
class B {}
A::foo();',
'error_message' => 'UndefinedMethod',
],
'undefinedMixinClassWithStaticMethodCall_WithMagicMethod' => [
// Similar test in MixinAnnotationTest.php
'code' => '<?php
/**
* @method baz()
* @mixin B
*/
class A {
public static function __callStatic(string $name, array $arguments) {}
}
/**
* @method bar()
* @mixin C
*/
class B {
public static function __callStatic(string $name, array $arguments) {}
}
A::foo();',
'error_message' => 'UndefinedMagicMethod',
],
];
}
}

0 comments on commit 021c77b

Please sign in to comment.