PHP 8.3.31
Preview: ExpandRulesetReferenceHomePathTest.php Size: 3.48 KB
/proc/self/root/opt/cpanel/ea-wappspector/vendor/squizlabs/php_codesniffer/tests/Core/Ruleset/ExpandRulesetReferenceHomePathTest.php

<?php
/**
 * Test the Ruleset::expandRulesetReference() method.
 *
 * @author    Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
 * @copyright 2025 PHPCSStandards and contributors
 * @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 PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase;

/**
 * Test home path handling in the Ruleset::expandRulesetReference() method.
 *
 * @covers \PHP_CodeSniffer\Ruleset::expandRulesetReference
 */
final class ExpandRulesetReferenceHomePathTest extends AbstractRulesetTestCase
{

    /**
     * Original value of the user's home path environment variable.
     *
     * @var string|false Path or false is the `HOME` environment variable is not available.
     */
    private static $homepath = false;


    /**
     * Store the user's home path.
     *
     * @beforeClass
     *
     * @return void
     */
    public static function storeHomePath()
    {
        self::$homepath = getenv('HOME');

    }//end storeHomePath()


    /**
     * Restore the user's home path environment variable in case the test changed it or created it.
     *
     * @afterClass
     *
     * @return void
     */
    public static function restoreHomePath()
    {
        if (is_string(self::$homepath) === true) {
            putenv('HOME='.self::$homepath);
        } else {
            // Remove the environment variable as it didn't exist before.
            putenv('HOME');
        }

    }//end restoreHomePath()


    /**
     * Set the home path to an alternative location.
     *
     * @before
     *
     * @return void
     */
    protected function setHomePath()
    {
        $fakeHomePath = __DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'FakeHomePath';
        putenv("HOME=$fakeHomePath");

    }//end setHomePath()


    /**
     * Verify that a sniff reference with the magic "home path" placeholder gets expanded correctly
     * and finds sniffs if the path exists underneath the "home path".
     *
     * @return void
     */
    public function testHomePathRefGetsExpandedAndFindsSniff()
    {
        // Set up the ruleset.
        $standard = __DIR__.'/ExpandRulesetReferenceHomePathTest.xml';
        $config   = new ConfigDouble(["--standard=$standard"]);
        $ruleset  = new Ruleset($config);

        $expected = ['MyStandard.Category.Valid' => 'FakeHomePath\\MyStandard\\Sniffs\\Category\\ValidSniff'];

        $this->assertSame($expected, $ruleset->sniffCodes);

    }//end testHomePathRefGetsExpandedAndFindsSniff()


    /**
     * Verify that a sniff reference with the magic "home path" placeholder gets expanded correctly
     * and still fails to find sniffs if the path doesn't exists underneath the "home path".
     *
     * @return void
     */
    public function testHomePathRefGetsExpandedAndThrowsExceptionWhenPathIsInvalid()
    {
        // Set up the ruleset.
        $standard = __DIR__.'/ExpandRulesetReferenceHomePathFailTest.xml';
        $config   = new ConfigDouble(["--standard=$standard"]);

        $exceptionMessage  = 'ERROR: Referenced sniff "~/src/MyStandard/Sniffs/DoesntExist/" does not exist.'.PHP_EOL;
        $exceptionMessage .= 'ERROR: No sniffs were registered.'.PHP_EOL.PHP_EOL;
        $this->expectRuntimeExceptionMessage($exceptionMessage);

        new Ruleset($config);

    }//end testHomePathRefGetsExpandedAndThrowsExceptionWhenPathIsInvalid()


}//end class

Directory Contents

Dirs: 1 × Files: 92

Name Size Perms Modified Actions
Fixtures DIR
- drwxr-xr-x 2025-11-04 16:30:35
Edit Download
3.83 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
217 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
11.11 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
10.83 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
512 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
547 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
425 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
3.48 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
337 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
643 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
330 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
2.51 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
332 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
333 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
325 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
434 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
364 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
5.35 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
621 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
508 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
515 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
469 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
2.49 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
349 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
374 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
247 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
8.16 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
3.42 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
742 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
3.23 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
556 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
4.67 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
1.55 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
465 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
4.13 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
369 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
21.06 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
1.99 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
1.18 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
345 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
592 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
394 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
6.12 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
1.39 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
0 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
420 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
201 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
3.13 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
362 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
439 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
997 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
12.43 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
1.67 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
11.24 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
24.71 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
3.31 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
317 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
12.04 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
3.81 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
355 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
2.08 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
446 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
444 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
454 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
445 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
2.71 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
10.27 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
3.28 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
482 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
3.19 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
479 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
364 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
18.56 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
1.84 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
728 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
732 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
729 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
338 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
343 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
376 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
439 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
354 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
16.73 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
371 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
367 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
373 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
373 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
369 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
513 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
360 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download
25.61 KB lrw-r--r-- 2025-11-04 16:30:35
Edit Download
622 B lrw-r--r-- 2025-11-04 16:30:35
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).