<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php
/**
 * Tests that invalid sniffs will be rejected with an informative error message.
 *
 * @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;

/**
 * Tests that invalid sniffs will be rejected with an informative error message.
 *
 * @covers \PHP_CodeSniffer\Ruleset::registerSniffs
 */
final class RegisterSniffsRejectsInvalidSniffTest extends AbstractRulesetTestCase
{


    /**
     * Verify that an error is thrown if an invalid sniff class is loaded.
     *
     * @param string $standard   The standard to use for the test.
     * @param string $methodName The name of the missing method.
     *
     * @dataProvider dataExceptionIsThrownOnMissingInterfaceMethod
     *
     * @return void
     */
    public function testExceptionIsThrownOnMissingInterfaceMethod($standard, $methodName)
    {
        // Set up the ruleset.
        $standard = __DIR__.'/'.$standard;
        $config   = new ConfigDouble(["--standard=$standard"]);

        $regex = "`(^|\R)ERROR: Sniff class \S+Sniff is missing required method $methodName\(\)\.\R`";
        $this->expectRuntimeExceptionRegex($regex);

        new Ruleset($config);

    }//end testExceptionIsThrownOnMissingInterfaceMethod()


    /**
     * Data provider.
     *
     * @see testExceptionIsThrownOnMissingInterfaceMethod()
     *
     * @return array<string, array<string, string>>
     */
    public static function dataExceptionIsThrownOnMissingInterfaceMethod()
    {
        return [
            'Missing register() method'                => [
                'standard'   => 'RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterTest.xml',
                'methodName' => 'register',
            ],
            'Missing process() method'                 => [
                'standard'   => 'RegisterSniffsRejectsInvalidSniffNoImplementsNoProcessTest.xml',
                'methodName' => 'process',
            ],
            'Missing both, checking register() method' => [
                'standard'   => 'RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterOrProcessTest.xml',
                'methodName' => 'register',
            ],
            'Missing both, checking process() method'  => [
                'standard'   => 'RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterOrProcessTest.xml',
                'methodName' => 'process',
            ],
        ];

    }//end dataExceptionIsThrownOnMissingInterfaceMethod()


}//end class
