1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/tests/ConstantTest.php
Jon Ursenbach 11bc153deb Rewriting and streamlining every unit test with data providers. (#147)
* Rewriting and streamlining every unit test with data providers.

All unit tests have been rewritten into PHPUnit data providers
to reduce the amount of unnecessary code-reuse through out the
test suite.
2017-04-24 23:45:02 -04:00

70 lines
1.7 KiB
PHP

<?php
namespace Psalm\Tests;
class ConstantTest extends TestCase
{
use Traits\FileCheckerInvalidCodeParseTestTrait;
use Traits\FileCheckerValidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'constantInFunction' => [
'<?php
useTest();
const TEST = 2;
function useTest() : int {
return TEST;
}'
],
'constantInClosure' => [
'<?php
const TEST = 2;
$useTest = function() : int {
return TEST;
};
$useTest();'
],
'constantDefinedInFunction' => [
'<?php
/**
* @return void
*/
function defineConstant() {
define("CONSTANT", 1);
}
defineConstant();
echo CONSTANT;'
]
];
}
/**
* @return array
*/
public function providerFileCheckerInvalidCodeParse()
{
return [
'constantDefinedInFunctionButNotCalled' => [
'<?php
/**
* @return void
*/
function defineConstant() {
define("CONSTANT", 1);
}
echo CONSTANT;',
'error_message' => 'UndefinedConstant'
]
];
}
}