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

957 lines
36 KiB
PHP
Raw Normal View History

2018-10-10 22:24:10 +02:00
<?php
2018-10-10 22:24:10 +02:00
namespace Psalm\Tests\FileUpdates;
2021-12-03 20:29:06 +01:00
use Psalm\Exception\CodeException;
2018-11-06 03:57:36 +01:00
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Provider\FakeFileProvider;
2018-11-06 03:57:36 +01:00
use Psalm\Internal\Provider\Providers;
2021-12-04 21:55:53 +01:00
use Psalm\Tests\Internal\Provider\FakeFileReferenceCacheProvider;
2021-12-03 20:11:20 +01:00
use Psalm\Tests\Internal\Provider\ParserInstanceCacheProvider;
use Psalm\Tests\Internal\Provider\ProjectCacheProvider;
use Psalm\Tests\TestCase;
2019-03-23 19:27:54 +01:00
use Psalm\Tests\TestConfig;
2021-12-03 21:40:18 +01:00
use UnexpectedValueException;
2018-10-10 22:24:10 +02:00
2021-06-08 04:55:21 +02:00
use function array_keys;
use function array_pop;
use function getcwd;
use function preg_quote;
use const DIRECTORY_SEPARATOR;
2021-12-03 20:11:20 +01:00
class ErrorAfterUpdateTest extends TestCase
2018-10-10 22:24:10 +02:00
{
public function setUp(): void
2018-10-10 22:24:10 +02:00
{
parent::setUp();
$this->file_provider = new FakeFileProvider();
2018-10-10 22:24:10 +02:00
$config = new TestConfig();
$providers = new Providers(
$this->file_provider,
2021-12-03 20:11:20 +01:00
new ParserInstanceCacheProvider(),
2018-10-10 22:24:10 +02:00
null,
null,
2021-12-04 21:55:53 +01:00
new FakeFileReferenceCacheProvider(),
2022-12-18 17:15:15 +01:00
new ProjectCacheProvider(),
2018-10-10 22:24:10 +02:00
);
2018-11-11 18:01:14 +01:00
$this->project_analyzer = new ProjectAnalyzer(
2018-10-10 22:24:10 +02:00
$config,
2022-12-18 17:15:15 +01:00
$providers,
2018-10-10 22:24:10 +02:00
);
$this->project_analyzer->setPhpVersion('7.3', 'tests');
2018-10-10 22:24:10 +02:00
}
/**
* @dataProvider providerTestInvalidUpdates
* @param array<int, array<string, string>> $file_stages
Add support for strict arrays, fix type alias intersection, fix array_is_list assertion on non-lists (#8395) * Immutable CodeLocation * Remove excess clones * Remove external clones * Remove leftover clones * Fix final clone issue * Immutable storages * Refactoring * Fixes * Fixes * Fix * Fix * Fixes * Simplify * Fixes * Fix * Fixes * Update * Fix * Cache global types * Fix * Update * Update * Fixes * Fixes * Refactor * Fixes * Fix * Fix * More caching * Fix * Fix * Update * Update * Fix * Fixes * Update * Refactor * Update * Fixes * Break one more test * Fix * FIx * Fix * Fix * Fix * Fix * Improve performance and readability * Equivalent logic * Fixes * Revert * Revert "Revert" This reverts commit f9175100c8452c80559234200663fd4c4f4dd889. * Fix * Fix reference bug * Make default TypeVisitor immutable * Bugfix * Remove clones * Partial refactoring * Refactoring * Fixes * Fix * Fixes * Fixes * cs-fix * Fix final bugs * Add test * Misc fixes * Update * Fixes * Experiment with removing different property * revert "Experiment with removing different property" This reverts commit ac1156e077fc4ea633530d51096d27b6e88bfdf9. * Uniform naming * Uniform naming * Hack hotfix * Clean up $_FILES ref #8621 * Undo hack, try fixing properly * Helper method * Remove redundant call * Partially fix bugs * Cleanup * Change defaults * Fix bug * Fix (?, hope this doesn't break anything else) * cs-fix * Review fixes * Bugfix * Bugfix * Improve logic * Add support for list{} and callable-list{} types, properly implement array_is_list assertions (fixes #8389) * Default to sealed arrays * Fix array_merge bug * Fixes * Fix * Sealed type checks * Properly infer properties-of and get_object_vars on final classes * Fix array_map zipping * Fix tests * Fixes * Fixes * Fix more stuff * Recursively resolve type aliases * Fix typo * Fixes * Fix array_is_list assertion on keyed array * Add BC docs * Fixes * fix * Update * Update * Update * Update * Seal arrays with count assertions * Fix #8528 * Fix * Update * Improve sealed array foreach logic * get_object_vars on template properties * Fix sealed array assertion reconciler logic * Improved reconciler * Add tests * Single source of truth for test types * Fix tests * Fixup tests * Fixup tests * Fixup tests * Update * Fix tests * Fix tests * Final fixes * Fixes * Use list syntax only when needed * Fix tests * Cs-fix * Update docs * Update docs * Update docs * Update docs * Update docs * Document missing types * Update docs * Improve class-string-map docs * Update * Update * I love working on psalm :) * Keep arrays unsealed by default * Fixup tests * Fix syntax mistake * cs-fix * Fix typo * Re-import missing types * Keep strict types only in return types * argc/argv fixes * argc/argv fixes * Fix test * Comment-out valinor code, pinging @romm pls merge https://github.com/CuyZ/Valinor/pull/246 so we can add valinor to the psalm docs :)
2022-11-05 22:34:42 +01:00
* @param array<string, string> $ignored_issues
2018-10-10 22:24:10 +02:00
*/
public function testErrorAfterUpdate(
array $file_stages,
string $error_message,
Add support for strict arrays, fix type alias intersection, fix array_is_list assertion on non-lists (#8395) * Immutable CodeLocation * Remove excess clones * Remove external clones * Remove leftover clones * Fix final clone issue * Immutable storages * Refactoring * Fixes * Fixes * Fix * Fix * Fixes * Simplify * Fixes * Fix * Fixes * Update * Fix * Cache global types * Fix * Update * Update * Fixes * Fixes * Refactor * Fixes * Fix * Fix * More caching * Fix * Fix * Update * Update * Fix * Fixes * Update * Refactor * Update * Fixes * Break one more test * Fix * FIx * Fix * Fix * Fix * Fix * Improve performance and readability * Equivalent logic * Fixes * Revert * Revert "Revert" This reverts commit f9175100c8452c80559234200663fd4c4f4dd889. * Fix * Fix reference bug * Make default TypeVisitor immutable * Bugfix * Remove clones * Partial refactoring * Refactoring * Fixes * Fix * Fixes * Fixes * cs-fix * Fix final bugs * Add test * Misc fixes * Update * Fixes * Experiment with removing different property * revert "Experiment with removing different property" This reverts commit ac1156e077fc4ea633530d51096d27b6e88bfdf9. * Uniform naming * Uniform naming * Hack hotfix * Clean up $_FILES ref #8621 * Undo hack, try fixing properly * Helper method * Remove redundant call * Partially fix bugs * Cleanup * Change defaults * Fix bug * Fix (?, hope this doesn't break anything else) * cs-fix * Review fixes * Bugfix * Bugfix * Improve logic * Add support for list{} and callable-list{} types, properly implement array_is_list assertions (fixes #8389) * Default to sealed arrays * Fix array_merge bug * Fixes * Fix * Sealed type checks * Properly infer properties-of and get_object_vars on final classes * Fix array_map zipping * Fix tests * Fixes * Fixes * Fix more stuff * Recursively resolve type aliases * Fix typo * Fixes * Fix array_is_list assertion on keyed array * Add BC docs * Fixes * fix * Update * Update * Update * Update * Seal arrays with count assertions * Fix #8528 * Fix * Update * Improve sealed array foreach logic * get_object_vars on template properties * Fix sealed array assertion reconciler logic * Improved reconciler * Add tests * Single source of truth for test types * Fix tests * Fixup tests * Fixup tests * Fixup tests * Update * Fix tests * Fix tests * Final fixes * Fixes * Use list syntax only when needed * Fix tests * Cs-fix * Update docs * Update docs * Update docs * Update docs * Update docs * Document missing types * Update docs * Improve class-string-map docs * Update * Update * I love working on psalm :) * Keep arrays unsealed by default * Fixup tests * Fix syntax mistake * cs-fix * Fix typo * Re-import missing types * Keep strict types only in return types * argc/argv fixes * argc/argv fixes * Fix test * Comment-out valinor code, pinging @romm pls merge https://github.com/CuyZ/Valinor/pull/246 so we can add valinor to the psalm docs :)
2022-11-05 22:34:42 +01:00
array $ignored_issues = []
): void {
2018-11-11 18:01:14 +01:00
$this->project_analyzer->getCodebase()->diff_methods = true;
$this->project_analyzer->getCodebase()->reportUnusedCode();
2018-10-10 22:24:10 +02:00
2018-11-11 18:01:14 +01:00
$codebase = $this->project_analyzer->getCodebase();
2018-10-10 22:24:10 +02:00
$config = $codebase->config;
Add support for strict arrays, fix type alias intersection, fix array_is_list assertion on non-lists (#8395) * Immutable CodeLocation * Remove excess clones * Remove external clones * Remove leftover clones * Fix final clone issue * Immutable storages * Refactoring * Fixes * Fixes * Fix * Fix * Fixes * Simplify * Fixes * Fix * Fixes * Update * Fix * Cache global types * Fix * Update * Update * Fixes * Fixes * Refactor * Fixes * Fix * Fix * More caching * Fix * Fix * Update * Update * Fix * Fixes * Update * Refactor * Update * Fixes * Break one more test * Fix * FIx * Fix * Fix * Fix * Fix * Improve performance and readability * Equivalent logic * Fixes * Revert * Revert "Revert" This reverts commit f9175100c8452c80559234200663fd4c4f4dd889. * Fix * Fix reference bug * Make default TypeVisitor immutable * Bugfix * Remove clones * Partial refactoring * Refactoring * Fixes * Fix * Fixes * Fixes * cs-fix * Fix final bugs * Add test * Misc fixes * Update * Fixes * Experiment with removing different property * revert "Experiment with removing different property" This reverts commit ac1156e077fc4ea633530d51096d27b6e88bfdf9. * Uniform naming * Uniform naming * Hack hotfix * Clean up $_FILES ref #8621 * Undo hack, try fixing properly * Helper method * Remove redundant call * Partially fix bugs * Cleanup * Change defaults * Fix bug * Fix (?, hope this doesn't break anything else) * cs-fix * Review fixes * Bugfix * Bugfix * Improve logic * Add support for list{} and callable-list{} types, properly implement array_is_list assertions (fixes #8389) * Default to sealed arrays * Fix array_merge bug * Fixes * Fix * Sealed type checks * Properly infer properties-of and get_object_vars on final classes * Fix array_map zipping * Fix tests * Fixes * Fixes * Fix more stuff * Recursively resolve type aliases * Fix typo * Fixes * Fix array_is_list assertion on keyed array * Add BC docs * Fixes * fix * Update * Update * Update * Update * Seal arrays with count assertions * Fix #8528 * Fix * Update * Improve sealed array foreach logic * get_object_vars on template properties * Fix sealed array assertion reconciler logic * Improved reconciler * Add tests * Single source of truth for test types * Fix tests * Fixup tests * Fixup tests * Fixup tests * Update * Fix tests * Fix tests * Final fixes * Fixes * Use list syntax only when needed * Fix tests * Cs-fix * Update docs * Update docs * Update docs * Update docs * Update docs * Document missing types * Update docs * Improve class-string-map docs * Update * Update * I love working on psalm :) * Keep arrays unsealed by default * Fixup tests * Fix syntax mistake * cs-fix * Fix typo * Re-import missing types * Keep strict types only in return types * argc/argv fixes * argc/argv fixes * Fix test * Comment-out valinor code, pinging @romm pls merge https://github.com/CuyZ/Valinor/pull/246 so we can add valinor to the psalm docs :)
2022-11-05 22:34:42 +01:00
foreach ($ignored_issues as $error_type => $error_level) {
2018-10-10 22:24:10 +02:00
$config->setCustomErrorLevel($error_type, $error_level);
}
if (!$file_stages) {
2021-12-03 21:40:18 +01:00
throw new UnexpectedValueException('$file_stages should not be empty');
}
2018-10-10 22:24:10 +02:00
$end_files = array_pop($file_stages);
foreach ($file_stages as $files) {
foreach ($files as $file_path => $contents) {
$this->file_provider->registerFile($file_path, $contents);
}
2018-11-11 18:01:14 +01:00
$codebase->reloadFiles($this->project_analyzer, array_keys($files));
2018-10-10 22:24:10 +02:00
2020-04-01 18:56:32 +02:00
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false, true);
2018-10-10 22:24:10 +02:00
}
foreach ($end_files as $file_path => $contents) {
$this->file_provider->registerFile($file_path, $contents);
}
2021-12-03 20:29:06 +01:00
$this->expectException(CodeException::class);
2022-01-19 19:29:16 +01:00
$this->expectExceptionMessageMatches('/\b' . preg_quote($error_message, '/') . '\b/');
2019-01-02 17:18:22 +01:00
2018-11-11 18:01:14 +01:00
$codebase->reloadFiles($this->project_analyzer, array_keys($end_files));
2018-10-10 22:24:10 +02:00
foreach ($end_files as $file_path => $_) {
$codebase->addFilesToAnalyze([$file_path => $file_path]);
}
2020-04-01 18:56:32 +02:00
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false, true);
2018-10-10 22:24:10 +02:00
}
/**
* @return array<string,array{file_stages:array<int,array<string,string>>,error_message:string}>
2018-10-10 22:24:10 +02:00
*/
public function providerTestInvalidUpdates(): array
2018-10-10 22:24:10 +02:00
{
return [
'invalidateParentCaller' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
public function foo() : void {}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B extends A { }',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'C.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class C {
public function bar() : void {
(new B)->foo();
}
}
(new C())->bar();',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A { }',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B extends A { }',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'C.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class C {
public function bar() : void {
(new B)->foo();
}
}
(new C())->bar();',
2018-10-10 22:24:10 +02:00
],
],
'error_message' => 'UndefinedMethod',
],
'invalidateAfterPropertyTypeChange' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
/** @var string */
public $foo = "bar";
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B {
public function foo() : string {
return (new A)->foo;
}
}
2021-06-10 18:57:13 +02:00
echo (new B)->foo();',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
/** @var int */
public $foo = 5;
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B {
public function foo() : string {
return (new A)->foo;
}
}
2021-06-10 18:57:13 +02:00
echo (new B)->foo();',
2018-10-10 22:24:10 +02:00
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'InvalidReturnStatement',
2018-10-10 22:24:10 +02:00
],
'invalidateAfterConstantChange' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
public const FOO = "bar";
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B {
public function foo() : string {
return A::FOO;
}
}
2021-06-10 18:57:13 +02:00
echo (new B)->foo();',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
public const FOO = 5;
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B {
public function foo() : string {
return A::FOO;
}
}
2021-06-10 18:57:13 +02:00
echo (new B)->foo();',
2018-10-10 22:24:10 +02:00
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'InvalidReturnStatement',
2018-10-10 22:24:10 +02:00
],
'invalidateAfterSkippedAnalysis' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
public function getB() : B {
return new B;
}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B {
public function getString() : string {
return "foo";
}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'C.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class C {
public function existingMethod() : string {
2018-10-10 22:24:10 +02:00
return (new A)->getB()->getString();
}
}
2021-06-10 18:57:13 +02:00
echo (new C)->existingMethod();',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
public function getB() : B {
return new B;
}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B {
public function getString() : string {
return "foo";
}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'C.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class C {
public function existingMethod() : string {
2018-10-10 22:24:10 +02:00
return (new A)->getB()->getString();
}
public function newMethod() : void {}
}
2021-06-10 18:57:13 +02:00
echo (new C)->existingMethod();
// newly-added call, removed in the next code block
(new C)->newMethod();',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
public function getB() : B {
return new B;
}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B {
public function getString() : ?string {
return "foo";
}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'C.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class C {
public function existingMethod() : string {
2018-10-10 22:24:10 +02:00
return (new A)->getB()->getString();
}
}
2021-06-10 18:57:13 +02:00
echo (new C)->existingMethod();',
2018-10-10 22:24:10 +02:00
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'NullableReturnStatement',
2018-10-10 22:24:10 +02:00
],
'invalidateMissingConstructorAfterPropertyChange' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
/** @var string */
public $foo = "bar";
}
echo (new A)->foo;',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
/** @var string */
public $foo;
}
echo (new A)->foo;',
2018-10-10 22:24:10 +02:00
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'MissingConstructor',
2018-10-10 22:24:10 +02:00
],
'invalidateEmptyConstructorAfterPropertyChange' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
/** @var string */
public $foo = "bar";
public function __construct() {}
}
echo (new A)->foo;',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
/** @var string */
public $foo;
public function __construct() {}
}
echo (new A)->foo;',
2018-10-10 22:24:10 +02:00
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'PropertyNotSetInConstructor',
2018-10-10 22:24:10 +02:00
],
'invalidateEmptyTraitConstructorAfterPropertyChange' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
use T;
/** @var string */
public $foo = "bar";
}
echo (new A)->foo;',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'T.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
trait T {
public function __construct() {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
use T;
/** @var string */
public $foo;
}
echo (new A)->foo;',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'T.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
trait T {
public function __construct() {}
}',
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'PropertyNotSetInConstructor',
2018-10-10 22:24:10 +02:00
],
'invalidateEmptyTraitConstructorAfterTraitPropertyChange' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
use T;
}
echo (new A)->foo;',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'T.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
trait T {
/** @var string */
public $foo = "bar";
public function __construct() {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
use T;
/** @var string */
public $foo;
}
echo (new A)->foo;',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'T.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
trait T {
/** @var string */
public $foo;
public function __construct() {}
}',
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'PropertyNotSetInConstructor',
2018-10-10 22:24:10 +02:00
],
'invalidateSetInPrivateMethodConstructorCheck' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
/** @var string */
public $foo;
public function __construct() {
$this->setFoo();
}
private function setFoo() : void {
$this->foo = "bar";
}
}
echo (new A)->foo;',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class A {
/** @var string */
public $foo;
public function __construct() {
$this->setFoo();
}
private function setFoo() : void {
}
}
echo (new A)->foo;',
2018-10-10 22:24:10 +02:00
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'PropertyNotSetInConstructor',
2018-10-10 22:24:10 +02:00
],
'invalidateMissingConstructorAfterParentPropertyChange' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
abstract class A {
/** @var string */
public $foo = "bar";
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B extends A {}
echo (new B)->foo;',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
abstract class A {
/** @var string */
public $foo;
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B extends A {}
echo (new B)->foo;',
2018-10-10 22:24:10 +02:00
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'MissingConstructor',
2018-10-10 22:24:10 +02:00
],
'invalidateNotSetInConstructorAfterParentPropertyChange' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
abstract class A {
/** @var string */
public $foo = "bar";
public function __construct() {}
}
class C extends A {}
new C();',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B extends A {
public function __construct() {}
}
echo (new B)->foo;',
2018-10-10 22:24:10 +02:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
abstract class A {
/** @var string */
public $foo;
public function __construct() {}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
2018-10-10 22:24:10 +02:00
namespace Foo;
class B extends A {
public function __construct() {}
}
echo (new B)->foo;',
2018-10-10 22:24:10 +02:00
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'PropertyNotSetInConstructor',
2018-10-10 22:24:10 +02:00
],
2019-01-02 17:18:22 +01:00
'duplicateClass' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2019-01-02 17:18:22 +01:00
namespace Foo;
class A {}
new A();',
2019-01-02 17:18:22 +01:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2019-01-02 17:18:22 +01:00
namespace Foo;
class A {}
class A {}',
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'DuplicateClass',
2019-01-02 17:18:22 +01:00
],
'duplicateMethod' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2019-01-02 17:18:22 +01:00
namespace Foo;
class A {
public function foo() : void {}
}
(new A)->foo();',
2019-01-02 17:18:22 +01:00
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
2019-01-02 17:18:22 +01:00
namespace Foo;
class A {
public function foo() : void {}
public function foo() : void {}
}',
],
],
2019-03-23 19:27:54 +01:00
'error_message' => 'DuplicateMethod',
2019-01-02 17:18:22 +01:00
],
'unusedClassReferencedInFile' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {}
2020-09-21 02:58:34 +02:00
$a = new A();
print_r($a);',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {}',
],
],
'error_message' => 'UnusedClass',
],
'unusedMethodReferencedInFile' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public function foo() : void {}
}
(new A)->foo();',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public function foo() : void {}
}
2020-09-21 02:58:34 +02:00
$a = new A();
print_r($a);',
],
],
'error_message' => 'PossiblyUnusedMethod',
],
'unusedStaticMethodReferencedInFile' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public static function foo() : void {}
public static function bar() : void {}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
\Foo\A::foo();
\Foo\A::bar();',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public static function foo() : void {}
public static function bar() : void {}
}',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'B.php' => '<?php
\Foo\A::bar();',
],
],
'error_message' => 'PossiblyUnusedMethod',
],
'unusedParamReferencedInFile' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public function foo(string $s) : void {}
}
class B extends A {
public function foo(string $s) : void {
echo $s;
}
}
(new B)->foo("hello");',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public function foo(string $s) : void {}
}
class B extends A {
}
(new B)->foo("hello");',
],
],
'error_message' => 'PossiblyUnusedParam',
],
'unusedMethodReferencedInMethod' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public function foo() : void {}
}
class B {
public function bar() : void {
(new A)->foo();
}
}
(new B)->bar();',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public function foo() : void {}
}
class B {
public function bar() : void {
new A();
}
}
(new B)->bar();',
],
],
'error_message' => 'PossiblyUnusedMethod',
],
'unusedPropertyReferencedInFile' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
/** @var string */
public $foo = "hello";
}
echo (new A)->foo;',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
/** @var string */
public $foo = "hello";
}
2020-09-21 02:58:34 +02:00
print_r(new A());',
],
],
'error_message' => 'PossiblyUnusedProperty',
],
'unusedPropertyReferencedInMethod' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
/** @var string */
public $foo = "hello";
}
class B {
public function bar() : void {
echo (new A)->foo;
}
}
(new B)->bar();',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
/** @var string */
public $foo = "hello";
}
class B {
public function bar() : void {
new A();
}
}
(new B)->bar();',
],
],
'error_message' => 'PossiblyUnusedProperty',
],
'uninitialisedChildProperty' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
abstract class A {
public function __construct() {
$this->setFoo();
}
abstract protected function setFoo() : void;
}',
getcwd() . DIRECTORY_SEPARATOR . 'AChild.php' => '<?php
namespace Foo;
class AChild extends A {
/** @var string */
public $foo;
protected function setFoo() : void {
$this->reallySetFoo();
}
private function reallySetFoo() : void {
$this->foo = "bar";
}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
abstract class A {
public function __construct() {
$this->setFoo();
}
abstract protected function setFoo() : void;
}',
getcwd() . DIRECTORY_SEPARATOR . 'AChild.php' => '<?php
namespace Foo;
class AChild extends A {
/** @var string */
public $foo;
protected function setFoo() : void {
$this->reallySetFoo();
}
private function reallySetFoo() : void {
//$this->foo = "bar";
}
}',
],
],
'error_message' => 'PropertyNotSetInConstructor',
],
'invalidateChildMethodWhenSignatureChanges' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public function foo(string $s) : void {
echo $s;
}
}
class AChild extends A {
public function foo(string $s) : void {
echo $s;
}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
public function foo(string $s = "") : void {
echo $s;
}
}
class AChild extends A {
public function foo(string $s) : void {
echo $s;
}
}',
],
],
'error_message' => 'MethodSignatureMismatch',
],
2018-10-10 22:24:10 +02:00
];
}
}