|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Unit test class for the ESLint sniff. |
| 4 | + * |
| 5 | + * @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl> |
| 6 | + * @copyright 2019 Juliette Reinders Folmer. All rights reserved. |
| 7 | + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PHP_CodeSniffer\Standards\Generic\Tests\Debug; |
| 11 | + |
| 12 | +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; |
| 13 | +use PHP_CodeSniffer\Config; |
| 14 | + |
| 15 | +class ESLintUnitTest extends AbstractSniffUnitTest |
| 16 | +{ |
| 17 | + |
| 18 | + /** |
| 19 | + * Basic ESLint config to use for testing the sniff. |
| 20 | + * |
| 21 | + * @var string |
| 22 | + */ |
| 23 | + const ESLINT_CONFIG = '{ |
| 24 | + "parserOptions": { |
| 25 | + "ecmaVersion": 5, |
| 26 | + "sourceType": "script", |
| 27 | + "ecmaFeatures": {} |
| 28 | + }, |
| 29 | + "rules": { |
| 30 | + "no-undef": 2, |
| 31 | + "no-unused-vars": 2 |
| 32 | + } |
| 33 | +}'; |
| 34 | + |
| 35 | + |
| 36 | + /** |
| 37 | + * Sets up this unit test. |
| 38 | + * |
| 39 | + * @return void |
| 40 | + */ |
| 41 | + protected function setUp() |
| 42 | + { |
| 43 | + parent::setUp(); |
| 44 | + |
| 45 | + $cwd = getcwd(); |
| 46 | + file_put_contents($cwd.'/.eslintrc.json', self::ESLINT_CONFIG); |
| 47 | + |
| 48 | + }//end setUp() |
| 49 | + |
| 50 | + |
| 51 | + /** |
| 52 | + * Remove artifact. |
| 53 | + * |
| 54 | + * @return void |
| 55 | + */ |
| 56 | + protected function tearDown() |
| 57 | + { |
| 58 | + parent::tearDown(); |
| 59 | + |
| 60 | + $cwd = getcwd(); |
| 61 | + unlink($cwd.'/.eslintrc.json'); |
| 62 | + |
| 63 | + }//end tearDown() |
| 64 | + |
| 65 | + |
| 66 | + /** |
| 67 | + * Should this test be skipped for some reason. |
| 68 | + * |
| 69 | + * @return void |
| 70 | + */ |
| 71 | + protected function shouldSkipTest() |
| 72 | + { |
| 73 | + $eslintPath = Config::getExecutablePath('eslint'); |
| 74 | + if ($eslintPath === null) { |
| 75 | + return true; |
| 76 | + } |
| 77 | + |
| 78 | + return false; |
| 79 | + |
| 80 | + }//end shouldSkipTest() |
| 81 | + |
| 82 | + |
| 83 | + /** |
| 84 | + * Returns the lines where errors should occur. |
| 85 | + * |
| 86 | + * The key of the array should represent the line number and the value |
| 87 | + * should represent the number of errors that should occur on that line. |
| 88 | + * |
| 89 | + * @return array<int, int> |
| 90 | + */ |
| 91 | + public function getErrorList() |
| 92 | + { |
| 93 | + return [1 => 2]; |
| 94 | + |
| 95 | + }//end getErrorList() |
| 96 | + |
| 97 | + |
| 98 | + /** |
| 99 | + * Returns the lines where warnings should occur. |
| 100 | + * |
| 101 | + * The key of the array should represent the line number and the value |
| 102 | + * should represent the number of warnings that should occur on that line. |
| 103 | + * |
| 104 | + * @return array<int, int> |
| 105 | + */ |
| 106 | + public function getWarningList() |
| 107 | + { |
| 108 | + return []; |
| 109 | + |
| 110 | + }//end getWarningList() |
| 111 | + |
| 112 | + |
| 113 | +}//end class |
0 commit comments