|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Rules\Variables; |
| 4 | + |
| 5 | +use PHPStan\Rules\Rule; |
| 6 | +use PHPStan\Testing\RuleTestCase; |
| 7 | + |
| 8 | +/** |
| 9 | + * @extends RuleTestCase<InvalidVariableAssignRule> |
| 10 | + */ |
| 11 | +class InvalidVariableAssignRuleTest extends RuleTestCase |
| 12 | +{ |
| 13 | + |
| 14 | + protected function getRule(): Rule |
| 15 | + { |
| 16 | + return new InvalidVariableAssignRule(); |
| 17 | + } |
| 18 | + |
| 19 | + public function testBug3585(): void |
| 20 | + { |
| 21 | + $this->analyse([__DIR__ . '/../Operators/data/bug-3585.php'], [ |
| 22 | + [ |
| 23 | + 'Cannot re-assign $this.', |
| 24 | + 9, |
| 25 | + ], |
| 26 | + [ |
| 27 | + 'Cannot re-assign $this.', |
| 28 | + 10, |
| 29 | + ], |
| 30 | + [ |
| 31 | + 'Cannot re-assign $this.', |
| 32 | + 11, |
| 33 | + ], |
| 34 | + [ |
| 35 | + 'Cannot re-assign $this.', |
| 36 | + 12, |
| 37 | + ], |
| 38 | + [ |
| 39 | + 'Cannot re-assign $this.', |
| 40 | + 17, |
| 41 | + ], |
| 42 | + [ |
| 43 | + 'Cannot re-assign $this.', |
| 44 | + 23, |
| 45 | + ], |
| 46 | + ]); |
| 47 | + } |
| 48 | + |
| 49 | + public function testBug14349(): void |
| 50 | + { |
| 51 | + $this->analyse([__DIR__ . '/data/bug-14349.php'], [ |
| 52 | + [ |
| 53 | + 'Cannot re-assign $this.', |
| 54 | + 11, |
| 55 | + ], |
| 56 | + [ |
| 57 | + 'Cannot re-assign $this.', |
| 58 | + 15, |
| 59 | + ], |
| 60 | + [ |
| 61 | + 'Cannot re-assign $this.', |
| 62 | + 19, |
| 63 | + ], |
| 64 | + [ |
| 65 | + 'Cannot re-assign $this.', |
| 66 | + 27, |
| 67 | + ], |
| 68 | + [ |
| 69 | + 'Cannot re-assign $this.', |
| 70 | + 28, |
| 71 | + ], |
| 72 | + [ |
| 73 | + 'Cannot re-assign $this.', |
| 74 | + 29, |
| 75 | + ], |
| 76 | + [ |
| 77 | + 'Cannot re-assign $this.', |
| 78 | + 30, |
| 79 | + ], |
| 80 | + [ |
| 81 | + 'Cannot re-assign $this.', |
| 82 | + 35, |
| 83 | + ], |
| 84 | + [ |
| 85 | + 'Cannot re-assign $this.', |
| 86 | + 42, |
| 87 | + ], |
| 88 | + ]); |
| 89 | + } |
| 90 | + |
| 91 | +} |
0 commit comments