|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - http://moodle.org/ |
| 3 | +// |
| 4 | +// Moodle is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Moodle is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +namespace MoodleHQ\MoodleCS\moodle\Tests; |
| 18 | + |
| 19 | +// phpcs:disable moodle.NamingConventions |
| 20 | + |
| 21 | +/** |
| 22 | + * Test the IncludingFile sniff. |
| 23 | + * |
| 24 | + * @package local_codechecker |
| 25 | + * @category test |
| 26 | + * @copyright 2021 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} |
| 27 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 28 | + * |
| 29 | + * @covers \MoodleHQ\MoodleCS\moodle\Sniffs\PHP\IncludingFileSniff |
| 30 | + */ |
| 31 | +class PHPIncludingFileTest extends MoodleCSBaseTest { |
| 32 | + |
| 33 | + public function test_php_includingfile() { |
| 34 | + // Define the standard, sniff and fixture to use. |
| 35 | + $this->set_standard('moodle'); |
| 36 | + $this->set_sniff('moodle.PHP.IncludingFile'); |
| 37 | + $this->set_fixture(__DIR__ . '/fixtures/php/includingfile.php'); |
| 38 | + |
| 39 | + // Define expected results (errors and warnings). Format, array of: |
| 40 | + // - line => number of problems, or |
| 41 | + // - line => array of contents for message / source problem matching. |
| 42 | + // - line => string of contents for message / source problem matching (only 1). |
| 43 | + $this->set_errors([ |
| 44 | + 9 => '@Message: "require" must be immediately followed by an open parenthesis', |
| 45 | + 10 => '@Source: moodle.PHP.IncludingFile.BracketsRequired', |
| 46 | + 13 => 1, |
| 47 | + 14 => 1, |
| 48 | + 17 => '@Source: moodle.PHP.IncludingFile.UseRequire', |
| 49 | + 18 => '@Source: moodle.PHP.IncludingFile.UseRequireOnce', |
| 50 | + ]); |
| 51 | + $this->set_warnings([]); |
| 52 | + |
| 53 | + // Let's do all the hard work! |
| 54 | + $this->verify_cs_results(); |
| 55 | + } |
| 56 | +} |
0 commit comments