\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/cpanel/ea-wappspector/vendor/squizlabs/php_codesniffer/tests/Core/Ruleset/

Viewing File: ExplainTest.php

<?php
/**
 * Tests to verify that the "explain" command functions as expected.
 *
 * @author    Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
 * @copyright 2023 Juliette Reinders Folmer. All rights reserved.
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/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::explain() function.
 *
 * @covers \PHP_CodeSniffer\Ruleset::explain
 */
final class ExplainTest extends TestCase
{


    /**
     * Test the output of the "explain" command.
     *
     * @return void
     */
    public function testExplain()
    {
        // Set up the ruleset.
        $config  = new ConfigDouble(['--standard=PSR1', '-e']);
        $ruleset = new Ruleset($config);

        $expected  = PHP_EOL;
        $expected .= 'The PSR1 standard contains 8 sniffs'.PHP_EOL.PHP_EOL;
        $expected .= 'Generic (4 sniffs)'.PHP_EOL;
        $expected .= '------------------'.PHP_EOL;
        $expected .= '  Generic.Files.ByteOrderMark'.PHP_EOL;
        $expected .= '  Generic.NamingConventions.UpperCaseConstantName'.PHP_EOL;
        $expected .= '  Generic.PHP.DisallowAlternativePHPTags'.PHP_EOL;
        $expected .= '  Generic.PHP.DisallowShortOpenTag'.PHP_EOL.PHP_EOL;
        $expected .= 'PSR1 (3 sniffs)'.PHP_EOL;
        $expected .= '---------------'.PHP_EOL;
        $expected .= '  PSR1.Classes.ClassDeclaration'.PHP_EOL;
        $expected .= '  PSR1.Files.SideEffects'.PHP_EOL;
        $expected .= '  PSR1.Methods.CamelCapsMethodName'.PHP_EOL.PHP_EOL;
        $expected .= 'Squiz (1 sniff)'.PHP_EOL;
        $expected .= '---------------'.PHP_EOL;
        $expected .= '  Squiz.Classes.ValidClassName'.PHP_EOL;

        $this->expectOutputString($expected);

        $ruleset->explain();

    }//end testExplain()


    /**
     * Test the output of the "explain" command is not influenced by a user set report width.
     *
     * @return void
     */
    public function testExplainAlwaysDisplaysCompleteSniffName()
    {
        // Set up the ruleset.
        $config  = new ConfigDouble(['--standard=PSR1', '-e', '--report-width=30']);
        $ruleset = new Ruleset($config);

        $expected  = PHP_EOL;
        $expected .= 'The PSR1 standard contains 8 sniffs'.PHP_EOL.PHP_EOL;
        $expected .= 'Generic (4 sniffs)'.PHP_EOL;
        $expected .= '------------------'.PHP_EOL;
        $expected .= '  Generic.Files.ByteOrderMark'.PHP_EOL;
        $expected .= '  Generic.NamingConventions.UpperCaseConstantName'.PHP_EOL;
        $expected .= '  Generic.PHP.DisallowAlternativePHPTags'.PHP_EOL;
        $expected .= '  Generic.PHP.DisallowShortOpenTag'.PHP_EOL.PHP_EOL;
        $expected .= 'PSR1 (3 sniffs)'.PHP_EOL;
        $expected .= '---------------'.PHP_EOL;
        $expected .= '  PSR1.Classes.ClassDeclaration'.PHP_EOL;
        $expected .= '  PSR1.Files.SideEffects'.PHP_EOL;
        $expected .= '  PSR1.Methods.CamelCapsMethodName'.PHP_EOL.PHP_EOL;
        $expected .= 'Squiz (1 sniff)'.PHP_EOL;
        $expected .= '---------------'.PHP_EOL;
        $expected .= '  Squiz.Classes.ValidClassName'.PHP_EOL;

        $this->expectOutputString($expected);

        $ruleset->explain();

    }//end testExplainAlwaysDisplaysCompleteSniffName()


    /**
     * Test the output of the "explain" command when a ruleset only contains a single sniff.
     *
     * This is mostly about making sure that the summary line uses the correct grammar.
     *
     * @return void
     */
    public function testExplainSingleSniff()
    {
        // Set up the ruleset.
        $standard = __DIR__.'/ExplainSingleSniffTest.xml';
        $config   = new ConfigDouble(["--standard=$standard", '-e']);
        $ruleset  = new Ruleset($config);

        $expected  = PHP_EOL;
        $expected .= 'The ExplainSingleSniffTest standard contains 1 sniff'.PHP_EOL.PHP_EOL;
        $expected .= 'Squiz (1 sniff)'.PHP_EOL;
        $expected .= '---------------'.PHP_EOL;
        $expected .= '  Squiz.Scope.MethodScope'.PHP_EOL;

        $this->expectOutputString($expected);

        $ruleset->explain();

    }//end testExplainSingleSniff()


