Skip to content

Commit f627f0e

Browse files
committed
Tests/FindExtendedClassNameTest: use named data sets
With non-named data sets, when a test fails, PHPUnit will display the number of the test which failed. With tests which have a _lot_ of data sets, this makes it _interesting_ (and time-consuming) to debug those, as one now has to figure out which of the data sets in the data provider corresponds to that number. Using named data sets makes debugging failing tests more straight forward as PHPUnit will display the data set name instead of the number. Using named data sets also documents what exactly each data set is testing. Aside from adding the data set name, this commit also adds the parameter name for each item in the data set, this time in an effort to make it more straight forward to update and add tests as it will be more obvious what each key in the data set signifies. Includes fixing the data types in the docblocks and making them more specific, where relevant.
1 parent 976547d commit f627f0e

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

tests/Core/File/FindExtendedClassNameTest.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class FindExtendedClassNameTest extends AbstractMethodUnitTest
2424
* Test retrieving the name of the class being extended by another class
2525
* (or interface).
2626
*
27-
* @param string $identifier Comment which precedes the test case.
28-
* @param bool $expected Expected function output.
27+
* @param string $identifier Comment which precedes the test case.
28+
* @param string|false $expected Expected function output.
2929
*
3030
* @dataProvider dataExtendedClass
3131
*
@@ -45,50 +45,50 @@ public function testFindExtendedClassName($identifier, $expected)
4545
*
4646
* @see testFindExtendedClassName()
4747
*
48-
* @return array
48+
* @return array<string, array<string, string|false>>
4949
*/
5050
public function dataExtendedClass()
5151
{
5252
return [
53-
[
54-
'/* testExtendsUnqualifiedClass */',
55-
'testFECNClass',
53+
'class extends unqualified class' => [
54+
'identifier' => '/* testExtendsUnqualifiedClass */',
55+
'expected' => 'testFECNClass',
5656
],
57-
[
58-
'/* testExtendsFullyQualifiedClass */',
59-
'\PHP_CodeSniffer\Tests\Core\File\testFECNClass',
57+
'class extends fully qualified class' => [
58+
'identifier' => '/* testExtendsFullyQualifiedClass */',
59+
'expected' => '\PHP_CodeSniffer\Tests\Core\File\testFECNClass',
6060
],
61-
[
62-
'/* testNonExtendedClass */',
63-
false,
61+
'class does not extend' => [
62+
'identifier' => '/* testNonExtendedClass */',
63+
'expected' => false,
6464
],
65-
[
66-
'/* testNonExtendedInterface */',
67-
false,
65+
'interface does not extend' => [
66+
'identifier' => '/* testNonExtendedInterface */',
67+
'expected' => false,
6868
],
69-
[
70-
'/* testInterfaceExtendsUnqualifiedInterface */',
71-
'testFECNInterface',
69+
'interface extends unqualified interface' => [
70+
'identifier' => '/* testInterfaceExtendsUnqualifiedInterface */',
71+
'expected' => 'testFECNInterface',
7272
],
73-
[
74-
'/* testInterfaceExtendsFullyQualifiedInterface */',
75-
'\PHP_CodeSniffer\Tests\Core\File\testFECNInterface',
73+
'interface extends fully qualified interface' => [
74+
'identifier' => '/* testInterfaceExtendsFullyQualifiedInterface */',
75+
'expected' => '\PHP_CodeSniffer\Tests\Core\File\testFECNInterface',
7676
],
77-
[
78-
'/* testNestedExtendedClass */',
79-
false,
77+
'class does not extend but contains anon class which extends' => [
78+
'identifier' => '/* testNestedExtendedClass */',
79+
'expected' => false,
8080
],
81-
[
82-
'/* testNestedExtendedAnonClass */',
83-
'testFECNAnonClass',
81+
'anon class extends, nested in non-extended class' => [
82+
'identifier' => '/* testNestedExtendedAnonClass */',
83+
'expected' => 'testFECNAnonClass',
8484
],
85-
[
86-
'/* testClassThatExtendsAndImplements */',
87-
'testFECNClass',
85+
'class extends and implements' => [
86+
'identifier' => '/* testClassThatExtendsAndImplements */',
87+
'expected' => 'testFECNClass',
8888
],
89-
[
90-
'/* testClassThatImplementsAndExtends */',
91-
'testFECNClass',
89+
'class implements and extends' => [
90+
'identifier' => '/* testClassThatImplementsAndExtends */',
91+
'expected' => 'testFECNClass',
9292
],
9393
];
9494

0 commit comments

Comments
 (0)