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

108 lines
2.9 KiB
PHP
Raw Normal View History

2017-01-13 19:48:58 +01:00
<?php
namespace Psalm\Tests;
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
/**
2019-03-01 21:55:20 +01:00
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
2017-01-13 20:07:23 +01:00
*/
public function providerValidCodeParse(): iterable
2017-01-13 19:48:58 +01:00
{
return [
'emptyNamespace' => [
'<?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' => [
'<?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' => [
'<?php
namespace Foo;
$a = $argv;
$b = $argc;',
],
'argvReferenceInFunction' => [
'<?php
namespace Foo;
function foo() : void {
global $argv;
$c = $argv;
}',
],
];
}
/**
2019-03-01 21:55:20 +01:00
* @return iterable<string,array{string,error_message:string,2?:string[],3?:bool,4?:string}>
*/
public function providerInvalidCodeParse(): iterable
{
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
}