Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4a905b

Browse filesBrowse files
committed
Additional test for detecting types from traits
1 parent 457195d commit f4a905b
Copy full SHA for f4a905b

File tree

Expand file treeCollapse file tree

3 files changed

+55
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+55
-0
lines changed

‎tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php

Copy file name to clipboardExpand all lines: tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ public function testDuplicateMethodDefinition(): void
117117
$this->assertCount(0, $errors);
118118
}
119119

120+
public function testWrongPropertyType(): void
121+
{
122+
$errors = $this->runAnalyse([__DIR__ . '/traits/wrongProperty/Foo.php']);
123+
$this->assertCount(2, $errors);
124+
$this->assertSame(15, $errors[0]->getLine());
125+
$this->assertSame(
126+
$this->fileHelper->normalizePath(__DIR__ . '/traits/wrongProperty/Foo.php'),
127+
$errors[0]->getFile()
128+
);
129+
$this->assertSame('Property TraitsWrongProperty\Foo::$id (int) does not accept string.', $errors[0]->getMessage());
130+
131+
$this->assertSame(17, $errors[1]->getLine());
132+
$this->assertSame(
133+
$this->fileHelper->normalizePath(__DIR__ . '/traits/wrongProperty/Foo.php'),
134+
$errors[1]->getFile()
135+
);
136+
$this->assertSame('Property TraitsWrongProperty\Foo::$bar (Ipsum) does not accept int(1).', $errors[1]->getMessage());
137+
}
138+
120139
/**
121140
* @param string[] $files
122141
* @return \PHPStan\Analyser\Error[]
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace TraitsWrongProperty;
4+
5+
use Lorem as Bar;
6+
7+
class Foo
8+
{
9+
10+
use FooTrait;
11+
12+
public function doFoo()
13+
{
14+
$this->id = 1;
15+
$this->id = 'foo';
16+
17+
$this->bar = 1;
18+
}
19+
20+
}
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace TraitsWrongProperty;
4+
5+
use Ipsum as Bar;
6+
7+
trait FooTrait
8+
{
9+
10+
/** @var int */
11+
private $id;
12+
13+
/** @var Bar */
14+
private $bar;
15+
16+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.