    /**
     * Test that "explain" works correctly with custom rulesets.
     *
     * Verifies that:
     * - The "standard" name is taken from the custom ruleset.
     * - Any and all sniff additions and exclusions in the ruleset are taken into account correctly.
     * - That the displayed list will have both the standards as well as the sniff names
     *   ordered alphabetically.
     *
     * @return void
     */
    public function testExplainCustomRuleset()
    {
        // Set up the ruleset.
        $standard = __DIR__.'/ExplainCustomRulesetTest.xml';
        $config   = new ConfigDouble(["--standard=$standard", '-e']);
        $ruleset  = new Ruleset($config);

        $expected  = PHP_EOL;
        $expected .= 'The ExplainCustomRulesetTest standard contains 10 sniffs'.PHP_EOL.PHP_EOL;
        $expected .= 'Generic (4 sniffs)'.PHP_EOL;
        $expected .= '------------------'.PHP_EOL;
        $expected .= '  Generic.Files.ByteOrderMark'.PHP_EOL;
        $expected .= '  Generic.NamingConventions.UpperCaseConstantName'.PHP_EOL;
        $expected .= '  Generic.PHP.DisallowAlternativePHPTags'.PHP_EOL;
        $expected .= '  Generic.PHP.DisallowShortOpenTag'.PHP_EOL.PHP_EOL;
        $expected .= 'PSR1 (2 sniffs)'.PHP_EOL;
        $expected .= '---------------'.PHP_EOL;
        $expected .= '  PSR1.Classes.ClassDeclaration'.PHP_EOL;
        $expected .= '  PSR1.Methods.CamelCapsMethodName'.PHP_EOL.PHP_EOL;
        $expected .= 'PSR12 (2 sniffs)'.PHP_EOL;
        $expected .= '----------------'.PHP_EOL;
        $expected .= '  PSR12.ControlStructures.BooleanOperatorPlacement'.PHP_EOL;
        $expected .= '  PSR12.ControlStructures.ControlStructureSpacing'.PHP_EOL.PHP_EOL;
        $expected .= 'Squiz (2 sniffs)'.PHP_EOL;
        $expected .= '----------------'.PHP_EOL;
        $expected .= '  Squiz.Classes.ValidClassName'.PHP_EOL;
        $expected .= '  Squiz.Scope.MethodScope'.PHP_EOL;

        $this->expectOutputString($expected);

        $ruleset->explain();

    }//end testExplainCustomRuleset()


    /**
     * Test the output of the "explain" command for a standard containing both deprecated
     * and non-deprecated sniffs.
     *
     * Tests that:
     * - Deprecated sniffs are marked with an asterix in the list.
     * - A footnote is displayed explaining the asterix.
     * - And that the "standard uses # deprecated sniffs" listing is **not** displayed.
     *
     * @return void
     */
    public function testExplainWithDeprecatedSniffs()
    {
        // Set up the ruleset.
        $standard = __DIR__."/ShowSniffDeprecationsTest.xml";
        $config   = new ConfigDouble(["--standard=$standard", '-e']);
        $ruleset  = new Ruleset($config);

        $expected  = PHP_EOL;
        $expected .= 'The ShowSniffDeprecationsTest standard contains 11 sniffs'.PHP_EOL.PHP_EOL;

        $expected .= 'TestStandard (11 sniffs)'.PHP_EOL;
        $expected .= '------------------------'.PHP_EOL;
        $expected .= '  TestStandard.Deprecated.WithLongReplacement *'.PHP_EOL;
        $expected .= '  TestStandard.Deprecated.WithoutReplacement *'.PHP_EOL;
        $expected .= '  TestStandard.Deprecated.WithReplacement *'.PHP_EOL;
        $expected .= '  TestStandard.Deprecated.WithReplacementContainingLinuxNewlines *'.PHP_EOL;
        $expected .= '  TestStandard.Deprecated.WithReplacementContainingNewlines *'.PHP_EOL;
        $expected .= '  TestStandard.SetProperty.AllowedAsDeclared'.PHP_EOL;
        $expected .= '  TestStandard.SetProperty.AllowedViaMagicMethod'.PHP_EOL;
        $expected .= '  TestStandard.SetProperty.AllowedViaStdClass'.PHP_EOL;
        $expected .= '  TestStandard.SetProperty.NotAllowedViaAttribute'.PHP_EOL;
        $expected .= '  TestStandard.SetProperty.PropertyTypeHandling'.PHP_EOL;
        $expected .= '  TestStandard.ValidSniffs.RegisterEmptyArray'.PHP_EOL.PHP_EOL;

        $expected .= '* Sniffs marked with an asterisk are deprecated.'.PHP_EOL;

        $this->expectOutputString($expected);

        $ruleset->explain();

    }//end testExplainWithDeprecatedSniffs()


}//end class