@@ -683,4 +683,42 @@ public function testToFormatThrowsExceptionForInvalidFormat(): void {
683683 $ method ->invoke ($ sniff , 'test ' );
684684 }
685685
686+ /**
687+ * Test leading underscore detection.
688+ *
689+ * @param string $name
690+ * The variable name to test.
691+ * @param bool $expected
692+ * Expected result.
693+ */
694+ #[DataProvider('providerHasLeadingUnderscore ' )]
695+ public function testHasLeadingUnderscore (string $ name , bool $ expected ): void {
696+ $ sniff = new LocalVariableNamingSniff ();
697+ $ reflection = new \ReflectionClass ($ sniff );
698+ $ method = $ reflection ->getMethod ('hasLeadingUnderscore ' );
699+
700+ $ result = $ method ->invoke ($ sniff , $ name );
701+ $ this ->assertSame ($ expected , $ result , 'Failed for: ' . $ name );
702+ }
703+
704+ /**
705+ * Data provider for hasLeadingUnderscore tests.
706+ *
707+ * @return array<string, array<string|bool>>
708+ * Test cases.
709+ */
710+ public static function providerHasLeadingUnderscore (): array {
711+ return [
712+ 'leading_underscore_snake ' => ['_static_value ' , TRUE ],
713+ 'leading_underscore_camel ' => ['_staticValue ' , TRUE ],
714+ 'leading_underscore_only ' => ['_ ' , TRUE ],
715+ 'leading_double_underscore ' => ['__internal ' , TRUE ],
716+ 'no_leading_underscore_snake ' => ['static_value ' , FALSE ],
717+ 'no_leading_underscore_camel ' => ['staticValue ' , FALSE ],
718+ 'underscore_in_middle ' => ['static_value ' , FALSE ],
719+ 'trailing_underscore ' => ['value_ ' , FALSE ],
720+ 'single_letter ' => ['a ' , FALSE ],
721+ ];
722+ }
723+
686724}
0 commit comments