Skip to content

Commit

Permalink
Implement use of the new AbstractMethodUnitTest::getTargetToken() method
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Aug 27, 2019
1 parent abad7a0 commit 281fc7d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 155 deletions.
13 changes: 2 additions & 11 deletions tests/Core/File/FindExtendedClassNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,8 @@ class FindExtendedClassNameTest extends AbstractMethodUnitTest
*/
public function testFindExtendedClassName($identifier, $expected)
{
$start = (self::$phpcsFile->numTokens - 1);
$delim = self::$phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
$identifier
);
$OOToken = self::$phpcsFile->findNext([T_CLASS, T_ANON_CLASS, T_INTERFACE], ($delim + 1));

$result = self::$phpcsFile->findExtendedClassName($OOToken);
$OOToken = $this->getTargetToken($identifier, [T_CLASS, T_ANON_CLASS, T_INTERFACE]);
$result = self::$phpcsFile->findExtendedClassName($OOToken);
$this->assertSame($expected, $result);

}//end testFindExtendedClassName()
Expand Down
13 changes: 2 additions & 11 deletions tests/Core/File/FindImplementedInterfaceNamesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,8 @@ class FindImplementedInterfaceNamesTest extends AbstractMethodUnitTest
*/
public function testFindImplementedInterfaceNames($identifier, $expected)
{
$start = (self::$phpcsFile->numTokens - 1);
$delim = self::$phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
$identifier
);
$OOToken = self::$phpcsFile->findNext([T_CLASS, T_ANON_CLASS, T_INTERFACE], ($delim + 1));

$result = self::$phpcsFile->findImplementedInterfaceNames($OOToken);
$OOToken = $this->getTargetToken($identifier, [T_CLASS, T_ANON_CLASS, T_INTERFACE]);
$result = self::$phpcsFile->findImplementedInterfaceNames($OOToken);
$this->assertSame($expected, $result);

}//end testFindImplementedInterfaceNames()
Expand Down
37 changes: 5 additions & 32 deletions tests/Core/File/GetMemberPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,8 @@ class GetMemberPropertiesTest extends AbstractMethodUnitTest
*/
public function testGetMemberProperties($identifier, $expected)
{
$start = (self::$phpcsFile->numTokens - 1);
$delim = self::$phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
$identifier
);
$variable = self::$phpcsFile->findNext(T_VARIABLE, ($delim + 1));

$result = self::$phpcsFile->getMemberProperties($variable);
$variable = $this->getTargetToken($identifier, T_VARIABLE);
$result = self::$phpcsFile->getMemberProperties($variable);
unset($result['type_token']);
unset($result['type_end_token']);
$this->assertSame($expected, $result);
Expand Down Expand Up @@ -488,17 +479,8 @@ public function dataGetMemberProperties()
*/
public function testNotClassPropertyException($identifier)
{
$start = (self::$phpcsFile->numTokens - 1);
$delim = self::$phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
$identifier
);
$variable = self::$phpcsFile->findNext(T_VARIABLE, ($delim + 1));

$result = self::$phpcsFile->getMemberProperties($variable);
$variable = $this->getTargetToken($identifier, T_VARIABLE);
$result = self::$phpcsFile->getMemberProperties($variable);

}//end testNotClassPropertyException()

Expand Down Expand Up @@ -534,16 +516,7 @@ public function dataNotClassProperty()
*/
public function testNotAVariableException()
{
$start = (self::$phpcsFile->numTokens - 1);
$delim = self::$phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testNotAVariable */'
);
$next = self::$phpcsFile->findNext(T_WHITESPACE, ($delim + 1), null, true);

$next = $this->getTargetToken('/* testNotAVariable */', T_RETURN);
$result = self::$phpcsFile->getMemberProperties($next);

}//end testNotAVariableException()
Expand Down
90 changes: 45 additions & 45 deletions tests/Core/File/IsReferenceTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,137 +2,137 @@

namespace PHP_CodeSniffer\Tests\Core\File;

/* bitwiseAndA */
/* testBitwiseAndA */
error_reporting( E_NOTICE & E_STRICT );

/* bitwiseAndB */
/* testBitwiseAndB */
$a = [ $something & $somethingElse ];

/* bitwiseAndC */
/* testBitwiseAndC */
$a = [ $first, $something & self::$somethingElse ];

/* bitwiseAndD */
/* testBitwiseAndD */
$a = array $first, $something & $somethingElse );

/* bitwiseAndE */
/* testBitwiseAndE */
$a = [ 'a' => $first, 'b' => $something & $somethingElse ];

