Skip to content

Commit 183b458

Browse files
committed
BCFile::getMethodParameters(): sync with PHPCS 4.0 / T_USE is parenthesis owner
This change was already previously handled in PHPCSUtils. This commit just syncs in the new tests as introduced upstream. Ref: PHPCSStandards/PHP_CodeSniffer 1013
1 parent 57e8980 commit 183b458

File tree

6 files changed

+214
-0
lines changed

6 files changed

+214
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
// Intentional parse error. Missing closure use parentheses. This should be the only test in the file.
4+
/* testParseError */
5+
$cl = function ($a) use
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
4+
*
5+
* @package PHPCSUtils
6+
* @copyright 2019-2020 PHPCSUtils Contributors
7+
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
8+
* @link https://github.com/PHPCSStandards/PHPCSUtils
9+
*/
10+
11+
namespace PHPCSUtils\Tests\BackCompat\BCFile;
12+
13+
use PHPCSUtils\BackCompat\BCFile;
14+
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
15+
16+
/**
17+
* Tests for the \PHPCSUtils\BackCompat\BCFile::getMethodParameters method.
18+
*
19+
* @covers \PHPCSUtils\BackCompat\BCFile::getMethodParameters
20+
*
21+
* @group functiondeclarations
22+
*
23+
* @since 1.1.0
24+
*/
25+
final class GetMethodParametersParseError3Test extends UtilityMethodTestCase
26+
{
27+
28+
/**
29+
* Test receiving an exception when encountering a specific parse error.
30+
*
31+
* @return void
32+
*/
33+
public function testParseError()
34+
{
35+
$this->expectPhpcsException('$stackPtr was not a valid T_USE');
36+
37+
$target = $this->getTargetToken('/* testParseError */', [\T_USE]);
38+
BCFile::getMethodParameters(self::$phpcsFile, $target);
39+
}
40+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
// Intentional parse error. Missing closure use close parenthesis. This should be the only test in the file.
4+
/* testParseError */
5+
$cl = function ($a) use (
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
4+
*
5+
* @package PHPCSUtils
6+
* @copyright 2019-2020 PHPCSUtils Contributors
7+
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
8+
* @link https://github.com/PHPCSStandards/PHPCSUtils
9+
*/
10+
11+
namespace PHPCSUtils\Tests\BackCompat\BCFile;
12+
13+
use PHPCSUtils\BackCompat\BCFile;
14+
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
15+
16+
/**
17+
* Tests for the \PHPCSUtils\BackCompat\BCFile::getMethodParameters method.
18+
*
19+
* @covers \PHPCSUtils\BackCompat\BCFile::getMethodParameters
20+
*
21+
* @group functiondeclarations
22+
*
23+
* @since 1.1.0
24+
*/
25+
final class GetMethodParametersParseError4Test extends UtilityMethodTestCase
26+
{
27+
28+
/**
29+
* Test receiving an empty array when encountering a specific parse error.
30+
*
31+
* @return void
32+
*/
33+
public function testParseError()
34+
{
35+
$target = $this->getTargetToken('/* testParseError */', [\T_USE]);
36+
$result = BCFile::getMethodParameters(self::$phpcsFile, $target);
37+
38+
$this->assertSame([], $result);
39+
}
40+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
4+
*
5+
* @package PHPCSUtils
6+
* @copyright 2019-2020 PHPCSUtils Contributors
7+
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
8+
* @link https://github.com/PHPCSStandards/PHPCSUtils
9+
*/
10+
11+
namespace PHPCSUtils\Tests\Utils\FunctionDeclarations;
12+
13+
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
14+
use PHPCSUtils\Utils\FunctionDeclarations;
15+
16+
/**
17+
* Tests for the \PHPCSUtils\Utils\FunctionDeclarations::getParameters method.
18+
*
19+
* @covers \PHPCSUtils\Utils\FunctionDeclarations::getParameters
20+
*
21+
* @group functiondeclarations
22+
*
23+
* @since 1.1.0
24+
*/
25+
final class GetParametersParseError3Test extends UtilityMethodTestCase
26+
{
27+
28+
/**
29+
* Full path to the test case file associated with this test class.
30+
*
31+
* @var string
32+
*/
33+
protected static $caseFile = '';
34+
35+
/**
36+
* Initialize PHPCS & tokenize the test case file.
37+
*
38+
* Overloaded to re-use the `$caseFile` from the BCFile test.
39+
*
40+
* @beforeClass
41+
*
42+
* @return void
43+
*/
44+
public static function setUpTestFile()
45+
{
46+
self::$caseFile = \dirname(\dirname(__DIR__)) . '/BackCompat/BCFile/GetMethodParametersParseError3Test.inc';
47+
parent::setUpTestFile();
48+
}
49+
50+
/**
51+
* Test receiving an exception when encountering a specific parse error.
52+
*
53+
* @return void
54+
*/
55+
public function testParseError()
56+
{
57+
$this->expectPhpcsException('The value of argument #2 ($stackPtr) must be the pointer to a closure use statement');
58+
59+
$target = $this->getTargetToken('/* testParseError */', [\T_USE]);
60+
FunctionDeclarations::getParameters(self::$phpcsFile, $target);
61+
}
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
4+
*
5+
* @package PHPCSUtils
6+
* @copyright 2019-2020 PHPCSUtils Contributors
7+
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
8+
* @link https://github.com/PHPCSStandards/PHPCSUtils
9+
*/
10+
11+
namespace PHPCSUtils\Tests\Utils\FunctionDeclarations;
12+
13+
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
14+
use PHPCSUtils\Utils\FunctionDeclarations;
15+
16+
/**
17+
* Tests for the \PHPCSUtils\Utils\FunctionDeclarations::getParameters method.
18+
*
19+
* @covers \PHPCSUtils\Utils\FunctionDeclarations::getParameters
20+
*
21+
* @group functiondeclarations
22+
*
23+
* @since 1.1.0
24+
*/
25+
final class GetParametersParseError4Test extends UtilityMethodTestCase
26+
{
27+
28+
/**
29+
* Full path to the test case file associated with this test class.
30+
*
31+
* @var string
32+
*/
33+
protected static $caseFile = '';
34+
35+
/**
36+
* Initialize PHPCS & tokenize the test case file.
37+
*
38+
* Overloaded to re-use the `$caseFile` from the BCFile test.
39+
*
40+
* @beforeClass
41+
*
42+
* @return void
43+
*/
44+
public static function setUpTestFile()
45+
{
46+
self::$caseFile = \dirname(\dirname(__DIR__)) . '/BackCompat/BCFile/GetMethodParametersParseError4Test.inc';
47+
parent::setUpTestFile();
48+
}
49+
50+
/**
51+
* Test receiving an empty array when encountering a specific parse error.
52+
*
53+
* @return void
54+
*/
55+
public function testParseError()
56+
{
57+
$target = $this->getTargetToken('/* testParseError */', [\T_USE]);
58+
$result = FunctionDeclarations::getParameters(self::$phpcsFile, $target);
59+
60+
$this->assertSame([], $result);
61+
}
62+
}

0 commit comments

Comments
 (0)