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

91 lines
2.3 KiB
PHP

<?php
namespace Psalm\Tests;
class NamespaceTest extends TestCase
{
use Traits\FileCheckerValidCodeParseTestTrait;
use Traits\FileCheckerInvalidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'emptyNamespace' => [
'<?php
namespace A {
/** @return void */
function foo() {
}
class Bar {
}
}
namespace {
A\foo();
\A\foo();
(new A\Bar);
}',
],
'constantReference' => [
'<?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;
}
}
}',
],
];
}
/**
* @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',
],
];
}
}