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

Add failing test case for unions #10

Open
wants to merge 1 commit into
base: 1.0.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add failing test case for unions
Seems unions for scalars with additional data (non-empty) lose
their extra data
BackEndTea committed Sep 25, 2022
commit 7ce66d4de8159a5a19de2dc7b87000c400915e8e
1 change: 1 addition & 0 deletions tests/Type/PslTypeSpecifyingExtensionTest.php
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/coerce.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/assert.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/matches.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9.php');
if (InstalledVersions::satisfies(new VersionParser(), 'azjezz/psl', '<2.0.0')) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/complexTypev1.php');
} else {
42 changes: 42 additions & 0 deletions tests/Type/data/bug-9.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace PslBug9Test;

use Psl\Type;
use function PHPStan\Testing\assertType;

/**
* @param mixed $input
*/
function checkShape($input): void
{
$output = Type\shape([
'foo' => Type\non_empty_string(),
'bar' => Type\nullable(Type\non_empty_string()),
'baz' => Type\optional(Type\non_empty_string()),
'other' => Type\union(Type\non_empty_string(), Type\positive_int())
])->coerce($input);

assertType('array{foo: non-empty-string, bar: non-empty-string|null, baz?: non-empty-string, other: int<1, max>|non-empty_string}', $output);
}


/**
* @param mixed $input
*/
function checkNoShape($input): void
{
$output = Type\union(Type\non_empty_string(), Type\positive_int())->coerce($input);

assertType('int<1, max>|non-empty-string', $output);
}

/**
* @param mixed $input
*/
function checkNoUnion($input): void
{
$output = Type\non_empty_string()->assert($input);

assertType('non-empty-string', $output);
}