2017-01-15 21:58:40 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class ConstantTest extends TestCase
|
2017-01-15 21:58:40 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2017-01-15 21:58:40 +01:00
|
|
|
|
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-01-15 21:58:40 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerValidCodeParse()
|
2017-01-15 21:58:40 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'constantInFunction' => [
|
|
|
|
'<?php
|
|
|
|
useTest();
|
|
|
|
const TEST = 2;
|
2017-12-06 06:05:01 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
function useTest() : int {
|
|
|
|
return TEST;
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'constantInClosure' => [
|
|
|
|
'<?php
|
|
|
|
const TEST = 2;
|
2017-12-06 06:05:01 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
$useTest = function() : int {
|
|
|
|
return TEST;
|
|
|
|
};
|
2017-05-27 02:05:57 +02:00
|
|
|
$useTest();',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'constantDefinedInFunction' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function defineConstant() {
|
|
|
|
define("CONSTANT", 1);
|
|
|
|
}
|
2017-12-06 06:05:01 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
defineConstant();
|
2017-12-06 06:05:01 +01:00
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
echo CONSTANT;',
|
|
|
|
],
|
2017-12-06 06:05:01 +01:00
|
|
|
'magicConstant' => [
|
|
|
|
'<?php
|
|
|
|
$a = __LINE__;
|
|
|
|
$b = __file__;',
|
|
|
|
'assertions' => [
|
|
|
|
'$a' => 'int',
|
|
|
|
'$b' => 'string',
|
|
|
|
],
|
|
|
|
],
|
2017-12-19 15:48:01 +01:00
|
|
|
'getClassConstantValue' => [
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
const B = [0, 1, 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = A::B[1];',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2017-01-15 21:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-01-15 21:58:40 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerInvalidCodeParse()
|
2017-01-15 21:58:40 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'constantDefinedInFunctionButNotCalled' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function defineConstant() {
|
|
|
|
define("CONSTANT", 1);
|
|
|
|
}
|
2017-12-06 06:05:01 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
echo CONSTANT;',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'UndefinedConstant',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2017-01-15 22:43:49 +01:00
|
|
|
}
|
2017-01-15 21:58:40 +01:00
|
|
|
}
|