2017-01-15 15:58:40 -05:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
class ConstantTest extends TestCase
|
2017-01-15 15:58:40 -05:00
|
|
|
{
|
2017-04-24 23:45:02 -04:00
|
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2017-01-15 15:58:40 -05:00
|
|
|
|
|
|
|
/**
|
2017-04-24 23:45:02 -04:00
|
|
|
* @return array
|
2017-01-15 15:58:40 -05:00
|
|
|
*/
|
2017-04-24 23:45:02 -04:00
|
|
|
public function providerFileCheckerValidCodeParse()
|
2017-01-15 15:58:40 -05:00
|
|
|
{
|
2017-04-24 23:45:02 -04:00
|
|
|
return [
|
|
|
|
'constantInFunction' => [
|
|
|
|
'<?php
|
|
|
|
useTest();
|
|
|
|
const TEST = 2;
|
|
|
|
|
|
|
|
function useTest() : int {
|
|
|
|
return TEST;
|
2017-05-26 20:05:57 -04:00
|
|
|
}',
|
2017-04-24 23:45:02 -04:00
|
|
|
],
|
|
|
|
'constantInClosure' => [
|
|
|
|
'<?php
|
|
|
|
const TEST = 2;
|
|
|
|
|
|
|
|
$useTest = function() : int {
|
|
|
|
return TEST;
|
|
|
|
};
|
2017-05-26 20:05:57 -04:00
|
|
|
$useTest();',
|
2017-04-24 23:45:02 -04:00
|
|
|
],
|
|
|
|
'constantDefinedInFunction' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function defineConstant() {
|
|
|
|
define("CONSTANT", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
defineConstant();
|
|
|
|
|
2017-05-26 20:05:57 -04:00
|
|
|
echo CONSTANT;',
|
|
|
|
],
|
2017-04-24 23:45:02 -04:00
|
|
|
];
|
2017-01-15 15:58:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-24 23:45:02 -04:00
|
|
|
* @return array
|
2017-01-15 15:58:40 -05:00
|
|
|
*/
|
2017-04-24 23:45:02 -04:00
|
|
|
public function providerFileCheckerInvalidCodeParse()
|
2017-01-15 15:58:40 -05:00
|
|
|
{
|
2017-04-24 23:45:02 -04:00
|
|
|
return [
|
|
|
|
'constantDefinedInFunctionButNotCalled' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function defineConstant() {
|
|
|
|
define("CONSTANT", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo CONSTANT;',
|
2017-05-26 20:05:57 -04:00
|
|
|
'error_message' => 'UndefinedConstant',
|
|
|
|
],
|
2017-04-24 23:45:02 -04:00
|
|
|
];
|
2017-01-15 16:43:49 -05:00
|
|
|
}
|
2017-01-15 15:58:40 -05:00
|
|
|
}
|