|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Rules\Keywords; |
| 4 | + |
| 5 | +use PHPStan\Node\Printer\ExprPrinter; |
| 6 | +use PHPStan\Node\Printer\Printer; |
| 7 | +use PHPStan\Rules\Rule; |
| 8 | +use PHPStan\Testing\RuleTestCase; |
| 9 | + |
| 10 | +/** |
| 11 | + * @extends RuleTestCase<DeclareStrictTypesRule> |
| 12 | + */ |
| 13 | +class DeclareStrictTypesRuleTest extends RuleTestCase |
| 14 | +{ |
| 15 | + |
| 16 | +protected function getRule(): Rule |
| 17 | +{ |
| 18 | +return new DeclareStrictTypesRule(new ExprPrinter(new Printer())); |
| 19 | +} |
| 20 | + |
| 21 | +public function testRule(): void |
| 22 | +{ |
| 23 | +$this->analyse([__DIR__ . '/data/declare-position.php'], [ |
| 24 | +[ |
| 25 | +'Declare strict_types must be the very first statement.', |
| 26 | +5, |
| 27 | +], |
| 28 | +]); |
| 29 | +} |
| 30 | + |
| 31 | +public function testRule2(): void |
| 32 | +{ |
| 33 | +$this->analyse([__DIR__ . '/data/declare-position2.php'], [ |
| 34 | +[ |
| 35 | +'Declare strict_types must be the very first statement.', |
| 36 | +1, |
| 37 | +], |
| 38 | +]); |
| 39 | +} |
| 40 | + |
| 41 | +public function testNested(): void |
| 42 | +{ |
| 43 | +$this->analyse([__DIR__ . '/data/declare-position-nested.php'], [ |
| 44 | +[ |
| 45 | +'Declare strict_types must be the very first statement.', |
| 46 | +7, |
| 47 | +], |
| 48 | +[ |
| 49 | +'Declare strict_types must be the very first statement.', |
| 50 | +12, |
| 51 | +], |
| 52 | +]); |
| 53 | +} |
| 54 | + |
| 55 | +public function testValidPosition(): void |
| 56 | +{ |
| 57 | +$this->analyse([__DIR__ . '/data/declare-position-valid.php'], []); |
| 58 | +} |
| 59 | + |
| 60 | +public function testTicks(): void |
| 61 | +{ |
| 62 | +$this->analyse([__DIR__ . '/data/declare-ticks.php'], []); |
| 63 | +} |
| 64 | + |
| 65 | +public function testMulti(): void |
| 66 | +{ |
| 67 | +$this->analyse([__DIR__ . '/data/declare-multi.php'], []); |
| 68 | +} |
| 69 | + |
| 70 | +public function testNonsense(): void |
| 71 | +{ |
| 72 | +$this->analyse([__DIR__ . '/data/declare-strict-nonsense.php'], [ |
| 73 | +[ |
| 74 | +"Declare strict_types must have 0 or 1 as its value, 'foo' given.", |
| 75 | +1, |
| 76 | +], |
| 77 | +]); |
| 78 | +} |
| 79 | + |
| 80 | +public function testNonsenseBool(): void |
| 81 | +{ |
| 82 | +$this->analyse([__DIR__ . '/data/declare-strict-nonsense-bool.php'], [ |
| 83 | +[ |
| 84 | +'Declare strict_types must have 0 or 1 as its value, \true given.', |
| 85 | +1, |
| 86 | +], |
| 87 | +]); |
| 88 | +} |
| 89 | + |
| 90 | +} |
0 commit comments