Skip to content

Commit

Permalink
Adjusted testcases for better pipe plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Dec 5, 2022
1 parent 82f241e commit 1a96de5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 48 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"phpbench/phpbench": "^1.2.3",
"phpunit/phpunit": "^9.5.16",
"vimeo/psalm": "^5.0.0",
"php-standard-library/psalm-plugin": "^2.1.0",
"php-standard-library/psalm-plugin": "dev-better-pipe",
"php-coveralls/php-coveralls": "^2.5.2",
"roave/infection-static-analysis-plugin": "^1.26.0"
},
Expand Down Expand Up @@ -57,5 +57,11 @@
},
"suggest": {
"php-standard-library/psalm-plugin": "Psalm integration"
}
},
"repositories": [
{
"type": "git",
"url": "https://github.com/veewee/psalm-plugin.git"
}
]
}
64 changes: 41 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Psl/IO/streaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @throws Exception\RuntimeException If an error occurred during the operation.
* @throws Exception\TimeoutException If $timeout is reached before being able to read all the handles until the end.
*
* @return Generator<T, string, mixed, void>
* @return Generator<T, string, mixed, null>
*/
function streaming(iterable $handles, ?float $timeout = null): Generator
{
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Network/ServerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function nextConnection(): SocketInterface;
*
* @throws Exception\RuntimeException In case failed to accept incoming connection.
*
* @return Generator<null, SocketInterface, void, void>
* @return Generator<null, SocketInterface, void, void|null>
*/
public function incoming(): Generator;

Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Network/StreamServerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function nextConnection(): StreamSocketInterface;
/**
* {@inheritDoc}
*
* @return Generator<null, StreamSocketInterface, void, void>
* @return Generator<null, StreamSocketInterface, void, void|null>
*/
public function incoming(): Generator;
}
39 changes: 19 additions & 20 deletions tests/static-analysis/Fun/pipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,36 @@

use function Psl\Fun\pipe;

/**
* @psalm-suppress TooFewArguments, UnusedClosureParam
*/
function test_too_few_argument_count_issues(): void
function test_too_few_argument_dont_matter(): int
{
$stages = pipe(
static fn (): int => 2,
);
$stages('hello');

return $stages('hello');
}

/**
* @psalm-suppress TooManyArguments, UnusedClosureParam, InvalidArgument
* @psalm-suppress InvalidArgument, UnusedClosureParam
*/
function test_too_many_argument_count_issues(): void
function test_too_many_argument_count_issues(): int
{
$stages = pipe(
static fn (string $x, string $y): int => 2,
);
$stages('hello');
return $stages('hello');
}

/**
* @psalm-suppress UnusedClosureParam, InvalidArgument
* @psalm-suppress UnusedClosureParam
*/
function test_variadic_and_default_params(): void
function test_variadic_and_default_params(): int
{
$stages = pipe(
static fn (int $y, string $x = 'hello'): float => 1.2,
static fn (float ...$items): int => 23
);
$stages('hello');
return $stages(123);
}

/**
Expand All @@ -46,11 +44,12 @@ function test_variadic_and_default_params(): void
* @see https://github.com/vimeo/psalm/issues/7244
*
* @psalm-suppress InvalidArgument
* @psalm-suppress NoValue - Resolves into "\Closure(never): never" because of the issue linked above.
*/
function test_empty_pipe(): void
function test_empty_pipe(): string
{
$stages = pipe();
$stages('hello');
return $stages('hello');
}

/**
Expand All @@ -66,27 +65,27 @@ function test_invalid_arguments(): void
}

/**
* @psalm-suppress UnusedClosureParam, InvalidArgument
* @psalm-suppress InvalidScalarArgument, UnusedClosureParam
*/
function test_invalid_return_to_input_type(): void
function test_invalid_return_to_input_type(): float
{
$stages = pipe(
static fn (string $x): int => 2,
static fn (string $y): float => 1.2
);
$stages('hello');
return $stages('hello');
}

/**
* @psalm-suppress UnusedClosureParam, InvalidArgument
*/
function test_invalid_input_type(): void
function test_invalid_input_type(): float
{
$stages = pipe(
static fn (string $x): int => 2,
static fn (int $y): float => 1.2
);
$stages(143);
return $stages(143);
}

/**
Expand All @@ -106,11 +105,11 @@ function test_output_type_is_known(): void
/**
* @psalm-suppress UnusedClosureParam
*/
function test_currently_unparsed_input_types(): void
function test_first_class_callables(): int
{
$stages = pipe(
$assignment = static fn (string $x): int => 2,
(static fn (): int => 2)(...),
);
$stages('hello');
return $stages('hello');
}

0 comments on commit 1a96de5

Please sign in to comment.