File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 22
33namespace PHPStan \Type \Nette ;
44
5+ use Composer \InstalledVersions ;
6+ use OutOfBoundsException ;
57use PHPStan \Testing \TypeInferenceTestCase ;
8+ use function class_exists ;
9+ use function version_compare ;
610
711class 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 /**
Original file line number Diff line number Diff line change 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 );
You can’t perform that action at this time.
0 commit comments