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 #372 from PHPCSStandards/testutils/utilitymethodte…
…stcase-gettargettoken-throw-on-missing-marker UtilityMethodTestCase::getTargetToken(): throw an exception when delimiter not found
- Loading branch information
Showing
4 changed files
with
88 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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\Exceptions; | ||
|
||
use OutOfBoundsException; | ||
|
||
/** | ||
* Exception thrown when a delimiter comment can not be found in a test case file. | ||
* | ||
* @since 1.0.0-alpha4 | ||
*/ | ||
final class TestMarkerNotFound extends OutOfBoundsException | ||
{ | ||
|
||
/** | ||
* Create a new "test marker not found" exception with a standardized text. | ||
* | ||
* @since 1.0.0-alpha4 | ||
* | ||
* @param string $marker The delimiter comment. | ||
* @param string $file The file in which the delimiter was not found. | ||
* | ||
* @return \PHPCSUtils\Exceptions\TestMarkerNotFound | ||
*/ | ||
public static function create($marker, $file) | ||
{ | ||
return new self( | ||
\sprintf( | ||
'Failed to find the test marker: %s in test case file %s', | ||
$marker, | ||
$file | ||
) | ||
); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
Tests/Exceptions/TestMarkerNotFound/TestMarkerNotFoundTest.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,38 @@ | ||
<?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\Exceptions\TestMarkerNotFound; | ||
|
||
use PHPCSUtils\Exceptions\TestMarkerNotFound; | ||
use Yoast\PHPUnitPolyfills\TestCases\TestCase; | ||
|
||
/** | ||
* Test class. | ||
* | ||
* @covers \PHPCSUtils\Exceptions\TestMarkerNotFound | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
final class TestMarkerNotFoundTest extends TestCase | ||
{ | ||
|
||
/** | ||
* Test that the text of the exception is as expected. | ||
* | ||
* @return void | ||
*/ | ||
public function testCreate() | ||
{ | ||
$this->expectException('PHPCSUtils\Exceptions\TestMarkerNotFound'); | ||
$this->expectExceptionMessage('Failed to find the test marker: /* testDummy */ in test case file filename.inc'); | ||
|
||
throw TestMarkerNotFound::create('/* testDummy */', 'filename.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