| @@ 16-89 (lines=74) @@ | ||
| 13 | * @package PHPCompatibility |
|
| 14 | * @author Wim Godden <[email protected]> |
|
| 15 | */ |
|
| 16 | class ForbiddenNegativeBitshiftSniffTest extends BaseSniffTest |
|
| 17 | { |
|
| 18 | const TEST_FILE = 'sniff-examples/forbidden_negative_bitshift.php'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * testForbiddenNegativeBitshift |
|
| 22 | * |
|
| 23 | * @group forbiddenNegativeBitshift |
|
| 24 | * |
|
| 25 | * @dataProvider dataForbiddenNegativeBitshift |
|
| 26 | * |
|
| 27 | * @param int $line Line number where the error should occur. |
|
| 28 | * |
|
| 29 | * @return void |
|
| 30 | */ |
|
| 31 | public function testForbiddenNegativeBitshift($line) |
|
| 32 | { |
|
| 33 | $file = $this->sniffFile(self::TEST_FILE, '5.6'); |
|
| 34 | $this->assertNoViolation($file, $line); |
|
| 35 | ||
| 36 | $file = $this->sniffFile(self::TEST_FILE, '7.0'); |
|
| 37 | $this->assertError($file, $line, 'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0'); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * dataForbiddenNegativeBitshift |
|
| 42 | * |
|
| 43 | * @see testForbiddenNegativeBitshift() |
|
| 44 | * |
|
| 45 | * @return array |
|
| 46 | */ |
|
| 47 | public function dataForbiddenNegativeBitshift() { |
|
| 48 | return array( |
|
| 49 | array(3), |
|
| 50 | array(4), |
|
| 51 | ); |
|
| 52 | } |
|
| 53 | ||
| 54 | ||
| 55 | /** |
|
| 56 | * testNoViolation |
|
| 57 | * |
|
| 58 | * @group forbiddenNegativeBitshift |
|
| 59 | * |
|
| 60 | * @dataProvider dataNoViolation |
|
| 61 | * |
|
| 62 | * @param int $line The line number. |
|
| 63 | * |
|
| 64 | * @return void |
|
| 65 | */ |
|
| 66 | public function testNoViolation($line) |
|
| 67 | { |
|
| 68 | $file = $this->sniffFile(self::TEST_FILE, '7.0'); |
|
| 69 | $this->assertNoViolation($file, $line); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * Data provider. |
|
| 74 | * |
|
| 75 | * @see testNoViolation() |
|
| 76 | * |
|
| 77 | * @return array |
|
| 78 | */ |
|
| 79 | public function dataNoViolation() |
|
| 80 | { |
|
| 81 | return array( |
|
| 82 | array(6), |
|
| 83 | array(7), |
|
| 84 | array(8), |
|
| 85 | //array(9), - currently gives a false positive, @todo: uncomment when fixed. |
|
| 86 | array(12), |
|
| 87 | ); |
|
| 88 | } |
|
| 89 | } |
|
| 90 | ||
| 91 | ||
| @@ 16-89 (lines=74) @@ | ||
| 13 | * @package PHPCompatibility |
|
| 14 | * @author Jansen Price <[email protected]> |
|
| 15 | */ |
|
| 16 | class ForbiddenSwitchWithMultipleDefaultBlocksSniffTest extends BaseSniffTest |
|
| 17 | { |
|
| 18 | const TEST_FILE = 'sniff-examples/forbidden_switch_with_multiple_default_blocks.php'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * testForbiddenSwitchWithMultipleDefaultBlocks |
|
| 22 | * |
|
| 23 | * @group forbiddenSwitchMultipleDefault |
|
| 24 | * |
|
| 25 | * @dataProvider dataForbiddenSwitchWithMultipleDefaultBlocks |
|
| 26 | * |
|
| 27 | * @param int $line The line number. |
|
| 28 | * |
|
| 29 | * @return void |
|
| 30 | */ |
|
| 31 | public function testForbiddenSwitchWithMultipleDefaultBlocks($line) |
|
| 32 | { |
|
| 33 | $file = $this->sniffFile(self::TEST_FILE, '5.6'); |
|
| 34 | $this->assertNoViolation($file, $line); |
|
| 35 | ||
| 36 | $file = $this->sniffFile(self::TEST_FILE, '7.0'); |
|
| 37 | $this->assertError($file, $line, 'Switch statements can not have multiple default blocks since PHP 7.0'); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Data provider. |
|
| 42 | * |
|
| 43 | * @see testForbiddenSwitchWithMultipleDefaultBlocks() |
|
| 44 | * |
|
| 45 | * @return array |
|
| 46 | */ |
|
| 47 | public function dataForbiddenSwitchWithMultipleDefaultBlocks() |
|
| 48 | { |
|
| 49 | return array( |
|
| 50 | array(3), |
|
| 51 | array(47), |
|
| 52 | array(56), |
|
| 53 | ); |
|
| 54 | } |
|
| 55 | ||
| 56 | ||
| 57 | /** |
|
| 58 | * testValidSwitchStatement |
|
| 59 | * |
|
| 60 | * @group forbiddenSwitchMultipleDefault |
|
| 61 | * |
|
| 62 | * @dataProvider dataValidSwitchStatement |
|
| 63 | * |
|
| 64 | * @param int $line The line number. |
|
| 65 | * |
|
| 66 | * @return void |
|
| 67 | */ |
|
| 68 | public function testValidSwitchStatement($line) |
|
| 69 | { |
|
| 70 | $file = $this->sniffFile(self::TEST_FILE, '7.0'); |
|
| 71 | $this->assertNoViolation($file, $line); |
|
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * Data provider. |
|
| 76 | * |
|
| 77 | * @see testValidSwitchStatement() |
|
| 78 | * |
|
| 79 | * @return array |
|
| 80 | */ |
|
| 81 | public function dataValidSwitchStatement() |
|
| 82 | { |
|
| 83 | return array( |
|
| 84 | array(14), |
|
| 85 | array(23), |
|
| 86 | array(43), |
|
| 87 | ); |
|
| 88 | } |
|
| 89 | } |
|
| 90 | ||
| 91 | ||