1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 13:51:54 +01:00

Adjusted existing tests to the new signature of explode()

Note how the signature became `array{0: string, 1?: string, 2?: string, array<int, string>}`,
which may be a side-effect of unions between a defined hashmap structure with array
keys, and `list<string>`.
This commit is contained in:
Marco Pivetta 2022-12-28 17:39:06 +01:00
parent bfded43614
commit 6341d7fef0
2 changed files with 26 additions and 31 deletions

View File

@ -422,7 +422,7 @@ class FunctionCallTest extends TestCase
/** @var string $string */ /** @var string $string */
$elements = explode(" ", $string, -5);', $elements = explode(" ", $string, -5);',
'assertions' => [ 'assertions' => [
'$elements' => 'list<string>', '$elements' => 'array<never, never>',
], ],
], ],
'explodeWithDynamicLimit' => [ 'explodeWithDynamicLimit' => [
@ -433,52 +433,63 @@ class FunctionCallTest extends TestCase
*/ */
$elements = explode(" ", $string, $limit);', $elements = explode(" ", $string, $limit);',
'assertions' => [ 'assertions' => [
'$elements' => 'list<string>', '$elements' => 'array{0?: string, 1?: string, 2?: string, ...<int<0, max>, string>}',
], ],
], ],
'explodeWithDynamicDelimiter' => [ 'explodeWithDynamicDelimiter' => [
'code' => '<?php 'code' => '<?php
/** /**
* @var string $delim * @var non-empty-string $delim
* @var string $string * @var string $string
*/ */
$elements = explode($delim, $string);', $elements = explode($delim, $string);',
'assertions' => [ 'assertions' => [
'$elements' => 'false|non-empty-list<string>', '$elements' => 'non-empty-list<string>',
],
],
'explodeWithDynamicDelimiterAndSmallPositiveLimit' => [
'code' => '<?php
/**
* @var non-empty-string $delim
* @var string $string
*/
$elements = explode($delim, $string, 2);',
'assertions' => [
'$elements' => 'array{0: string, 1?: string}',
], ],
], ],
'explodeWithDynamicDelimiterAndPositiveLimit' => [ 'explodeWithDynamicDelimiterAndPositiveLimit' => [
'code' => '<?php 'code' => '<?php
/** /**
* @var string $delim * @var non-empty-string $delim
* @var string $string * @var string $string
*/ */
$elements = explode($delim, $string, 5);', $elements = explode($delim, $string, 5);',
'assertions' => [ 'assertions' => [
'$elements' => 'false|non-empty-list<string>', '$elements' => 'non-empty-list<string>',
], ],
], ],
'explodeWithDynamicDelimiterAndNegativeLimit' => [ 'explodeWithDynamicDelimiterAndNegativeLimit' => [
'code' => '<?php 'code' => '<?php
/** /**
* @var string $delim * @var non-empty-string $delim
* @var string $string * @var string $string
*/ */
$elements = explode($delim, $string, -5);', $elements = explode($delim, $string, -5);',
'assertions' => [ 'assertions' => [
'$elements' => 'false|list<string>', '$elements' => 'array<never, never>',
], ],
], ],
'explodeWithDynamicDelimiterAndLimit' => [ 'explodeWithDynamicDelimiterAndLimit' => [
'code' => '<?php 'code' => '<?php
/** /**
* @var string $delim * @var non-empty-string $delim
* @var string $string * @var string $string
* @var int $limit * @var int $limit
*/ */
$elements = explode($delim, $string, $limit);', $elements = explode($delim, $string, $limit);',
'assertions' => [ 'assertions' => [
'$elements' => 'false|list<string>', '$elements' => 'array{0?: string, 1?: string, 2?: string, ...<int<0, max>, string>}',
], ],
], ],
'explodeWithDynamicNonEmptyDelimiter' => [ 'explodeWithDynamicNonEmptyDelimiter' => [
@ -502,19 +513,12 @@ class FunctionCallTest extends TestCase
'$elements' => 'non-empty-list<string>', '$elements' => 'non-empty-list<string>',
], ],
], ],
'explodeWithLiteralEmptyDelimiter' => [
'code' => '<?php
/**
* @var string $string
*/
$elements = explode("", $string);',
'assertions' => [
'$elements' => 'false',
],
],
'explodeWithPossiblyFalse' => [ 'explodeWithPossiblyFalse' => [
'code' => '<?php 'code' => '<?php
/** @return non-empty-list<string> */ /**
* @param non-empty-string $d
* @return non-empty-list<string>
*/
function exploder(string $d, string $s) : array { function exploder(string $d, string $s) : array {
return explode($d, $s); return explode($d, $s);
}', }',
@ -2232,7 +2236,7 @@ class FunctionCallTest extends TestCase
function exploder(string $s) : array { function exploder(string $s) : array {
return explode("", $s); return explode("", $s);
}', }',
'error_message' => 'FalsableReturnStatement', 'error_message' => 'InvalidArgument',
], ],
'complainAboutArrayToIterable' => [ 'complainAboutArrayToIterable' => [
'code' => '<?php 'code' => '<?php

View File

@ -1065,15 +1065,6 @@ class IssetTest extends TestCase
}', }',
'error_message' => 'InvalidArrayOffset', 'error_message' => 'InvalidArrayOffset',
], ],
'listDestructuringErrorSuppress' => [
'code' => '<?php
function foo(string $s) : string {
/** @psalm-suppress PossiblyUndefinedArrayOffset */
@list($port) = explode(":", $s, -1);
return $port;
}',
'error_message' => 'NullableReturnStatement',
],
'undefinedVarInNullCoalesce' => [ 'undefinedVarInNullCoalesce' => [
'code' => '<?php 'code' => '<?php
function bar(): void { function bar(): void {