Skip to content

Commit

Permalink
FindExtendedClassNameTest: Girlscouting
Browse files Browse the repository at this point in the history
Replace all the individual tests which are basically all duplicates of each other, with one test method and a data provider.
  • Loading branch information
jrfnl committed Aug 22, 2018
1 parent 4d88439 commit 2c8e104
Showing 1 changed file with 53 additions and 154 deletions.
207 changes: 53 additions & 154 deletions tests/Core/File/FindExtendedClassNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,180 +60,79 @@ public function tearDown()


/**
* Test a class that extends another.
* Test retrieving the name of the class being extended by another class
* (or interface).
*
* @return void
*/
public function testExtendedClass()
{
$start = ($this->phpcsFile->numTokens - 1);
$class = $this->phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testExtendedClass */'
);

$found = $this->phpcsFile->findExtendedClassName(($class + 2));
$this->assertSame('testFECNClass', $found);

}//end testExtendedClass()


/**
* Test a class that extends another, using namespaces.
* @param string $identifier Comment which preceeds the test case.
* @param bool $expected Expected function output.
*
* @return void
*/
public function testNamespacedClass()
{
$start = ($this->phpcsFile->numTokens - 1);
$class = $this->phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testNamespacedClass */'
);

$found = $this->phpcsFile->findExtendedClassName(($class + 2));
$this->assertSame('\PHP_CodeSniffer\Tests\Core\File\testFECNClass', $found);

}//end testNamespacedClass()


/**
* Test a class that doesn't extend another.
* @dataProvider dataExtendedClass
*
* @return void
*/
public function testNonExtendedClass()
public function testFindExtendedClassName($identifier, $expected)
{
$start = ($this->phpcsFile->numTokens - 1);
$class = $this->phpcsFile->findPrevious(
$start = ($this->phpcsFile->numTokens - 1);
$delim = $this->phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testNonExtendedClass */'
$identifier
);
$OOToken = $this->phpcsFile->findNext([T_CLASS, T_ANON_CLASS, T_INTERFACE], ($delim + 1));

$found = $this->phpcsFile->findExtendedClassName(($class + 2));
$this->assertFalse($found);
$result = $this->phpcsFile->findExtendedClassName($OOToken);
$this->assertSame($expected, $result);

}//end testNonExtendedClass()
}//end testFindExtendedClassName()


/**
* Test an interface.
* Data provider for the FindExtendedClassName test.
*
* @return void
*/
public function testInterface()
{
$start = ($this->phpcsFile->numTokens - 1);
$class = $this->phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testInterface */'
);

$found = $this->phpcsFile->findExtendedClassName(($class + 2));
$this->assertFalse($found);

}//end testInterface()


/**
* Test an interface that extends another.
* @see testFindExtendedClassName()
*
* @return void
* @return array
*/
public function testExtendedInterface()
public function dataExtendedClass()
{
$start = ($this->phpcsFile->numTokens - 1);
$class = $this->phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testInterfaceThatExtendsInterface */'
);

$found = $this->phpcsFile->findExtendedClassName(($class + 2));
$this->assertSame('testFECNInterface', $found);

}//end testExtendedInterface()


/**
* Test an interface that extends another, using namespaces.
*
* @return void
*/
public function testExtendedNamespacedInterface()
{
$start = ($this->phpcsFile->numTokens - 1);
$class = $this->phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testInterfaceThatExtendsFQCNInterface */'
);

$found = $this->phpcsFile->findExtendedClassName(($class + 2));
$this->assertSame('\PHP_CodeSniffer\Tests\Core\File\testFECNInterface', $found);

}//end testExtendedNamespacedInterface()


/**
* Test a non-extended class with a nested class which does extend another class.
*
* @return void
*/
public function testNestedExtendedClass()
{
$start = ($this->phpcsFile->numTokens - 1);
$class = $this->phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testNestedExtendedClass */'
);

$found = $this->phpcsFile->findExtendedClassName(($class + 2));
$this->assertFalse($found);

}//end testNestedExtendedClass()


/**
* Test a nested anonymous class that extends a named class.
*
* @return void
*/
public function testNestedExtendedAnonClass()
{
$start = ($this->phpcsFile->numTokens - 1);
$class = $this->phpcsFile->findPrevious(
T_COMMENT,
$start,
null,
false,
'/* testNestedExtendedAnonClass */'
);
$class = $this->phpcsFile->findNext(T_ANON_CLASS, ($class + 1));

$found = $this->phpcsFile->findExtendedClassName($class);
$this->assertSame('testFECNAnonClass', $found);

}//end testNestedExtendedAnonClass()
return [
[
'/* testExtendedClass */',
'testFECNClass',
],
[
'/* testNamespacedClass */',
'\PHP_CodeSniffer\Tests\Core\File\testFECNClass',
],
[
'/* testNonExtendedClass */',
false,
],
[
'/* testInterface */',
false,
],
[
'/* testInterfaceThatExtendsInterface */',
'testFECNInterface',
],
[
'/* testInterfaceThatExtendsFQCNInterface */',
'\PHP_CodeSniffer\Tests\Core\File\testFECNInterface',
],
[
'/* testNestedExtendedClass */',
false,
],
[
'/* testNestedExtendedAnonClass */',
'testFECNAnonClass',
],
];

}//end dataExtendedClass()


}//end class

0 comments on commit 2c8e104

Please sign in to comment.