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

Sign up
Appearance settings

Commit 84328de

Browse files
committed
Add failing tests for MissingReadOnlyPropertyAssignRule
1 parent 2879e5f commit 84328de

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Properties;
4+
5+
use PHPStan\Rules\Rule;
6+
use PHPStan\Testing\RuleTestCase;
7+
8+
/**
9+
* @extends RuleTestCase<MissingReadOnlyByPhpDocPropertyAssignRule>
10+
*/
11+
class MissingReadOnlyByPhpDocPropertyAssignRuleTest extends RuleTestCase
12+
{
13+
14+
protected function getRule(): Rule
15+
{
16+
return self::getContainer()->getByType(MissingReadOnlyByPhpDocPropertyAssignRule::class);
17+
}
18+
19+
public static function getAdditionalConfigFiles(): array
20+
{
21+
return [__DIR__ . '/../../../extension.neon'];
22+
}
23+
24+
public function testRule(): void
25+
{
26+
$this->analyse([__DIR__ . '/data/missing-readonly-property-assign-phpdoc.php'], []);
27+
}
28+
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Properties;
4+
5+
use PHPStan\Rules\Rule;
6+
use PHPStan\Testing\RuleTestCase;
7+
use const PHP_VERSION_ID;
8+
9+
/**
10+
* @extends RuleTestCase<MissingReadOnlyPropertyAssignRule>
11+
*/
12+
class MissingReadOnlyPropertyAssignRuleTest extends RuleTestCase
13+
{
14+
15+
protected function getRule(): Rule
16+
{
17+
return self::getContainer()->getByType(MissingReadOnlyPropertyAssignRule::class);
18+
}
19+
20+
public static function getAdditionalConfigFiles(): array
21+
{
22+
return [__DIR__ . '/../../../extension.neon'];
23+
}
24+
25+
public function testRule(): void
26+
{
27+
if (PHP_VERSION_ID < 80100) {
28+
self::markTestSkipped('Test requires PHP 8.1.');
29+
}
30+
31+
$this->analyse([__DIR__ . '/data/missing-readonly-property-assign.php'], []);
32+
}
33+
34+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php // lint >= 7.4
2+
3+
namespace MissingReadOnlyPropertyAssignPhpDoc;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Entity
9+
*/
10+
class Entity
11+
{
12+
13+
/**
14+
* @ORM\Id
15+
* @ORM\GeneratedValue
16+
* @ORM\Column
17+
* @readonly
18+
*/
19+
private int $id; // ok because of PropertiesExtension
20+
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php // lint >= 8.1
2+
3+
namespace MissingReadOnlyPropertyAssign;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
#[ORM\Entity]
8+
class Entity
9+
{
10+
11+
#[ORM\Id]
12+
#[ORM\GeneratedValue]
13+
#[ORM\Column]
14+
private readonly int $id; // ok because of PropertiesExtension
15+
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /