Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions tests/Type/PslTypeSpecifyingExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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);
}