File: GetIncludePatternsTest.php

package info (click to toggle)
php-codesniffer 3.11.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,772 kB
  • sloc: php: 84,771; pascal: 10,061; xml: 6,832; javascript: 2,096; sh: 11; makefile: 4
file content (108 lines) | stat: -rw-r--r-- 3,308 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
 * Test the Ruleset::getIncludePatterns() method.
 *
 * @author    Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
 * @copyright 2024 PHPCSStandards and contributors
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 */

namespace PHP_CodeSniffer\Tests\Core\Ruleset;

use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Tests\ConfigDouble;
use PHPUnit\Framework\TestCase;

/**
 * Test the Ruleset::getIncludePatterns() method.
 *
 * @covers \PHP_CodeSniffer\Ruleset::getIncludePatterns
 */
final class GetIncludePatternsTest extends TestCase
{

    /**
     * The Ruleset object.
     *
     * @var \PHP_CodeSniffer\Ruleset
     */
    private static $ruleset;


    /**
     * Initialize the config and ruleset objects for this test.
     *
     * @beforeClass
     *
     * @return void
     */
    public static function initializeConfigAndRuleset()
    {
        // Set up the ruleset.
        $standard      = __DIR__."/GetIncludePatternsTest.xml";
        $config        = new ConfigDouble(["--standard=$standard"]);
        self::$ruleset = new Ruleset($config);

    }//end initializeConfigAndRuleset()


    /**
     * Test retrieving include patterns.
     *
     * @param string|null                                 $listener The listener to get patterns for or null for all patterns.
     * @param array<string, string|array<string, string>> $expected The expected function output.
     *
     * @dataProvider dataGetIncludePatterns
     *
     * @return void
     */
    public function testGetIncludePatterns($listener, $expected)
    {
        $this->assertSame($expected, self::$ruleset->getIncludePatterns($listener));

    }//end testGetIncludePatterns()


    /**
     * Data provider.
     *
     * @see self::testGetIncludePatterns()
     *
     * @return array<string, array<string, string|array<string, string|array<string, string>>|null>>
     */
    public static function dataGetIncludePatterns()
    {
        return [
            'All include patterns'                                   => [
                'listener' => null,
                'expected' => [
                    'PSR1.Classes.ClassDeclaration'     => [
                        './src/*/file.php' => 'absolute',
                        './bin/'           => 'relative',
                    ],
                    'Generic.Formatting.SpaceAfterCast' => [
                        './src/*/test\\.php$' => 'absolute',
                    ],
                ],
            ],
            'Include patterns for PSR1.Classes.ClassDeclaration'     => [
                'listener' => 'PSR1.Classes.ClassDeclaration',
                'expected' => [
                    './src/*/file.php' => 'absolute',
                    './bin/'           => 'relative',
                ],
            ],
            'Include patterns for Generic.Formatting.SpaceAfterCast' => [
                'listener' => 'Generic.Formatting.SpaceAfterCast',
                'expected' => ['./src/*/test\\.php$' => 'absolute'],
            ],
            'Include patterns for sniff without include patterns'    => [
                'listener' => 'PSR1.Files.SideEffects',
                'expected' => [],
            ],
        ];

    }//end dataGetIncludePatterns()


}//end class