/* bitwiseAndF */
/* testBitwiseAndF */
$a = array( 'a' => $first, 'b' => $something & \MyClass::$somethingElse );

/* bitwiseAndG */
/* testBitwiseAndG */
$a = $something & $somethingElse;

/* bitwiseAndH */
/* testBitwiseAndH */
function myFunction($a = 10 & 20) {}

/* bitwiseAndI */
/* testBitwiseAndI */
$closure = function ($a = MY_CONSTANT & parent::OTHER_CONSTANT) {};

/* functionReturnByReference */
/* testFunctionReturnByReference */
function &myFunction() {}

/* functionPassByReferenceA */
/* testFunctionPassByReferenceA */
function myFunction( &$a ) {}

/* functionPassByReferenceB */
/* testFunctionPassByReferenceB */
function myFunction( $a, &$b ) {}

/* functionPassByReferenceC */
/* testFunctionPassByReferenceC */
$closure = function ( &$a ) {};

/* functionPassByReferenceD */
/* testFunctionPassByReferenceD */
$closure = function ( $a, &$b ) {};

/* functionPassByReferenceE */
/* testFunctionPassByReferenceE */
function myFunction(array &$one) {}

/* functionPassByReferenceF */
/* testFunctionPassByReferenceF */
$closure = function (\MyClass &$one) {};

/* functionPassByReferenceG */
/* testFunctionPassByReferenceG */
$closure = function myFunc($param, &...$moreParams) {};

/* foreachValueByReference */
/* testForeachValueByReference */
foreach( $array as $key => &$value ) {}

/* foreachKeyByReference */
/* testForeachKeyByReference */
foreach( $array as &$key => $value ) {}

/* arrayValueByReferenceA */
/* testArrayValueByReferenceA */
$a = [ 'a' => &$something ];

/* arrayValueByReferenceB */
/* testArrayValueByReferenceB */
$a = [ 'a' => $something, 'b' => &$somethingElse ];

/* arrayValueByReferenceC */
/* testArrayValueByReferenceC */
$a = [ &$something ];

/* arrayValueByReferenceD */
/* testArrayValueByReferenceD */
$a = [ $something, &$somethingElse ];

/* arrayValueByReferenceE */
/* testArrayValueByReferenceE */
$a = array( 'a' => &$something );

/* arrayValueByReferenceF */
/* testArrayValueByReferenceF */
$a = array( 'a' => $something, 'b' => &$somethingElse );

/* arrayValueByReferenceG */
/* testArrayValueByReferenceG */
$a = array( &$something );

/* arrayValueByReferenceH */
/* testArrayValueByReferenceH */
$a = array( $something, &$somethingElse );

/* assignByReferenceA */
/* testAssignByReferenceA */
$b = &$something;

/* assignByReferenceB */
/* testAssignByReferenceB */
$b =& $something;

/* assignByReferenceC */
/* testAssignByReferenceC */
$b .= &$something;

/* assignByReferenceD */
/* testAssignByReferenceD */
$myValue = &$obj->getValue();

/* assignByReferenceE */
/* testAssignByReferenceE */
$collection = &collector();

/* passByReferenceA */
/* testPassByReferenceA */
functionCall(&$something, $somethingElse);

/* passByReferenceB */
/* testPassByReferenceB */
functionCall($something, &$somethingElse);

/* passByReferenceC */
/* testPassByReferenceC */
functionCall($something, &$this->somethingElse);

/* passByReferenceD */
/* testPassByReferenceD */
functionCall($something, &self::$somethingElse);

/* passByReferenceE */
/* testPassByReferenceE */
functionCall($something, &parent::$somethingElse);

/* passByReferenceF */
/* testPassByReferenceF */
functionCall($something, &static::$somethingElse);

/* passByReferenceG */
/* testPassByReferenceG */
functionCall($something, &SomeClass::$somethingElse);

/* passByReferenceH */
/* testPassByReferenceH */
functionCall(&\SomeClass::$somethingElse);

/* passByReferenceI */
/* testPassByReferenceI */
functionCall($something, &\SomeNS\SomeClass::$somethingElse);

/* passByReferenceJ */
/* testPassByReferenceJ */
functionCall($something, &namespace\SomeClass::$somethingElse);

/* newByReferenceA */
/* testNewByReferenceA */
$foobar2 = &new Foobar();

/* newByReferenceB */
/* testNewByReferenceB */
functionCall( $something , &new Foobar() );

/* useByReference */
/* testUseByReference */
$closure = function() use (&$var){};
Loading

0 comments on commit 281fc7d

Please sign in to comment.