-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #983 from kylekatarnls/fix/issue-924-bool-arg-in-c…
…onstructor Add exceptions and ignorepattern properties to BooleanArgumentFlag rule
- Loading branch information
Showing
10 changed files
with
267 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
65 changes: 65 additions & 0 deletions
65
src/test/php/PHPMD/Rule/CleanCode/BooleanArgumentFlagTest.php
This file contains 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,65 @@ | ||
<?php | ||
/** | ||
* This file is part of PHP Mess Detector. | ||
* | ||
* Copyright (c) Manuel Pichler <mapi@phpmd.org>. | ||
* All rights reserved. | ||
* | ||
* Licensed under BSD License | ||
* For full copyright and license information, please see the LICENSE file. | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author Manuel Pichler <mapi@phpmd.org> | ||
* @copyright Manuel Pichler. All rights reserved. | ||
* @license https://opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://phpmd.org/ | ||
*/ | ||
|
||
namespace PHPMD\Rule\CleanCode; | ||
|
||
use PHPMD\AbstractTest; | ||
|
||
/** | ||
* @coversDefaultClass \PHPMD\Rule\CleanCode\BooleanArgumentFlag | ||
*/ | ||
class BooleanArgumentFlagTest extends AbstractTest | ||
{ | ||
/** | ||
* Get the rule under test. | ||
* | ||
* @return BooleanArgumentFlag | ||
*/ | ||
public function getRule() | ||
{ | ||
$rule = new BooleanArgumentFlag(); | ||
|
||
$rule->addProperty('exceptions', 'MyClass'); | ||
$rule->addProperty('ignorepattern', '/WhitelistedMethod$/'); | ||
|
||
return $rule; | ||
} | ||
|
||
/** | ||
* Tests the rule for cases where it should apply. | ||
* | ||
* @param string $file The test file to test against. | ||
* @return void | ||
* @dataProvider getApplyingCases | ||
*/ | ||
public function testRuleAppliesTo($file) | ||
{ | ||
$this->expectRuleHasViolationsForFile($this->getRule(), static::ONE_VIOLATION, $file); | ||
} | ||
|
||
/** | ||
* Tests the rule for cases where it should not apply. | ||
* | ||
* @param string $file The test file to test against. | ||
* @return void | ||
* @dataProvider getNotApplyingCases | ||
*/ | ||
public function testRuleDoesNotApplyTo($file) | ||
{ | ||
$this->expectRuleHasViolationsForFile($this->getRule(), static::NO_VIOLATION, $file); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...st/resources/files/Rule/CleanCode/BooleanArgumentFlag/testRuleAppliesToTypedParameter.php
This file contains 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,23 @@ | ||
<?php | ||
/** | ||
* This file is part of PHP Mess Detector. | ||
* | ||
* Copyright (c) Manuel Pichler <mapi@phpmd.org>. | ||
* All rights reserved. | ||
* | ||
* Licensed under BSD License | ||
* For full copyright and license information, please see the LICENSE file. | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author Manuel Pichler <mapi@phpmd.org> | ||
* @copyright Manuel Pichler. All rights reserved. | ||
* @license https://opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://phpmd.org/ | ||
*/ | ||
|
||
class Foo | ||
{ | ||
public function testRuleAppliesToTypedParameter(bool $stuff = true): void | ||
{ | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../resources/files/Rule/CleanCode/BooleanArgumentFlag/testRuleAppliesToUntypedParameter.php
This file contains 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,23 @@ | ||
<?php | ||
/** | ||
* This file is part of PHP Mess Detector. | ||
* | ||
* Copyright (c) Manuel Pichler <mapi@phpmd.org>. | ||
* All rights reserved. | ||
* | ||
* Licensed under BSD License | ||
* For full copyright and license information, please see the LICENSE file. | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author Manuel Pichler <mapi@phpmd.org> | ||
* @copyright Manuel Pichler. All rights reserved. | ||
* @license https://opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://phpmd.org/ | ||
*/ | ||
|
||
class Foo | ||
{ | ||
public function testRuleAppliesToUntypedParameter($stuff = false) | ||
{ | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...CleanCode/BooleanArgumentFlag/testRuleDoesNotApplyToTypedParameterWithoutDefaultValue.php
This file contains 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,23 @@ | ||
<?php | ||
/** | ||
* This file is part of PHP Mess Detector. | ||
* | ||
* Copyright (c) Manuel Pichler <mapi@phpmd.org>. | ||
* All rights reserved. | ||
* | ||
* Licensed under BSD License | ||
* For full copyright and license information, please see the LICENSE file. | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author Manuel Pichler <mapi@phpmd.org> | ||
* @copyright Manuel Pichler. All rights reserved. | ||
* @license https://opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://phpmd.org/ | ||
*/ | ||
|
||
class Foo | ||
{ | ||
public function testRuleDoesNotApplyToTypedParameterWithoutDefaultValue(bool $stuff): void | ||
{ | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...eanCode/BooleanArgumentFlag/testRuleDoesNotApplyToUntypedParameterWithoutDefaultValue.php
This file contains 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,23 @@ | ||
<?php | ||
/** | ||
* This file is part of PHP Mess Detector. | ||
* | ||
* Copyright (c) Manuel Pichler <mapi@phpmd.org>. | ||
* All rights reserved. | ||
* | ||
* Licensed under BSD License | ||
* For full copyright and license information, please see the LICENSE file. | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author Manuel Pichler <mapi@phpmd.org> | ||
* @copyright Manuel Pichler. All rights reserved. | ||
* @license https://opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://phpmd.org/ | ||
*/ | ||
|
||
class Foo | ||
{ | ||
public function testRuleDoesNotApplyToUntypedParameterWithoutDefaultValue($stuff) | ||
{ | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...urces/files/Rule/CleanCode/BooleanArgumentFlag/testRuleDoesNotApplyToWhitelistedClass.php
This file contains 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,23 @@ | ||
<?php | ||
/** | ||
* This file is part of PHP Mess Detector. | ||
* | ||
* Copyright (c) Manuel Pichler <mapi@phpmd.org>. | ||
* All rights reserved. | ||
* | ||
* Licensed under BSD License | ||
* For full copyright and license information, please see the LICENSE file. | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author Manuel Pichler <mapi@phpmd.org> | ||
* @copyright Manuel Pichler. All rights reserved. | ||
* @license https://opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://phpmd.org/ | ||
*/ | ||
|
||
class MyClass | ||
{ | ||
public function testRuleDoesNotApplyToWhitelistedClass(bool $stuff = false): void | ||
{ | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...rces/files/Rule/CleanCode/BooleanArgumentFlag/testRuleDoesNotApplyToWhitelistedMethod.php
This file contains 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,23 @@ | ||
<?php | ||
/** | ||
* This file is part of PHP Mess Detector. | ||
* | ||
* Copyright (c) Manuel Pichler <mapi@phpmd.org>. | ||
* All rights reserved. | ||
* | ||
* Licensed under BSD License | ||
* For full copyright and license information, please see the LICENSE file. | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author Manuel Pichler <mapi@phpmd.org> | ||
* @copyright Manuel Pichler. All rights reserved. | ||
* @license https://opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://phpmd.org/ | ||
*/ | ||
|
||
class Foo | ||
{ | ||
public function testRuleDoesNotApplyToWhitelistedMethod(bool $stuff = false): void | ||
{ | ||
} | ||
} |