1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00
psalm/tests/NamespaceTest.php
2022-01-13 14:38:17 -05:00

112 lines
3.1 KiB
PHP

<?php
namespace Psalm\Tests;
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
class NamespaceTest extends TestCase
{
use ValidCodeAnalysisTestTrait;
use InvalidCodeAnalysisTestTrait;
/**
* @return iterable<string,array{code:string,assertions?:array<string,string>,ignored_issues?:list<string>}>
*/
public function providerValidCodeParse(): iterable
{
return [
'emptyNamespace' => [
'code' => '<?php
namespace A {
/** @return void */
function foo() {
}
class Bar {
}
}
namespace {
A\foo();
\A\foo();
(new A\Bar);
}',
],
'constantReference' => [
'code' => '<?php
namespace Aye\Bee {
const HELLO = "hello";
}
namespace Aye\Bee {
/** @return void */
function foo() {
echo \Aye\Bee\HELLO;
}
class Bar {
/** @return void */
public function foo() {
echo \Aye\Bee\HELLO;
}
}
}',
],
'argvReference' => [
'code' => '<?php
namespace Foo;
$a = $argv;
$b = $argc;',
],
'argvReferenceInFunction' => [
'code' => '<?php
namespace Foo;
function foo() : void {
global $argv;
$c = $argv;
}',
],
];
}
/**
* @return iterable<string,array{code:string,error_message:string,ignored_issues?:list<string>,php_version?:string}>
*/
public function providerInvalidCodeParse(): iterable
{
return [
'callNamespacedFunctionFromEmptyNamespace' => [
'code' => '<?php
namespace A {
/** @return void */
function foo() {
}
}
namespace {
foo();
}',
'error_message' => 'UndefinedFunction',
],
'callRootFunctionFromNamespace' => [
'code' => '<?php
namespace {
/** @return void */
function foo() {
}
}
namespace A {
\A\foo();
}',
'error_message' => 'UndefinedFunction',
],
];
}
}