Skip to content

Commit 3f40f5c

Browse files
committed
Reworked TypeSpecifyingExtension tests
1 parent 239291a commit 3f40f5c

21 files changed

+444
-354
lines changed

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use PHPStan\Reflection\MethodReflection;
1111
use PHPStan\Reflection\ParametersAcceptorSelector;
1212
use PHPStan\Testing\TypeInferenceTestCase;
13-
use PHPStan\Tests\AssertionClassMethodTypeSpecifyingExtension;
14-
use PHPStan\Tests\AssertionClassStaticMethodTypeSpecifyingExtension;
1513
use PHPStan\TrinaryLogic;
1614
use PHPStan\Type\Constant\ConstantBooleanType;
1715
use PHPStan\Type\Constant\ConstantFloatType;
@@ -6379,183 +6377,6 @@ public function testSpecifiedTypesUsingIsFunctions(
63796377
);
63806378
}
63816379

6382-
public function dataTypeSpecifyingExtensions(): array
6383-
{
6384-
return [
6385-
[
6386-
'string',
6387-
'$foo',
6388-
true,
6389-
],
6390-
[
6391-
'int',
6392-
'$bar',
6393-
true,
6394-
],
6395-
[
6396-
'string|null',
6397-
'$foo',
6398-
false,
6399-
],
6400-
[
6401-
'int|null',
6402-
'$bar',
6403-
false,
6404-
],
6405-
[
6406-
'string',
6407-
'$foo',
6408-
null,
6409-
],
6410-
[
6411-
'int',
6412-
'$bar',
6413-
null,
6414-
],
6415-
];
6416-
}
6417-
6418-
/**
6419-
* @dataProvider dataTypeSpecifyingExtensions
6420-
* @param string $description
6421-
* @param string $expression
6422-
* @param bool|null $nullContext
6423-
*/
6424-
public function testTypeSpecifyingExtensions(
6425-
string $description,
6426-
string $expression,
6427-
?bool $nullContext
6428-
): void
6429-
{
6430-
$this->assertTypes(
6431-
__DIR__ . '/data/type-specifying-extensions.php',
6432-
$description,
6433-
$expression,
6434-
[new AssertionClassMethodTypeSpecifyingExtension($nullContext)],
6435-
[new AssertionClassStaticMethodTypeSpecifyingExtension($nullContext)],
6436-
'die',
6437-
[],
6438-
false
6439-
);
6440-
}
6441-
6442-
public function dataTypeSpecifyingExtensions2(): array
6443-
{
6444-
return [
6445-
[
6446-
'string|null',
6447-
'$foo',
6448-
true,
6449-
],
6450-
[
6451-
'int|null',
6452-
'$bar',
6453-
true,
6454-
],
6455-
[
6456-
'string|null',
6457-
'$foo',
6458-
false,
6459-
],
6460-
[
6461-
'int|null',
6462-
'$bar',
6463-
false,
6464-
],
6465-
[
6466-
'string|null',
6467-
'$foo',
6468-
null,
6469-
],
6470-
[
6471-
'int|null',
6472-
'$bar',
6473-
null,
6474-
],
6475-
];
6476-
}
6477-
6478-
/**
6479-
* @dataProvider dataTypeSpecifyingExtensions2
6480-
* @param string $description
6481-
* @param string $expression
6482-
* @param bool|null $nullContext
6483-
*/
6484-
public function testTypeSpecifyingExtensions2(
6485-
string $description,
6486-
string $expression,
6487-
?bool $nullContext
6488-
): void
6489-
{
6490-
$this->assertTypes(
6491-
__DIR__ . '/data/type-specifying-extensions2.php',
6492-
$description,
6493-
$expression,
6494-
[new AssertionClassMethodTypeSpecifyingExtension($nullContext)],
6495-
[new AssertionClassStaticMethodTypeSpecifyingExtension($nullContext)]
6496-
);
6497-
}
6498-
6499-
public function dataTypeSpecifyingExtensions3(): array
6500-
{
6501-
return [
6502-
[
6503-
'string',
6504-
'$foo',
6505-
false,
6506-
],
6507-
[
6508-
'int',
6509-
'$bar',
6510-
false,
6511-
],
6512-
[
6513-
'string|null',
6514-
'$foo',
6515-
true,
6516-
],
6517-
[
6518-
'int|null',
6519-
'$bar',
6520-
true,
6521-
],
6522-
[
6523-
'string',
6524-
'$foo',
6525-
null,
6526-
],
6527-
[
6528-
'int',
6529-
'$bar',
6530-
null,
6531-
],
6532-
];
6533-
}
6534-
6535-
/**
6536-
* @dataProvider dataTypeSpecifyingExtensions3
6537-
* @param string $description
6538-
* @param string $expression
6539-
* @param bool|null $nullContext
6540-
*/
6541-
public function testTypeSpecifyingExtensions3(
6542-
string $description,
6543-
string $expression,
6544-
?bool $nullContext
6545-
): void
6546-
{
6547-
$this->assertTypes(
6548-
__DIR__ . '/data/type-specifying-extensions3.php',
6549-
$description,
6550-
$expression,
6551-
[new AssertionClassMethodTypeSpecifyingExtension($nullContext)],
6552-
[new AssertionClassStaticMethodTypeSpecifyingExtension($nullContext)],
6553-
'die',
6554-
[],
6555-
false
6556-
);
6557-
}
6558-
65596380
public function dataIterable(): array
65606381
{
65616382
return [
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
-
3+
class: PHPStan\Tests\AssertionClassMethodTypeSpecifyingExtension
4+
arguments:
5+
nullContext: false
6+
tags:
7+
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
8+
-
9+
class: PHPStan\Tests\AssertionClassStaticMethodTypeSpecifyingExtension
10+
arguments:
11+
nullContext: false
12+
tags:
13+
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
-
3+
class: PHPStan\Tests\AssertionClassMethodTypeSpecifyingExtension
4+
arguments:
5+
nullContext: null
6+
tags:
7+
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
8+
-
9+
class: PHPStan\Tests\AssertionClassStaticMethodTypeSpecifyingExtension
10+
arguments:
11+
nullContext: null
12+
tags:
13+
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
-
3+
class: PHPStan\Tests\AssertionClassMethodTypeSpecifyingExtension
4+
arguments:
5+
nullContext: true
6+
tags:
7+
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
8+
-
9+
class: PHPStan\Tests\AssertionClassStaticMethodTypeSpecifyingExtension
10+
arguments:
11+
nullContext: true
12+
tags:
13+
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PHPStan\Testing\TypeInferenceTestCase;
6+
7+
class TypeSpecifyingExtensionTypeInferenceFalseTest extends TypeInferenceTestCase
8+
{
9+
10+
public function dataTypeSpecifyingExtensionsFalse(): iterable
11+
{
12+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-1-false.php');
13+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-2-false.php');
14+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-3-false.php');
15+
}
16+
17+
/**
18+
* @dataProvider dataTypeSpecifyingExtensionsFalse
19+
* @param string $assertType
20+
* @param string $file
21+
* @param mixed ...$args
22+
*/
23+
public function testTypeSpecifyingExtensionsFalse(
24+
string $assertType,
25+
string $file,
26+
...$args
27+
): void
28+
{
29+
$this->assertFileAsserts($assertType, $file, ...$args);
30+
}
31+
32+
public static function getAdditionalConfigFiles(): array
33+
{
34+
return [
35+
__DIR__ . '/TypeSpecifyingExtension-false.neon',
36+
];
37+
}
38+
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PHPStan\Testing\TypeInferenceTestCase;
6+
7+
class TypeSpecifyingExtensionTypeInferenceNullTest extends TypeInferenceTestCase
8+
{
9+
10+
public function dataTypeSpecifyingExtensionsNull(): iterable
11+
{
12+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-1-null.php');
13+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-2-null.php');
14+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-3-null.php');
15+
}
16+
17+
/**
18+
* @dataProvider dataTypeSpecifyingExtensionsNull
19+
* @param string $assertType
20+
* @param string $file
21+
* @param mixed ...$args
22+
*/
23+
public function testTypeSpecifyingExtensionsNull(
24+
string $assertType,
25+
string $file,
26+
...$args
27+
): void
28+
{
29+
$this->assertFileAsserts($assertType, $file, ...$args);
30+
}
31+
32+
public static function getAdditionalConfigFiles(): array
33+
{
34+
return [
35+
__DIR__ . '/TypeSpecifyingExtension-null.neon',
36+
];
37+
}
38+
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PHPStan\Testing\TypeInferenceTestCase;
6+
7+
class TypeSpecifyingExtensionTypeInferenceTrueTest extends TypeInferenceTestCase
8+
{
9+
10+
public function dataTypeSpecifyingExtensionsTrue(): iterable
11+
{
12+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-1-true.php');
13+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-2-true.php');
14+
yield from $this->gatherAssertTypes(__DIR__ . '/data/type-specifying-extensions-3-true.php');
15+
}
16+
17+
/**
18+
* @dataProvider dataTypeSpecifyingExtensionsTrue
19+
* @param string $assertType
20+
* @param string $file
21+
* @param mixed ...$args
22+
*/
23+
public function testTypeSpecifyingExtensionsTrue(
24+
string $assertType,
25+
string $file,
26+
...$args
27+
): void
28+
{
29+
$this->assertFileAsserts($assertType, $file, ...$args);
30+
}
31+
32+
public static function getAdditionalConfigFiles(): array
33+
{
34+
return [
35+
__DIR__ . '/TypeSpecifyingExtension-true.neon',
36+
];
37+
}
38+
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use function PHPStan\Testing\assertType;
4+
5+
/** @var string|null $foo */
6+
$foo = null;
7+
/** @var int|null $bar */
8+
$bar = null;
9+
10+
(new \PHPStan\Tests\AssertionClass())->assertString($foo);
11+
$test = \PHPStan\Tests\AssertionClass::assertInt($bar);
12+
13+
assertType('string|null', $foo);
14+
assertType('int|null', $bar);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use function PHPStan\Testing\assertType;
4+
35
/** @var string|null $foo */
46
$foo = null;
57
/** @var int|null $bar */
@@ -8,4 +10,5 @@
810
(new \PHPStan\Tests\AssertionClass())->assertString($foo);
911
$test = \PHPStan\Tests\AssertionClass::assertInt($bar);
1012

11-
die;
13+
assertType('string', $foo);
14+
assertType('int', $bar);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use function PHPStan\Testing\assertType;
4+
5+
/** @var string|null $foo */
6+
$foo = null;
7+
/** @var int|null $bar */
8+
$bar = null;
9+
10+
(new \PHPStan\Tests\AssertionClass())->assertString($foo);
11+
$test = \PHPStan\Tests\AssertionClass::assertInt($bar);
12+
13+
assertType('string', $foo);
14+
assertType('int', $bar);

0 commit comments

Comments
 (0)