-
-
Notifications
You must be signed in to change notification settings - Fork 76
Generic/UpperCaseConstantName: improve code coverage #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jrfnl
merged 12 commits into
PHPCSStandards:master
from
rodrigoprimo:test-coverage-upper-case-constant-name
Nov 27, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d2545e1
Generic/UpperCaseConstantName: handle unconventional spacing and comm…
rodrigoprimo 712eb98
Generic/UpperCaseConstantName: handle unconventional spacing and comm…
rodrigoprimo 2c77bad
Generic/UpperCaseConstantName: false positives when constant name is …
rodrigoprimo e053795
Generic/UpperCaseConstantName: fix attributes false positive
rodrigoprimo db558c9
Generic/UpperCaseConstantName: minor improvement to the error message…
rodrigoprimo 3b6db72
Generic/UpperCaseConstantName: remove special case for double-colon
rodrigoprimo 59b86fc
Generic/UpperCaseConstantName: rename test case file
rodrigoprimo 1352ce8
Generic/UpperCaseConstantName: `findNext()` may return `false`
rodrigoprimo de8a5d0
Generic/UpperCaseConstantName: improve code coverage
rodrigoprimo 4f42d3c
Improve tests based on feedback from PR review
rodrigoprimo e861eaf
Generic/UpperCaseConstantName: fix false positive for class instantia…
rodrigoprimo af0b0f5
Generic/UpperCaseConstantName: move parse error test to its own file
rodrigoprimo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.1.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
use Exception as My_Exception, foo\bar, baz; | ||
namespace foo; | ||
namespace foo\bar; | ||
namespace bar\foo\baz; | ||
|
||
define('VALID_NAME', true); | ||
DEFINE('invalidName', true); | ||
define("VALID_NAME", true); | ||
define("invalidName", true); | ||
define('bar\foo\baz\VALID_NAME_WITH_NAMESPACE', true); | ||
define('bar\foo\baz\invalidNameWithNamespace', true); | ||
define("bar\foo\baz\VALID_NAME_WITH_NAMESPACE", true); | ||
define("bar\foo\baz\invalidNameWithNamespace", true); | ||
|
||
class TestClass extends MyClass implements MyInterface, YourInterface | ||
{ | ||
|
||
const const1 = 'hello'; | ||
const CONST2 = 'hello'; | ||
} | ||
|
||
$foo->define('bar'); | ||
$foo->getBar()->define('foo'); | ||
Foo::define('bar'); | ||
|
||
class ClassConstBowOutTest { | ||
const /* comment */ abc = 1; | ||
const // phpcs:ignore Standard.Category.Sniff | ||
some_constant = 2; | ||
} | ||
|
||
$foo->getBar()?->define('foo'); | ||
|
||
// PHP 8.3 introduces typed constants. | ||
class TypedConstants { | ||
|
||
const MyClass MYCONST = new MyClass; | ||
const int VALID_NAME = 0; | ||
final public const INT invalid_name = 0; | ||
const FALSE false = false; // Yes, false can be used as a constant name, don't ask. | ||
final protected const array ARRAY = array(); // Same goes for array. | ||
} | ||
|
||
define /* comment */ ( /* comment */ 'CommentsInUnconventionalPlaces', 'value' ); | ||
|
||
define | ||
// comment | ||
( | ||
// phpcs:ignore Stnd.Cat.SniffName -- for reasons. | ||
'CommentsInUnconventionalPlaces', | ||
'value' | ||
); | ||
|
||
$foo-> /* comment */ define('bar'); | ||
$foo?-> | ||
// phpcs:ignore Stnd.Cat.SniffName -- for reasons. | ||
define('bar'); | ||
|
||
const DEFINE = 'value'; | ||
|
||
#[Define('some param')] | ||
class MyClass {} | ||
|
||
#[ | ||
AttributeA, | ||
define('some param') | ||
] | ||
class MyClass {} | ||
|
||
const MixedCase = 1; | ||
|
||
define('lower_case_name', 'value'); | ||
define($var, 'sniff should bow out'); | ||
define(constantName(), 'sniff should bow out'); | ||
define($obj->constantName(), 'sniff should bow out'); | ||
define(MyClass::constantName(), 'sniff should bow out'); | ||
define(condition() ? 'name1' : 'name2', 'sniff should bow out'); | ||
|
||
$callable = define(...); | ||
|
||
// Valid if outside the global namespace. Sniff should bow out. | ||
function define($param) {} | ||
|
||
class MyClass { | ||
public function define($param) {} | ||
} | ||
|
||
$a = ($cond) ? DEFINE : SOMETHING_ELSE; | ||
|
||
$object = new Define('value'); |
7 changes: 7 additions & 0 deletions
7
src/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.2.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// Intentional parse error (missing constant name). | ||
// This should be the only test in this file. | ||
// Testing that the sniff is *not* triggered. | ||
|
||
define( |
7 changes: 7 additions & 0 deletions
7
src/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.3.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// Intentional parse error (missing opening parenthesis). | ||
// This should be the only test in this file. | ||
// Testing that the sniff is *not* triggered. | ||
|
||
define |
7 changes: 7 additions & 0 deletions
7
src/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.4.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// Intentional parse error (missing constant name). | ||
// This should be the only test in this file. | ||
// Testing that the sniff is *not* triggered. | ||
|
||
const = |
9 changes: 9 additions & 0 deletions
9
src/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.5.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
// Intentional parse error (missing class constant value). | ||
// This should be the only test in this file. | ||
// Testing that the sniff is *not* triggered. | ||
|
||
class TypedConstants { | ||
const MISSING_VALUE; | ||
} |
43 changes: 0 additions & 43 deletions
43
src/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.inc
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.