Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 17, 2022
1 parent f816c06 commit 53e3889
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
10 changes: 5 additions & 5 deletions tests/CoreStubsTest.php
Expand Up @@ -34,7 +34,7 @@ public function providerValidCodeParse(): iterable
'php_version' => '8.0',
];
yield 'Iterating over \DatePeriod (#5954) PHP7 Traversable' => [
'<?php
'code' => '<?php
$period = new DatePeriod(
new DateTimeImmutable("now"),
Expand All @@ -53,7 +53,7 @@ public function providerValidCodeParse(): iterable
'php_version' => '7.3',
];
yield 'Iterating over \DatePeriod (#5954) PHP8 IteratorAggregate' => [
'<?php
'code' => '<?php
$period = new DatePeriod(
new DateTimeImmutable("now"),
Expand All @@ -72,7 +72,7 @@ public function providerValidCodeParse(): iterable
'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;
Expand All @@ -87,7 +87,7 @@ public function providerValidCodeParse(): iterable
'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) {}',
Expand All @@ -96,7 +96,7 @@ public function providerValidCodeParse(): iterable
'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) {}',
Expand Down
72 changes: 36 additions & 36 deletions tests/FileManipulation/ThrowsBlockAdditionTest.php
Expand Up @@ -5,20 +5,20 @@
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
*/
Expand All @@ -28,12 +28,12 @@ function foo(string $s): string {
}
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();
Expand All @@ -43,7 +43,7 @@ function foo(string $s): string {
}
return $s;
}',
'<?php
'output' => '<?php
/**
* @throws InvalidArgumentException|DomainException
*/
Expand All @@ -56,12 +56,12 @@ function foo(string $s): string {
}
return $s;
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
'preservesExistingThrowsAnnotationToFunction' => [
'<?php
'input' => '<?php
/**
* @throws InvalidArgumentException|DomainException
*/
Expand All @@ -71,7 +71,7 @@ function foo(string $s): string {
}
return $s;
}',
'<?php
'output' => '<?php
/**
* @throws InvalidArgumentException|DomainException
* @throws Exception
Expand All @@ -82,12 +82,12 @@ function foo(string $s): string {
}
return $s;
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
'doesNotAddDuplicateThrows' => [
'<?php
'input' => '<?php
/**
* @throws InvalidArgumentException
*/
Expand All @@ -100,7 +100,7 @@ function foo(string $s): string {
}
return $s;
}',
'<?php
'output' => '<?php
/**
* @throws InvalidArgumentException
* @throws DomainException
Expand All @@ -114,20 +114,20 @@ function foo(string $s): string {
}
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) {
throw new \InvalidArgumentException();
}
return $s;
}',
'<?php
'output_type' => '<?php
namespace Foo;
/**
* @throws \InvalidArgumentException
Expand All @@ -138,12 +138,12 @@ function foo(string $s): string {
}
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();
Expand All @@ -158,7 +158,7 @@ function bar(): void {
throw new BarException();
}
}',
'<?php
'output_type' => '<?php
namespace Foo {
/**
* @throws \Bar\BarException
Expand All @@ -176,12 +176,12 @@ function bar(): void {
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 {
Expand All @@ -197,7 +197,7 @@ function bar(): void {
namespace Bar {
class BarException extends \DomainException {}
}',
'<?php
'output_type' => '<?php
namespace Foo {
use Bar\BarException;
/**
Expand All @@ -216,9 +216,9 @@ function bar(): void {
namespace Bar {
class BarException extends \DomainException {}
}',
'7.4',
['MissingThrowsDocblock'],
true,
'php_version' => '7.4',
'issues_to_fix' => ['MissingThrowsDocblock'],
'safe_types' => true,
],
];
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ReturnTypeProvider/ArrayColumnTest.php
Expand Up @@ -65,7 +65,7 @@ function f(array $shape): array {
];

yield 'arrayColumnWithObjectsAndColumnNameNull' => [
'<?php
'code' => '<?php
class C {
/** @var string */
public $name = "";
Expand All @@ -79,7 +79,7 @@ public function foo(): void {}
];

yield 'arrayColumnWithIntersectionAndColumnNameNull' => [
'<?php
'code' => '<?php
interface I {
public function foo(): void;
}
Expand All @@ -103,7 +103,7 @@ public function bar(): void {}
];

yield 'arrayColumnWithArrayAndColumnNameNull' => [
'<?php
'code' => '<?php
class C {
/** @var string */
public $name = "";
Expand All @@ -117,7 +117,7 @@ public function foo(): void {}
];

yield 'arrayColumnWithListOfObject' => [
'<?php
'code' => '<?php
function foo(object $object): void {}
/** @var list<object> $instances */
Expand All @@ -129,7 +129,7 @@ function foo(object $object): void {}
];

yield 'arrayColumnWithListOfArrays' => [
'<?php
'code' => '<?php
function foo(array $array): void {}
/** @var list<array> $arrays */
Expand All @@ -144,7 +144,7 @@ function foo(array $array): void {}
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) {
Expand Down
12 changes: 6 additions & 6 deletions tests/ReturnTypeProvider/MinMaxReturnTypeProviderTest.php
Expand Up @@ -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) {
Expand All @@ -44,7 +44,7 @@ public function providerValidCodeParse(): iterable
$min = min($h0, $h1);
$max = max($h0, $h1);
',
[
'assertions' => [
'$min' => 'int<0, max>',
'$max' => 'int<0, max>',
],
Expand Down

0 comments on commit 53e3889

Please sign in to comment.