mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Add more test case scenario for @psalm-import-type (#3375)
* Add test case scenario for @psalm-import-type Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com> * Add fix for @psalm-import-type test Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com> * Add test for import ocross namespaces Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com> * Add tests for failing cases Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
This commit is contained in:
parent
4dd0a2b775
commit
f824cc380a
@ -78,7 +78,7 @@ class TypeParser
|
||||
} else {
|
||||
$only_token[0] = TypeTokenizer::fixScalarTerms($only_token[0], $php_version);
|
||||
|
||||
$atomic = Atomic::create($only_token[0], $php_version, $template_type_map);
|
||||
$atomic = Atomic::create($only_token[0], $php_version, $template_type_map, $type_aliases);
|
||||
$atomic->offset_start = 0;
|
||||
$atomic->offset_end = strlen($only_token[0]);
|
||||
|
||||
|
@ -189,6 +189,70 @@ class TypeAnnotationTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'classTypeAliasImportWithAlias' => [
|
||||
'<?php
|
||||
/** @psalm-type PhoneType = array{phone: string} */
|
||||
class Phone {
|
||||
/** @psalm-return PhoneType */
|
||||
public function toArray(): array {
|
||||
return ["phone" => "Nokia"];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-import-type PhoneType from Phone as TPhone
|
||||
*/
|
||||
class User {
|
||||
/** @psalm-return TPhone */
|
||||
function toArray(): array {
|
||||
return array_merge([], (new Phone)->toArray());
|
||||
}
|
||||
}'
|
||||
],
|
||||
'classTypeAliasDirectUsage' => [
|
||||
'<?php
|
||||
/** @psalm-type PhoneType = array{phone: string} */
|
||||
class Phone {
|
||||
/** @psalm-return PhoneType */
|
||||
public function toArray(): array {
|
||||
return ["phone" => "Nokia"];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-import-type PhoneType from Phone
|
||||
*/
|
||||
class User {
|
||||
/** @psalm-return PhoneType */
|
||||
function toArray(): array {
|
||||
return array_merge([], (new Phone)->toArray());
|
||||
}
|
||||
}'
|
||||
],
|
||||
'classTypeAliasFromExternalNamespace' => [
|
||||
'<?php
|
||||
namespace Foo {
|
||||
/** @psalm-type PhoneType = array{phone: string} */
|
||||
class Phone {
|
||||
/** @psalm-return PhoneType */
|
||||
public function toArray(): array {
|
||||
return ["phone" => "Nokia"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Bar {
|
||||
/**
|
||||
* @psalm-import-type PhoneType from \Foo\Phone
|
||||
*/
|
||||
class User {
|
||||
/** @psalm-return PhoneType */
|
||||
function toArray(): array {
|
||||
return (new \Foo\Phone)->toArray();
|
||||
}
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -254,6 +318,38 @@ class TypeAnnotationTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'InvalidReturnStatement',
|
||||
],
|
||||
'classTypeInvalidAlias' => [
|
||||
'<?php
|
||||
class Phone {
|
||||
function toArray(): array {
|
||||
return ["name" => "Matt"];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-import-type PhoneType from Phone
|
||||
*/
|
||||
class User {
|
||||
/** @psalm-return UserType */
|
||||
function toArray(): array {
|
||||
return (new Phone)->toArray();
|
||||
}
|
||||
}',
|
||||
'error_message' => 'UndefinedDocblockClass',
|
||||
],
|
||||
'classTypeAliasFromInvalidClass' => [
|
||||
'<?php
|
||||
/**
|
||||
* @psalm-import-type PhoneType from Phone
|
||||
*/
|
||||
class User {
|
||||
/** @psalm-return UserType */
|
||||
function toArray(): array {
|
||||
return [];
|
||||
}
|
||||
}',
|
||||
'error_message' => 'UndefinedDocblockClass',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user