Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusted testcases for better pipe plugin #372

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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": "^2.2",
"php-coveralls/php-coveralls": "^2.5.2",
"roave/infection-static-analysis-plugin": "^1.26.0"
},
Expand Down
26 changes: 13 additions & 13 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, 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, 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
veewee marked this conversation as resolved.
Show resolved Hide resolved
{
$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');
}