Skip to content

Commit a547291

Browse files
committed
Add test for variable description
1 parent 7892ac6 commit a547291

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/PHPStan/Testing/TypeInferenceTestCaseTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\File\FileHelper;
66
use PHPUnit\Framework\AssertionFailedError;
7+
use function array_values;
78
use function sprintf;
89

910
final class TypeInferenceTestCaseTest extends TypeInferenceTestCase
@@ -90,4 +91,14 @@ public function testFileAssertionFailedErrors(string $filePath, string $errorMes
9091
$this->gatherAssertTypes($filePath);
9192
}
9293

94+
public function testVariableOrOffsetDescription(): void
95+
{
96+
$filePath = __DIR__ . '/data/assert-certainty-variable-or-offset.php';
97+
98+
[$variableAssert, $offsetAssert] = array_values($this->gatherAssertTypes($filePath));
99+
100+
$this->assertSame('variable $context', $variableAssert[4]);
101+
$this->assertSame("offset 'email'", $offsetAssert[4]);
102+
}
103+
93104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace AssertCertaintyVariableOrOffset;
4+
5+
use PHPStan\TrinaryLogic;
6+
use function PHPStan\Testing\assertVariableCertainty;
7+
8+
/**
9+
* @param array{} $context
10+
*/
11+
function someMethod(array $context) : void
12+
{
13+
assertVariableCertainty(TrinaryLogic::createNo(), $context);
14+
assertVariableCertainty(TrinaryLogic::createYes(), $context['email']);
15+
}

0 commit comments

Comments
 (0)