2017-01-13 19:48:58 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class NamespaceTest extends TestCase
|
2017-01-13 19:48:58 +01:00
|
|
|
{
|
2018-11-06 03:57:36 +01:00
|
|
|
use Traits\ValidCodeAnalysisTestTrait;
|
|
|
|
use Traits\InvalidCodeAnalysisTestTrait;
|
2017-01-13 19:48:58 +01:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-01-13 20:07:23 +01:00
|
|
|
*/
|
2018-11-06 03:57:36 +01:00
|
|
|
public function providerValidCodeParse()
|
2017-01-13 19:48:58 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'emptyNamespace' => [
|
|
|
|
'<?php
|
|
|
|
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' => [
|
|
|
|
'<?php
|
|
|
|
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' => [
|
|
|
|
'<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
$a = $argv;
|
|
|
|
$b = $argc;',
|
|
|
|
],
|
|
|
|
'argvReferenceInFunction' => [
|
|
|
|
'<?php
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-11-06 03:57:36 +01:00
|
|
|
public function providerInvalidCodeParse()
|
2018-02-25 17:13:00 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'callNamespacedFunctionFromEmptyNamespace' => [
|
|
|
|
'<?php
|
|
|
|
namespace A {
|
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace {
|
|
|
|
foo();
|
|
|
|
}',
|
|
|
|
'error_message' => 'UndefinedFunction',
|
|
|
|
],
|
|
|
|
'callRootFunctionFromNamespace' => [
|
|
|
|
'<?php
|
|
|
|
namespace {
|
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace A {
|
|
|
|
\A\foo();
|
|
|
|
}',
|
|
|
|
'error_message' => 'UndefinedFunction',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2017-01-13 19:48:58 +01:00
|
|
|
}
|