1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00
psalm/tests/Php56Test.php
Matthew Brown e29dd140e3 Refactor scanning and analysis, introducing multithreading (#191)
* Add failing test

* Add visitor to soup up classlike references

* Move a whole bunch of code into the visitor

* Move some methods back, move onto analysis stage

* Use the getAliases method everywhere

* Fix refs

* Fix more refs

* Fix some tests

* Fix more tests

* Fix include tests

* Shift config class finding to project checker and fix bugs

* Fix a few more tests

* transition test to new syntax

* Remove var_dump

* Delete a bunch of code and fix mutation test

* Remove unnecessary visitation

* Transition to better mocked out file provider, breaking some cached statement loading

* Use different scheme for naming anonymous classes

* Fix anonymous class issues

* Refactor file/statement loading

* Add specific property types

* Fix mapped property assignment

* Improve how we deal with traits

* Fix trait checking

* Pass Psalm checks

* Add multi-process support

* Delay console output until the end

* Remove PHP 7 syntax

* Update file storage with classes

* Fix scanning individual files and add reflection return types

* Always turn XDebug off

* Add quicker method of getting method mutations

* Queue return types for crawling

* Interpret all strings as possible classes once we see a `get_class` call

* Check invalid return types again

* Fix template namespacing issues

* Default to class-insensitive file names for includes

* Don’t overwrite existing issues data

* Add var docblocks for scanning

* Add null check

* Fix loading of external classes in templates

* Only try to populate class when we haven’t yet seen it’s not a class

* Fix trait property accessibility

* Only ever improve docblock param type

* Make param replacement more robust

* Fix static const missing inferred type

* Fix a few more tests

* Register constant definitions

* Fix trait aliasing

* Skip constant type tests for now

* Fix linting issues

* Make sure caching is off for tests

* Remove unnecessary return

* Use emulative parser if on PHP 5.6

* Cache parser for faster first-time parse

* Fix constant resolution when scanning classes

* Remove test that’s beyond a practical scope

* Add back --diff support

* Add --help for --threads

* Remove unused vars
2017-07-25 16:11:02 -04:00

158 lines
4.7 KiB
PHP

<?php
namespace Psalm\Tests;
class Php56Test extends TestCase
{
use Traits\FileCheckerValidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'constArray' => [
'<?php
const ARR = ["a", "b"];
$a = ARR[0];',
'assertions' => [
'$a' => 'string',
],
],
'classConstFeatures' => [
'<?php
class C {
const ONE = 1;
const TWO = self::ONE * 2;
const THREE = self::TWO + 1;
const ONE_THIRD = self::ONE / self::THREE;
const SENTENCE = "The value of THREE is " . self::THREE;
/**
* @param int $a
* @return int
*/
public function f($a = ONE + self::THREE) {
return $a;
}
}
$c1 = C::ONE;
$c2 = C::TWO;
$c3 = C::THREE;
$c1_3rd = C::ONE_THIRD;
$c_sentence = C::SENTENCE;
$cf = (new C)->f();',
'assertions' => [
'$c1' => 'int',
'$c2' => 'int',
'$c3' => 'int',
'$c1_3rd' => 'float|int',
'$c_sentence' => 'string',
'$cf' => 'int',
],
],
'constFeatures' => [
'<?php
const ONE = 1;
const TWO = ONE * 2;
$one = ONE;
$two = TWO;',
'assertions' => [
'$one' => 'int',
'$two' => 'int',
],
],
'argumentUnpacking' => [
'<?php
/**
* @return int
* @param int $a
* @param int $b
* @param int $c
*/
function add($a, $b, $c) {
return $a + $b + $c;
}
$operators = [2, 3];
echo add(1, ...$operators);',
],
'exponentiation' => [
'<?php
$a = 2;
$a **= 3;',
],
'constantAliasInNamespace' => [
'<?php
namespace Name\Space {
const FOO = 42;
}
namespace Noom\Spice {
use const Name\Space\FOO;
echo FOO . "\n";
echo \Name\Space\FOO;
}',
],
'constantAliasInClass' => [
'<?php
namespace Name\Space {
const FOO = 42;
}
namespace Noom\Spice {
use const Name\Space\FOO;
class A {
/** @return void */
public function fooFoo() {
echo FOO . "\n";
echo \Name\Space\FOO;
}
}
}',
],
'functionAliasInNamespace' => [
'<?php
namespace Name\Space {
/**
* @return void
*/
function f() { echo __FUNCTION__."\n"; }
}
namespace Noom\Spice {
use function Name\Space\f;
f();
\Name\Space\f();
}',
],
'functionAliasInClass' => [
'<?php
namespace Name\Space {
/**
* @return void
*/
function f() { echo __FUNCTION__."\n"; }
}
namespace Noom\Spice {
use function Name\Space\f;
class A {
/** @return void */
public function fooFoo() {
f();
\Name\Space\f();
}
}
}',
],
];
}
}