diff --git a/tests/FileManipulation/MissingReturnTypeTest.php b/tests/FileManipulation/MissingReturnTypeTest.php new file mode 100644 index 000000000..0b7fb0a75 --- /dev/null +++ b/tests/FileManipulation/MissingReturnTypeTest.php @@ -0,0 +1,851 @@ + + */ + public function providerValidCodeParse() + { + return [ + 'addMissingVoidReturnType56' => [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' "hello"] : ["a" => "goodbye", "b" => "hello again"]; + }', + ' "hello"] : ["a" => "goodbye", "b" => "hello again"]; + }', + '7.0', + ['MissingReturnType'], + true, + ], + 'addMissingObjectLikeReturnTypeWithEmptyArray' => [ + ' 1, + "b" => 2, + ]; + }', + ' 1, + "b" => 2, + ]; + }', + '7.0', + ['MissingReturnType'], + true, + ], + 'addMissingObjectLikeReturnTypeWithNestedArrays' => [ + ' 1, + "b" => 2, + "c" => [ + "a" => 1, + "b" => 2, + "c" => [ + "a" => 1, + "b" => 2, + "c" => 3, + ], + ], + ]; + }', + ' 1, + "b" => 2, + "c" => [ + "a" => 1, + "b" => 2, + "c" => [ + "a" => 1, + "b" => 2, + "c" => 3, + ], + ], + ]; + }', + '7.0', + ['MissingReturnType'], + true, + ], + 'addMissingObjectLikeReturnTypeSeparateStatements70' => [ + ' "hello", "b" => "hello again"]; + } + + if (rand(0, 1)) { + return ["a" => "hello", "b" => "hello again"]; + } + + return ["a" => "goodbye"]; + }', + ' "hello", "b" => "hello again"]; + } + + if (rand(0, 1)) { + return ["a" => "hello", "b" => "hello again"]; + } + + return ["a" => "goodbye"]; + }', + '7.0', + ['MissingReturnType'], + true, + ], + 'addMissingStringArrayReturnTypeFromCall71' => [ + ' + */ + function bar(): array { + return foo(); + }', + '7.1', + ['MissingReturnType'], + true, + ], + 'addMissingDocblockStringArrayReturnTypeFromCall71' => [ + ' + */ + function bar() { + return foo(); + }', + '7.1', + ['MissingReturnType'], + true, + ], + 'addMissingNullableStringReturnType71' => [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' */ + function bar(): iterable { + return [1, 2, 3]; + }', + ' + */ + function foo(): iterable { + return bar(); + } + + /** @return iterable */ + function bar(): iterable { + return [1, 2, 3]; + }', + '7.1', + ['MissingReturnType'], + false, + ], + 'addMissingNullableReturnTypeInDocblockOnly71' => [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' + */ + function foo(): array { + return []; + }', + '7.3', + ['MissingReturnType'], + false, + ], + ]; + } +} diff --git a/tests/FileManipulation/ReturnTypeManipulationTest.php b/tests/FileManipulation/ReturnTypeManipulationTest.php index 2709ae52b..96307f4b9 100644 --- a/tests/FileManipulation/ReturnTypeManipulationTest.php +++ b/tests/FileManipulation/ReturnTypeManipulationTest.php @@ -9,68 +9,6 @@ class ReturnTypeManipulationTest extends FileManipulationTest public function providerValidCodeParse() { return [ - 'addMissingVoidReturnType56' => [ - ' [ - ' [ - ' [ - ' [ - ' [ ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' "hello"] : ["a" => "goodbye", "b" => "hello again"]; - }', - ' "hello"] : ["a" => "goodbye", "b" => "hello again"]; - }', - '7.0', - ['MissingReturnType'], - true, - ], - 'addMissingObjectLikeReturnTypeWithEmptyArray' => [ - ' 1, - "b" => 2, - ]; - }', - ' 1, - "b" => 2, - ]; - }', - '7.0', - ['MissingReturnType'], - true, - ], - 'addMissingObjectLikeReturnTypeWithNestedArrays' => [ - ' 1, - "b" => 2, - "c" => [ - "a" => 1, - "b" => 2, - "c" => [ - "a" => 1, - "b" => 2, - "c" => 3, - ], - ], - ]; - }', - ' 1, - "b" => 2, - "c" => [ - "a" => 1, - "b" => 2, - "c" => [ - "a" => 1, - "b" => 2, - "c" => 3, - ], - ], - ]; - }', - '7.0', - ['MissingReturnType'], - true, - ], - 'addMissingObjectLikeReturnTypeSeparateStatements70' => [ - ' "hello", "b" => "hello again"]; - } - - if (rand(0, 1)) { - return ["a" => "hello", "b" => "hello again"]; - } - - return ["a" => "goodbye"]; - }', - ' "hello", "b" => "hello again"]; - } - - if (rand(0, 1)) { - return ["a" => "hello", "b" => "hello again"]; - } - - return ["a" => "goodbye"]; - }', - '7.0', - ['MissingReturnType'], - true, - ], - 'addMissingStringArrayReturnTypeFromCall71' => [ - ' - */ - function bar(): array { - return foo(); - }', - '7.1', - ['MissingReturnType'], - true, - ], - 'addMissingDocblockStringArrayReturnTypeFromCall71' => [ - ' - */ - function bar() { - return foo(); - }', - '7.1', - ['MissingReturnType'], - true, - ], - 'addMissingNullableStringReturnType71' => [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' */ - function bar(): iterable { - return [1, 2, 3]; - }', - ' - */ - function foo(): iterable { - return bar(); - } - - /** @return iterable */ - function bar(): iterable { - return [1, 2, 3]; - }', - '7.1', - ['MissingReturnType'], - false, - ], - 'addMissingNullableReturnTypeInDocblockOnly71' => [ - ' [ - ' [ ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' [ ' [ - ' [ - ' [ ' [ - ' - */ - function foo(): array { - return []; - }', - '7.3', - ['MissingReturnType'], - false, - ], 'dontReplaceValidReturnTypePreventingBackwardsIncompatibility' => [ '