1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/tests/Php55Test.php

82 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Tests;
class Php55Test extends TestCase
{
2018-11-06 03:57:36 +01:00
use Traits\ValidCodeAnalysisTestTrait;
2017-01-13 20:07:23 +01:00
/**
2019-03-01 21:55:20 +01:00
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
2017-01-13 20:07:23 +01:00
*/
2018-11-06 03:57:36 +01:00
public function providerValidCodeParse()
{
return [
'generator' => [
'<?php
/**
* @param int $start
* @param int $limit
* @param int $step
* @return Generator<int>
*/
function xrange($start, $limit, $step = 1) {
for ($i = $start; $i <= $limit; $i += $step) {
yield $i;
}
}
2017-06-29 16:22:49 +02:00
$a = null;
2017-06-29 16:22:49 +02:00
/*
* Note that an array is never created or returned,
* which saves memory.
*/
foreach (xrange(1, 9, 2) as $number) {
$a = $number;
}',
'assertions' => [
'$a' => 'int|null',
2017-05-27 02:05:57 +02:00
],
],
'finally' => [
'<?php
try {
}
catch (\Exception $e) {
}
finally {
2017-05-27 02:05:57 +02:00
}',
],
'foreachList' => [
'<?php
$array = [
[1, 2],
[3, 4],
];
2017-06-29 16:22:49 +02:00
foreach ($array as list($a, $b)) {
echo "A: $a; B: $b\n";
2017-05-27 02:05:57 +02:00
}',
],
'arrayStringDereferencing' => [
'<?php
$a = [1, 2, 3][0];
$b = "PHP"[0];',
'assertions' => [
2017-06-29 16:22:49 +02:00
'$a' => 'int',
'$b' => 'string',
2017-05-27 02:05:57 +02:00
],
],
'classString' => [
'<?php
class ClassName {}
2017-06-29 16:22:49 +02:00
$a = ClassName::class;',
'assertions' => [
'$a' => 'class-string',
2017-05-27 02:05:57 +02:00
],
],
];
}
}