1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Move Override tests to separate file

This commit is contained in:
Evan Shaw 2024-02-04 15:30:36 +13:00
parent 7d07e258a3
commit c71ad2221c
2 changed files with 111 additions and 85 deletions

View File

@ -293,36 +293,6 @@ class AttributeTest extends TestCase
'ignored_issues' => [], 'ignored_issues' => [],
'php_version' => '8.2', 'php_version' => '8.2',
], ],
'override' => [
'code' => '<?php
class C {
public function f(): void {}
}
class C2 extends C {
#[Override]
public function f(): void {}
}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
'overrideInterface' => [
'code' => '<?php
interface I {
public function f(): void;
}
interface I2 extends I {
#[Override]
public function f(): void;
}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
'sensitiveParameter' => [ 'sensitiveParameter' => [
'code' => '<?php 'code' => '<?php
@ -541,61 +511,6 @@ class AttributeTest extends TestCase
function foo(#[Pure] string $str) : void {}', function foo(#[Pure] string $str) : void {}',
'error_message' => 'UndefinedAttributeClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:4:36', 'error_message' => 'UndefinedAttributeClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:4:36',
], ],
'overrideWithNoParent' => [
'code' => '<?php
class C {
#[Override]
public function f(): void {}
}
',
'error_message' => 'InvalidOverride - src' . DIRECTORY_SEPARATOR . 'somefile.php:3:25',
'error_levels' => [],
'php_version' => '8.3',
],
'overrideConstructor' => [
'code' => '<?php
/**
* @psalm-consistent-constructor
*/
class C {
public function __construct() {}
}
class C2 extends C {
#[Override]
public function __construct() {}
}
',
'error_message' => 'InvalidOverride - src' . DIRECTORY_SEPARATOR . 'somefile.php:10:25',
'error_levels' => [],
'php_version' => '8.3',
],
'overridePrivate' => [
'code' => '<?php
class C {
private function f(): void {}
}
class C2 extends C {
#[Override]
private function f(): void {}
}
',
'error_message' => 'InvalidOverride - src' . DIRECTORY_SEPARATOR . 'somefile.php:7:25',
'error_levels' => [],
'php_version' => '8.3',
],
'overrideInterfaceWithNoParent' => [
'code' => '<?php
interface I {
#[Override]
public function f(): void;
}
',
'error_message' => 'InvalidOverride - src' . DIRECTORY_SEPARATOR . 'somefile.php:3:25',
'error_levels' => [],
'php_version' => '8.3',
],
'tooFewArgumentsToAttributeConstructor' => [ 'tooFewArgumentsToAttributeConstructor' => [
'code' => '<?php 'code' => '<?php
namespace Foo; namespace Foo;

111
tests/OverrideTest.php Normal file
View File

@ -0,0 +1,111 @@
<?php
namespace Psalm\Tests;
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
use const DIRECTORY_SEPARATOR;
class OverrideTest extends TestCase
{
use ValidCodeAnalysisTestTrait;
use InvalidCodeAnalysisTestTrait;
public function providerValidCodeParse(): iterable
{
return [
'overrideClass' => [
'code' => '<?php
class C {
public function f(): void {}
}
class C2 extends C {
#[Override]
public function f(): void {}
}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
'overrideInterface' => [
'code' => '<?php
interface I {
public function f(): void;
}
interface I2 extends I {
#[Override]
public function f(): void;
}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
];
}
public function providerInvalidCodeParse(): iterable
{
return [
'noParent' => [
'code' => '<?php
class C {
#[Override]
public function f(): void {}
}
',
'error_message' => 'InvalidOverride - src' . DIRECTORY_SEPARATOR . 'somefile.php:3:25',
'error_levels' => [],
'php_version' => '8.3',
],
'constructor' => [
'code' => '<?php
/**
* @psalm-consistent-constructor
*/
class C {
public function __construct() {}
}
class C2 extends C {
#[Override]
public function __construct() {}
}
',
'error_message' => 'InvalidOverride - src' . DIRECTORY_SEPARATOR . 'somefile.php:10:25',
'error_levels' => [],
'php_version' => '8.3',
],
'privateMethod' => [
'code' => '<?php
class C {
private function f(): void {}
}
class C2 extends C {
#[Override]
private function f(): void {}
}
',
'error_message' => 'InvalidOverride - src' . DIRECTORY_SEPARATOR . 'somefile.php:7:25',
'error_levels' => [],
'php_version' => '8.3',
],
'interfaceWithNoParent' => [
'code' => '<?php
interface I {
#[Override]
public function f(): void;
}
',
'error_message' => 'InvalidOverride - src' . DIRECTORY_SEPARATOR . 'somefile.php:3:25',
'error_levels' => [],
'php_version' => '8.3',
],
];
}
}