Skip to content

Commit 2ab207e

Browse files
committed
Tests for nullable Multiplier
1 parent 3320991 commit 2ab207e

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

tests/Type/Nette/MultiplierTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,30 @@
22

33
namespace PHPStan\Type\Nette;
44

5+
use Composer\InstalledVersions;
6+
use OutOfBoundsException;
57
use PHPStan\Testing\TypeInferenceTestCase;
8+
use function class_exists;
9+
use function version_compare;
610

711
class MultiplierTest extends TypeInferenceTestCase
812
{
913

1014
public function dataFileAsserts(): iterable
1115
{
12-
yield from self::gatherAssertTypes(__DIR__ . '/data/multiplier.php');
16+
try {
17+
$applicationVersion = class_exists(InstalledVersions::class)
18+
? InstalledVersions::getVersion('nette/application')
19+
: null;
20+
} catch (OutOfBoundsException $e) {
21+
$applicationVersion = null;
22+
}
23+
24+
if ($applicationVersion !== null && version_compare($applicationVersion, '3.2.5', '>=')) {
25+
yield from self::gatherAssertTypes(__DIR__ . '/data/multiplierApplication325.php');
26+
} else {
27+
yield from self::gatherAssertTypes(__DIR__ . '/data/multiplier.php');
28+
}
1329
}
1430

1531
/**
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types = 1);
2+
3+
use Nette\Application\UI\Form;
4+
use Nette\Application\UI\Multiplier;
5+
6+
use function PHPStan\Testing\assertType;
7+
8+
/** @var Multiplier<Form|null> $multiplier */
9+
$multiplier = new Multiplier(function (string $name): ?Form {
10+
if($name === 'foo') {
11+
return new Form();
12+
} else {
13+
return null;
14+
}
15+
});
16+
17+
assertType('Nette\Application\UI\Multiplier<Nette\Application\UI\Form|null>', $multiplier);
18+
19+
$form = $multiplier->createComponent('foo');
20+
21+
assertType(Form::class . '|null', $form);

0 commit comments

Comments
 (0)