2016-10-19 04:23:09 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class Php56Test extends TestCase
|
2016-10-19 04:23:09 +02:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2016-10-19 04:23:09 +02:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-01-13 20:07:23 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerValidCodeParse()
|
2016-10-19 04:23:09 +02:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'constArray' => [
|
|
|
|
'<?php
|
|
|
|
const ARR = ["a", "b"];
|
|
|
|
$a = ARR[0];',
|
|
|
|
'assertions' => [
|
2017-06-29 16:22:49 +02:00
|
|
|
'$a' => 'string',
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2017-07-25 22:11:02 +02:00
|
|
|
'classConstFeatures' => [
|
2017-04-25 05:45:02 +02:00
|
|
|
'<?php
|
|
|
|
class C {
|
2017-07-25 22:11:02 +02:00
|
|
|
const ONE = 1;
|
|
|
|
const TWO = self::ONE * 2;
|
|
|
|
const THREE = self::TWO + 1;
|
|
|
|
const ONE_THIRD = self::ONE / self::THREE;
|
2017-04-25 05:45:02 +02:00
|
|
|
const SENTENCE = "The value of THREE is " . self::THREE;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2018-01-21 18:44:46 +01:00
|
|
|
/** @var int */
|
|
|
|
public $four = self::ONE + self::THREE;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
/**
|
|
|
|
* @param int $a
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function f($a = ONE + self::THREE) {
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$c1 = C::ONE;
|
|
|
|
$c2 = C::TWO;
|
|
|
|
$c3 = C::THREE;
|
|
|
|
$c1_3rd = C::ONE_THIRD;
|
|
|
|
$c_sentence = C::SENTENCE;
|
2018-01-21 18:44:46 +01:00
|
|
|
$cf = (new C)->f();
|
|
|
|
$c4 = (new C)->four',
|
2017-07-25 22:11:02 +02:00
|
|
|
'assertions' => [
|
|
|
|
'$c1' => 'int',
|
|
|
|
'$c2' => 'int',
|
|
|
|
'$c3' => 'int',
|
|
|
|
'$c1_3rd' => 'float|int',
|
|
|
|
'$c_sentence' => 'string',
|
|
|
|
'$cf' => 'int',
|
2018-01-21 18:44:46 +01:00
|
|
|
'$c4' => 'int',
|
2017-07-25 22:11:02 +02:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'constFeatures' => [
|
|
|
|
'<?php
|
|
|
|
const ONE = 1;
|
|
|
|
const TWO = ONE * 2;
|
|
|
|
|
|
|
|
$one = ONE;
|
|
|
|
$two = TWO;',
|
2017-04-25 05:45:02 +02:00
|
|
|
'assertions' => [
|
2017-07-25 22:11:02 +02:00
|
|
|
'$one' => 'int',
|
|
|
|
'$two' => 'int',
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'argumentUnpacking' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
* @param int $a
|
|
|
|
* @param int $b
|
|
|
|
* @param int $c
|
|
|
|
*/
|
|
|
|
function add($a, $b, $c) {
|
|
|
|
return $a + $b + $c;
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
$operators = [2, 3];
|
2017-05-27 02:05:57 +02:00
|
|
|
echo add(1, ...$operators);',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2017-12-23 02:09:58 +01:00
|
|
|
'arrayMergeArgumentUnpacking' => [
|
|
|
|
'<?php
|
|
|
|
$a = [[1, 2]];
|
|
|
|
$b = array_merge([], ...$a);',
|
|
|
|
'assertions' => [
|
|
|
|
'$b' => 'array{0:int, 1:int}',
|
|
|
|
],
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'exponentiation' => [
|
|
|
|
'<?php
|
|
|
|
$a = 2;
|
2017-05-27 02:05:57 +02:00
|
|
|
$a **= 3;',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'constantAliasInNamespace' => [
|
|
|
|
'<?php
|
|
|
|
namespace Name\Space {
|
|
|
|
const FOO = 42;
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
namespace Noom\Spice {
|
|
|
|
use const Name\Space\FOO;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
echo FOO . "\n";
|
|
|
|
echo \Name\Space\FOO;
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'constantAliasInClass' => [
|
|
|
|
'<?php
|
|
|
|
namespace Name\Space {
|
|
|
|
const FOO = 42;
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
namespace Noom\Spice {
|
|
|
|
use const Name\Space\FOO;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class A {
|
|
|
|
/** @return void */
|
|
|
|
public function fooFoo() {
|
|
|
|
echo FOO . "\n";
|
|
|
|
echo \Name\Space\FOO;
|
|
|
|
}
|
|
|
|
}
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'functionAliasInNamespace' => [
|
|
|
|
'<?php
|
|
|
|
namespace Name\Space {
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function f() { echo __FUNCTION__."\n"; }
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
namespace Noom\Spice {
|
|
|
|
use function Name\Space\f;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
f();
|
|
|
|
\Name\Space\f();
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'functionAliasInClass' => [
|
|
|
|
'<?php
|
|
|
|
namespace Name\Space {
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function f() { echo __FUNCTION__."\n"; }
|
|
|
|
}
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
namespace Noom\Spice {
|
|
|
|
use function Name\Space\f;
|
2017-06-29 16:22:49 +02:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class A {
|
|
|
|
/** @return void */
|
|
|
|
public function fooFoo() {
|
|
|
|
f();
|
|
|
|
\Name\Space\f();
|
|
|
|
}
|
|
|
|
}
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2016-10-19 04:23:09 +02:00
|
|
|
}
|
|
|
|
}
|