1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/tests/NamespaceTest.php

124 lines
3.3 KiB
PHP
Raw Normal View History

2017-01-13 19:48:58 +01:00
<?php
2017-01-13 19:48:58 +01:00
namespace Psalm\Tests;
2021-12-04 21:55:53 +01:00
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
class NamespaceTest extends TestCase
2017-01-13 19:48:58 +01:00
{
2021-12-04 21:55:53 +01:00
use ValidCodeAnalysisTestTrait;
use InvalidCodeAnalysisTestTrait;
2017-01-13 19:48:58 +01:00
public function providerValidCodeParse(): iterable
2017-01-13 19:48:58 +01:00
{
return [
'emptyNamespace' => [
'code' => '<?php
namespace A {
/** @return void */
function foo() {
}
class Bar {
}
}
namespace {
A\foo();
\A\foo();
(new A\Bar);
2017-05-27 02:05:57 +02:00
}',
],
'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;
}
}
2017-05-27 02:05:57 +02:00
}',
],
'argvReference' => [
'code' => '<?php
namespace Foo;
$a = $argv;
$b = $argc;',
],
'argvReferenceInFunction' => [
'code' => '<?php
namespace Foo;
function foo() : void {
global $argv;
$c = $argv;
}',
],
'varsAreNotScoped' => [
'code' => '<?php
namespace A {
$a = "1";
}
namespace B\C {
$bc = "2";
}
namespace {
echo $a . PHP_EOL;
echo $bc . PHP_EOL;
}
',
'assertions' => [
'$a===' => "'1'",
'$bc===' => "'2'",
],
],
];
}
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',
],
];
}
2017-01-13 19:48:58 +01:00
}