-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UtilityMethodTestCase: safeguard against duplicate test markers
Sister-PR to upstream PHPCSStandards/PHP_CodeSniffer 777 addressing issue PHPCSStandards/PHP_CodeSniffer 773. This commit adds a `testTestMarkersAreUnique()` test method to the `UtilityMethodTestCase` class to automatically verify that the case file in use by the child test class only contains unique test markers. The actual logic for the test is in a custom, `static`, assertion `assertTestMarkersAreUnique()` to allow for calling the assertion directly if an additional test case file is tokenized for the test. Includes unit tests. Includes updating a few tests related to the `UtilityMethodTestCase` itself to not run the `testTestMarkersAreUnique()` test when the test is testing an error condition/doesn't have a valid `$phpcsFile` property set.
- Loading branch information
Showing
13 changed files
with
283 additions
and
0 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
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
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
13 changes: 13 additions & 0 deletions
13
Tests/TestUtils/UtilityMethodTestCase/TestMarkersAreUniqueFailsTest.inc
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,13 @@ | ||
<?php | ||
|
||
/* testMarkerA */ | ||
echo 'hello'; | ||
|
||
/* testMarkerB */ | ||
echo 'hello'; | ||
|
||
/* testMarkerA */ | ||
echo 'hello'; | ||
|
||
/* testMarkerB */ | ||
echo 'hello'; |
45 changes: 45 additions & 0 deletions
45
Tests/TestUtils/UtilityMethodTestCase/TestMarkersAreUniqueFailsTest.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,45 @@ | ||
<?php | ||
/** | ||
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers. | ||
* | ||
* @package PHPCSUtils | ||
* @copyright 2019-2020 PHPCSUtils Contributors | ||
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3 | ||
* @link https://github.com/PHPCSStandards/PHPCSUtils | ||
*/ | ||
|
||
namespace PHPCSUtils\Tests\TestUtils\UtilityMethodTestCase; | ||
|
||
use PHPCSUtils\Tests\PolyfilledTestCase; | ||
|
||
/** | ||
* Tests for the \PHPCSUtils\TestUtils\UtilityMethodTestCase class. | ||
* | ||
* @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::testTestMarkersAreUnique | ||
* @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::assertTestMarkersAreUnique | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
final class TestMarkersAreUniqueFailsTest extends PolyfilledTestCase | ||
{ | ||
|
||
/** | ||
* Overload the "normal" test marker QA check - this test class does not have a valid File object. | ||
* | ||
* @return void | ||
*/ | ||
public function testTestMarkersAreUnique() | ||
{ | ||
$msg = "Duplicate test markers found.\nFailed asserting that "; | ||
$exception = 'PHPUnit\Framework\AssertionFailedError'; | ||
if (\class_exists('PHPUnit_Framework_AssertionFailedError')) { | ||
// PHPUnit < 6. | ||
$exception = 'PHPUnit_Framework_AssertionFailedError'; | ||
} | ||
|
||
$this->expectException($exception); | ||
$this->expectExceptionMessage($msg); | ||
|
||
parent::testTestMarkersAreUnique(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
Tests/TestUtils/UtilityMethodTestCase/TestMarkersAreUniqueNoMarkersTest.inc
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,4 @@ | ||
<?php | ||
|
||
echo 'hello'; | ||
echo 'hello'; |
35 changes: 35 additions & 0 deletions
35
Tests/TestUtils/UtilityMethodTestCase/TestMarkersAreUniqueNoMarkersTest.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,35 @@ | ||
<?php | ||
/** | ||
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers. | ||
* | ||
* @package PHPCSUtils | ||
* @copyright 2019-2020 PHPCSUtils Contributors | ||
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3 | ||
* @link https://github.com/PHPCSStandards/PHPCSUtils | ||
*/ | ||
|
||
namespace PHPCSUtils\Tests\TestUtils\UtilityMethodTestCase; | ||
|
||
use PHPCSUtils\Tests\PolyfilledTestCase; | ||
|
||
/** | ||
* Tests for the \PHPCSUtils\TestUtils\UtilityMethodTestCase class. | ||
* | ||
* @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::testTestMarkersAreUnique | ||
* @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::assertTestMarkersAreUnique | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
final class TestMarkersAreUniqueNoMarkersTest extends PolyfilledTestCase | ||
{ | ||
|
||
/** | ||
* Overload the "normal" test marker QA check, but only to overload the `@covers` tags. | ||
* | ||
* @return void | ||
*/ | ||
public function testTestMarkersAreUnique() | ||
{ | ||
parent::testTestMarkersAreUnique(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Tests/TestUtils/UtilityMethodTestCase/TestMarkersAreUniqueTest.inc
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,13 @@ | ||
<?php | ||
|
||
/* testMarkerA */ | ||
echo 'hello'; | ||
|
||
/* testMarkerB */ | ||
echo 'hello'; | ||
|
||
/* notAMarker */ | ||
echo 'hello'; | ||
|
||
/* testMarkerD */ | ||
echo 'hello'; |
35 changes: 35 additions & 0 deletions
35
Tests/TestUtils/UtilityMethodTestCase/TestMarkersAreUniqueTest.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,35 @@ | ||
<?php | ||
/** | ||
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers. | ||
* | ||
* @package PHPCSUtils | ||
* @copyright 2019-2020 PHPCSUtils Contributors | ||
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3 | ||
* @link https://github.com/PHPCSStandards/PHPCSUtils | ||
*/ | ||
|
||
namespace PHPCSUtils\Tests\TestUtils\UtilityMethodTestCase; | ||
|
||
use PHPCSUtils\Tests\PolyfilledTestCase; | ||
|
||
/** | ||
* Tests for the \PHPCSUtils\TestUtils\UtilityMethodTestCase class. | ||
* | ||
* @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::testTestMarkersAreUnique | ||
* @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::assertTestMarkersAreUnique | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
final class TestMarkersAreUniqueTest extends PolyfilledTestCase | ||
{ | ||
|
||
/** | ||
* Overload the "normal" test marker QA check, but only to overload the `@covers` tags. | ||
* | ||
* @return void | ||
*/ | ||
public function testTestMarkersAreUnique() | ||
{ | ||
parent::testTestMarkersAreUnique(); | ||
} | ||
} |