2017-01-13 19:48:58 +01:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
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;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
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
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
2022-01-13 20:38:17 +01:00
|
|
|
* @return iterable<string,array{code:string,assertions?:array<string,string>,ignored_issues?:list<string>}>
|
2017-01-13 20:07:23 +01:00
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): iterable
|
2017-01-13 19:48:58 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'emptyNamespace' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
namespace A {
|
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
2018-02-25 17:13:00 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
2018-02-25 17:13:00 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class Bar {
|
2018-02-25 17:13:00 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace {
|
|
|
|
A\foo();
|
|
|
|
\A\foo();
|
2018-02-25 17:13:00 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
(new A\Bar);
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'constantReference' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2017-04-25 05:45:02 +02:00
|
|
|
namespace Aye\Bee {
|
|
|
|
const HELLO = "hello";
|
|
|
|
}
|
|
|
|
namespace Aye\Bee {
|
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
|
|
|
echo \Aye\Bee\HELLO;
|
|
|
|
}
|
2018-02-25 17:13:00 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class Bar {
|
|
|
|
/** @return void */
|
|
|
|
public function foo() {
|
|
|
|
echo \Aye\Bee\HELLO;
|
|
|
|
}
|
|
|
|
}
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
|
|
|
],
|
2018-03-18 15:38:08 +01:00
|
|
|
'argvReference' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-03-18 15:38:08 +01:00
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
$a = $argv;
|
|
|
|
$b = $argc;',
|
|
|
|
],
|
|
|
|
'argvReferenceInFunction' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-03-18 15:38:08 +01:00
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
function foo() : void {
|
|
|
|
global $argv;
|
|
|
|
|
|
|
|
$c = $argv;
|
|
|
|
}',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2017-01-18 05:55:08 +01:00
|
|
|
}
|
2018-02-25 17:13:00 +01:00
|
|
|
|
|
|
|
/**
|
2022-01-13 20:38:17 +01:00
|
|
|
* @return iterable<string,array{code:string,error_message:string,ignored_issues?:list<string>,php_version?:string}>
|
2018-02-25 17:13:00 +01:00
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerInvalidCodeParse(): iterable
|
2018-02-25 17:13:00 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'callNamespacedFunctionFromEmptyNamespace' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-02-25 17:13:00 +01:00
|
|
|
namespace A {
|
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace {
|
|
|
|
foo();
|
|
|
|
}',
|
|
|
|
'error_message' => 'UndefinedFunction',
|
|
|
|
],
|
|
|
|
'callRootFunctionFromNamespace' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2018-02-25 17:13:00 +01:00
|
|
|
namespace {
|
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace A {
|
|
|
|
\A\foo();
|
|
|
|
}',
|
|
|
|
'error_message' => 'UndefinedFunction',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2017-01-13 19:48:58 +01:00
|
|
|
}
|