2017-01-13 13:48:58 -05:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
class NamespaceTest extends TestCase
|
2017-01-13 13:48:58 -05:00
|
|
|
{
|
2017-04-24 23:45:02 -04:00
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2018-02-25 11:13:00 -05:00
|
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
2017-01-13 13:48:58 -05:00
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
2017-04-24 23:45:02 -04:00
|
|
|
* @return array
|
2017-01-13 14:07:23 -05:00
|
|
|
*/
|
2017-04-24 23:45:02 -04:00
|
|
|
public function providerFileCheckerValidCodeParse()
|
2017-01-13 13:48:58 -05:00
|
|
|
{
|
2017-04-24 23:45:02 -04:00
|
|
|
return [
|
|
|
|
'emptyNamespace' => [
|
|
|
|
'<?php
|
|
|
|
namespace A {
|
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
2018-02-25 11:13:00 -05:00
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
}
|
2018-02-25 11:13:00 -05:00
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
class Bar {
|
2018-02-25 11:13:00 -05:00
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace {
|
|
|
|
A\foo();
|
|
|
|
\A\foo();
|
2018-02-25 11:13:00 -05:00
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
(new A\Bar);
|
2017-05-26 20:05:57 -04:00
|
|
|
}',
|
2017-04-24 23:45:02 -04:00
|
|
|
],
|
|
|
|
'constantReference' => [
|
|
|
|
'<?php
|
|
|
|
namespace Aye\Bee {
|
|
|
|
const HELLO = "hello";
|
|
|
|
}
|
|
|
|
namespace Aye\Bee {
|
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
|
|
|
echo \Aye\Bee\HELLO;
|
|
|
|
}
|
2018-02-25 11:13:00 -05:00
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
class Bar {
|
|
|
|
/** @return void */
|
|
|
|
public function foo() {
|
|
|
|
echo \Aye\Bee\HELLO;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 20:05:57 -04:00
|
|
|
}',
|
|
|
|
],
|
2018-03-18 10:38:08 -04:00
|
|
|
'argvReference' => [
|
|
|
|
'<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
$a = $argv;
|
|
|
|
$b = $argc;',
|
|
|
|
],
|
|
|
|
'argvReferenceInFunction' => [
|
|
|
|
'<?php
|
|
|
|
namespace Foo;
|
|
|
|
|
|
|
|
function foo() : void {
|
|
|
|
global $argv;
|
|
|
|
|
|
|
|
$c = $argv;
|
|
|
|
}',
|
|
|
|
],
|
2017-04-24 23:45:02 -04:00
|
|
|
];
|
2017-01-17 23:55:08 -05:00
|
|
|
}
|
2018-02-25 11:13:00 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function providerFileCheckerInvalidCodeParse()
|
|
|
|
{
|
|
|
|
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 13:48:58 -05:00
|
|
|
}
|