1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00
This commit is contained in:
Daniil Gentili 2022-10-17 10:21:26 +02:00
parent f816c06331
commit 53e3889745
4 changed files with 53 additions and 53 deletions

View File

@ -34,7 +34,7 @@ class CoreStubsTest extends TestCase
'php_version' => '8.0',
];
yield 'Iterating over \DatePeriod (#5954) PHP7 Traversable' => [
'<?php
'code' => '<?php
$period = new DatePeriod(
new DateTimeImmutable("now"),
@ -53,7 +53,7 @@ class CoreStubsTest extends TestCase
'php_version' => '7.3',
];
yield 'Iterating over \DatePeriod (#5954) PHP8 IteratorAggregate' => [
'<?php
'code' => '<?php
$period = new DatePeriod(
new DateTimeImmutable("now"),
@ -72,7 +72,7 @@ class CoreStubsTest extends TestCase
'php_version' => '8.0',
];
yield 'Iterating over \DatePeriod (#5954), ISO string' => [
'<?php
'code' => '<?php
$period = new DatePeriod("R4/2012-07-01T00:00:00Z/P7D");
$dt = null;
@ -87,7 +87,7 @@ class CoreStubsTest extends TestCase
'php_version' => '8.0',
];
yield 'DatePeriod implements only Traversable on PHP 7' => [
'<?php
'code' => '<?php
$period = new DatePeriod("R4/2012-07-01T00:00:00Z/P7D");
if ($period instanceof IteratorAggregate) {}',
@ -96,7 +96,7 @@ class CoreStubsTest extends TestCase
'php_version' => '7.3',
];
yield 'DatePeriod implements IteratorAggregate on PHP 8' => [
'<?php
'code' => '<?php
$period = new DatePeriod("R4/2012-07-01T00:00:00Z/P7D");
if ($period instanceof IteratorAggregate) {}',

View File

@ -5,20 +5,20 @@ namespace Psalm\Tests\FileManipulation;
class ThrowsBlockAdditionTest extends FileManipulationTestCase
{
/**
* @return array<string,array{string,string,string,string[],bool}>
* @return array<string,array{input:string,output:string,php_version:string,issues_to_fix:string[],safe_types:bool}>
*/
public function providerValidCodeParse(): array
{
return [
'addThrowsAnnotationToFunction' => [
'<?php
'input' => '<?php
function foo(string $s): string {
if("" === $s) {
throw new \InvalidArgumentException();
}
return $s;
}',
'<?php
'output' => '<?php
/**
* @throws InvalidArgumentException
*/
@ -28,12 +28,12 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
'addMultipleThrowsAnnotationToFunction' => [
'<?php
'input' => '<?php
function foo(string $s): string {
if("" === $s) {
throw new \InvalidArgumentException();
@ -43,7 +43,7 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'<?php
'output' => '<?php
/**
* @throws InvalidArgumentException|DomainException
*/
@ -56,12 +56,12 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
'preservesExistingThrowsAnnotationToFunction' => [
'<?php
'input' => '<?php
/**
* @throws InvalidArgumentException|DomainException
*/
@ -71,7 +71,7 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'<?php
'output' => '<?php
/**
* @throws InvalidArgumentException|DomainException
* @throws Exception
@ -82,12 +82,12 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
'doesNotAddDuplicateThrows' => [
'<?php
'input' => '<?php
/**
* @throws InvalidArgumentException
*/
@ -100,7 +100,7 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'<?php
'output' => '<?php
/**
* @throws InvalidArgumentException
* @throws DomainException
@ -114,12 +114,12 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
'addThrowsAnnotationToFunctionInNamespace' => [
'<?php
'input_type' => '<?php
namespace Foo;
function foo(string $s): string {
if("" === $s) {
@ -127,7 +127,7 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'<?php
'output_type' => '<?php
namespace Foo;
/**
* @throws \InvalidArgumentException
@ -138,12 +138,12 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
}
return $s;
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
'addThrowsAnnotationToFunctionFromFunctionFromOtherNamespace' => [
'<?php
'input_type' => '<?php
namespace Foo {
function foo(): void {
\Bar\bar();
@ -158,7 +158,7 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
throw new BarException();
}
}',
'<?php
'output_type' => '<?php
namespace Foo {
/**
* @throws \Bar\BarException
@ -176,12 +176,12 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
throw new BarException();
}
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
'addThrowsAnnotationAccountsForUseStatements' => [
'<?php
'input_type' => '<?php
namespace Foo {
use Bar\BarException;
function foo(): void {
@ -197,7 +197,7 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
namespace Bar {
class BarException extends \DomainException {}
}',
'<?php
'output_type' => '<?php
namespace Foo {
use Bar\BarException;
/**
@ -216,9 +216,9 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase
namespace Bar {
class BarException extends \DomainException {}
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
];
}

View File

@ -65,7 +65,7 @@ class ArrayColumnTest extends TestCase
];
yield 'arrayColumnWithObjectsAndColumnNameNull' => [
'<?php
'code' => '<?php
class C {
/** @var string */
public $name = "";
@ -79,7 +79,7 @@ class ArrayColumnTest extends TestCase
];
yield 'arrayColumnWithIntersectionAndColumnNameNull' => [
'<?php
'code' => '<?php
interface I {
public function foo(): void;
}
@ -103,7 +103,7 @@ class ArrayColumnTest extends TestCase
];
yield 'arrayColumnWithArrayAndColumnNameNull' => [
'<?php
'code' => '<?php
class C {
/** @var string */
public $name = "";
@ -117,7 +117,7 @@ class ArrayColumnTest extends TestCase
];
yield 'arrayColumnWithListOfObject' => [
'<?php
'code' => '<?php
function foo(object $object): void {}
/** @var list<object> $instances */
@ -129,7 +129,7 @@ class ArrayColumnTest extends TestCase
];
yield 'arrayColumnWithListOfArrays' => [
'<?php
'code' => '<?php
function foo(array $array): void {}
/** @var list<array> $arrays */
@ -144,7 +144,7 @@ class ArrayColumnTest extends TestCase
public function providerInvalidCodeParse(): iterable
{
yield 'arrayColumnWithArrayAndColumnNameNull' => [
'<?php
'code' => '<?php
/** @var list<array{name: string, instance: object}> $arrays */
$arrays = [];
foreach (array_column($arrays, null, "name") as $array) {

View File

@ -12,27 +12,27 @@ class MinMaxReturnTypeProviderTest extends TestCase
public function providerValidCodeParse(): iterable
{
yield 'literalInt' => [
'<?php
'code' => '<?php
$min = min(1, 2);
$max = max(3, 4);
',
[
'assertions' => [
'$min' => 'int',
'$max' => 'int',
],
];
yield 'nonInt' => [
'<?php
'code' => '<?php
$min = min("a", "b");
$max = max("x", "y");
',
[
'assertions' => [
'$min' => 'string',
'$max' => 'string',
],
];
yield 'maxIntRange' => [
'<?php
'code' => '<?php
$headers = fgetcsv(fopen("test.txt", "r"));
$h0 = $h1 = null;
foreach($headers as $i => $v) {
@ -44,7 +44,7 @@ class MinMaxReturnTypeProviderTest extends TestCase
$min = min($h0, $h1);
$max = max($h0, $h1);
',
[
'assertions' => [
'$min' => 'int<0, max>',
'$max' => 'int<0, max>',
],