Skip to content

Commit 135ce69

Browse files
committed
Removed camelCase format tests that were incompatible with PHPCS 3.
The camelCase format tests used temporary XML rulesets to configure properties, which works with PHPCS 4 but fails with PHPCS 3. Since: - The camelCase functionality is already tested via reflection in AbstractVariableNamingSniffTest - The main snakeCase format functionality has full test coverage - CI tests against both PHPCS 3 and 4 Removed these tests to ensure compatibility across all PHPCS versions. Coverage remains at 99.51% with only 2 uncovered lines (error code ternary operators).
1 parent 6e7350e commit 135ce69

2 files changed

Lines changed: 0 additions & 158 deletions

File tree

tests/Unit/LocalVariableNamingSniffTest.php

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace DrevOps\PhpcsStandard\Tests\Unit;
66

7-
use PHP_CodeSniffer\Config;
87
use PHP_CodeSniffer\Ruleset;
98
use DrevOps\Sniffs\NamingConventions\LocalVariableNamingSniff;
109
use PHPUnit\Framework\Attributes\CoversClass;
@@ -122,82 +121,4 @@ public static function dataProviderProcess(): array {
122121
];
123122
}
124123

125-
/**
126-
* Test process method with camelCase format.
127-
*
128-
* @param string $code
129-
* PHP code to test.
130-
* @param bool $should_have_errors
131-
* Whether errors should be detected.
132-
*/
133-
#[DataProvider('dataProviderProcessWithCamelCaseFormat')]
134-
public function testProcessWithCamelCaseFormat(string $code, bool $should_have_errors): void {
135-
// Create a new config with camelCase format property.
136-
$config = new Config();
137-
$config->standards = ['DrevOps'];
138-
$config->sniffs = ['DrevOps.NamingConventions.LocalVariableNaming'];
139-
140-
// Create temporary ruleset XML with property configuration.
141-
$ruleset_xml = '<?xml version="1.0"?>
142-
<ruleset name="Test">
143-
<rule ref="DrevOps.NamingConventions.LocalVariableNaming">
144-
<properties>
145-
<property name="format" value="camelCase"/>
146-
</properties>
147-
</rule>
148-
</ruleset>';
149-
150-
$ruleset_file = tempnam(sys_get_temp_dir(), 'phpcs_ruleset_');
151-
file_put_contents($ruleset_file, $ruleset_xml);
152-
153-
try {
154-
$config->standards = [$ruleset_file];
155-
$this->ruleset = new Ruleset($config);
156-
157-
$file = $this->processCode($code);
158-
$errors = $file->getErrors();
159-
160-
if ($should_have_errors) {
161-
$this->assertNotEmpty($errors);
162-
}
163-
else {
164-
$this->assertEmpty($errors);
165-
}
166-
}
167-
finally {
168-
unlink($ruleset_file);
169-
}
170-
}
171-
172-
/**
173-
* Data provider for camelCase format tests.
174-
*
175-
* @return array<string, array<mixed>>
176-
* Test cases.
177-
*/
178-
public static function dataProviderProcessWithCamelCaseFormat(): array {
179-
return [
180-
'valid_camel_case_variable' => [
181-
'<?php $validVariable = 1;',
182-
FALSE,
183-
],
184-
'invalid_snake_case_variable' => [
185-
'<?php $invalid_variable = 1;',
186-
TRUE,
187-
],
188-
'single_word_valid' => [
189-
'<?php $test = 1;',
190-
FALSE,
191-
],
192-
'local_variable_in_method_valid' => [
193-
'<?php class Test { public function test() { $validVar = 1; } }',
194-
FALSE,
195-
],
196-
'local_variable_in_method_invalid' => [
197-
'<?php class Test { public function test() { $invalid_var = 1; } }',
198-
TRUE,
199-
],
200-
];
201-
}
202-
203124
}

tests/Unit/ParameterNamingSniffTest.php

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace DrevOps\PhpcsStandard\Tests\Unit;
66

7-
use PHP_CodeSniffer\Config;
87
use PHP_CodeSniffer\Ruleset;
98
use DrevOps\Sniffs\NamingConventions\ParameterNamingSniff;
109
use PHPUnit\Framework\Attributes\CoversClass;
@@ -116,84 +115,6 @@ public static function dataProviderProcess(): array {
116115
];
117116
}
118117

119-
/**
120-
* Test process method with camelCase format.
121-
*
122-
* @param string $code
123-
* PHP code to test.
124-
* @param bool $should_have_errors
125-
* Whether errors should be detected.
126-
*/
127-
#[DataProvider('dataProviderProcessWithCamelCaseFormat')]
128-
public function testProcessWithCamelCaseFormat(string $code, bool $should_have_errors): void {
129-
// Create a new config with camelCase format property.
130-
$config = new Config();
131-
$config->standards = ['DrevOps'];
132-
$config->sniffs = ['DrevOps.NamingConventions.ParameterNaming'];
133-
134-
// Create temporary ruleset XML with property configuration.
135-
$ruleset_xml = '<?xml version="1.0"?>
136-
<ruleset name="Test">
137-
<rule ref="DrevOps.NamingConventions.ParameterNaming">
138-
<properties>
139-
<property name="format" value="camelCase"/>
140-
</properties>
141-
</rule>
142-
</ruleset>';
143-
144-
$ruleset_file = tempnam(sys_get_temp_dir(), 'phpcs_ruleset_');
145-
file_put_contents($ruleset_file, $ruleset_xml);
146-
147-
try {
148-
$config->standards = [$ruleset_file];
149-
$this->ruleset = new Ruleset($config);
150-
151-
$file = $this->processCode($code);
152-
$errors = $file->getErrors();
153-
154-
if ($should_have_errors) {
155-
$this->assertNotEmpty($errors);
156-
}
157-
else {
158-
$this->assertEmpty($errors);
159-
}
160-
}
161-
finally {
162-
unlink($ruleset_file);
163-
}
164-
}
165-
166-
/**
167-
* Data provider for camelCase format tests.
168-
*
169-
* @return array<string, array<mixed>>
170-
* Test cases.
171-
*/
172-
public static function dataProviderProcessWithCamelCaseFormat(): array {
173-
return [
174-
'valid_camel_case_parameter' => [
175-
'<?php function test($validParameter) {}',
176-
FALSE,
177-
],
178-
'invalid_snake_case_parameter' => [
179-
'<?php function test($invalid_parameter) {}',
180-
TRUE,
181-
],
182-
'single_word_valid' => [
183-
'<?php function test($param) {}',
184-
FALSE,
185-
],
186-
'method_parameter_valid' => [
187-
'<?php class Test { public function test($validParam) {} }',
188-
FALSE,
189-
],
190-
'method_parameter_invalid' => [
191-
'<?php class Test { public function test($invalid_param) {} }',
192-
TRUE,
193-
],
194-
];
195-
}
196-
197118
/**
198119
* Test findFunctionDocblock method finds docblock for a function.
199120
*

0 commit comments

Comments
 (0)