Skip to content

Commit d997e9c

Browse files
committed
Tests/FindImplementedInterfaceNamesTest: 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 623deda commit d997e9c

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

tests/Core/File/FindImplementedInterfaceNamesTest.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class FindImplementedInterfaceNamesTest extends AbstractMethodUnitTest
2323
/**
2424
* Test retrieving the name(s) of the interfaces being implemented by a class.
2525
*
26-
* @param string $identifier Comment which precedes the test case.
27-
* @param bool $expected Expected function output.
26+
* @param string $identifier Comment which precedes the test case.
27+
* @param array<string>|false $expected Expected function output.
2828
*
2929
* @dataProvider dataImplementedInterface
3030
*
@@ -44,59 +44,59 @@ public function testFindImplementedInterfaceNames($identifier, $expected)
4444
*
4545
* @see testFindImplementedInterfaceNames()
4646
*
47-
* @return array
47+
* @return array<string, array<string, string|array<string>>>
4848
*/
4949
public function dataImplementedInterface()
5050
{
5151
return [
52-
[
53-
'/* testClassImplementsSingle */',
54-
['testFIINInterface'],
52+
'class implements single interface, unqualified' => [
53+
'identifier' => '/* testClassImplementsSingle */',
54+
'expected' => ['testFIINInterface'],
5555
],
56-
[
57-
'/* testClassImplementsMultiple */',
58-
[
56+
'class implements multiple interfaces' => [
57+
'identifier' => '/* testClassImplementsMultiple */',
58+
'expected' => [
5959
'testFIINInterface',
6060
'testFIINInterface2',
6161
],
6262
],
63-
[
64-
'/* testImplementsFullyQualified */',
65-
['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface'],
63+
'class implements single interface, fully qualified' => [
64+
'identifier' => '/* testImplementsFullyQualified */',
65+
'expected' => ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface'],
6666
],
67-
[
68-
'/* testNonImplementedClass */',
69-
false,
67+
'class does not implement' => [
68+
'identifier' => '/* testNonImplementedClass */',
69+
'expected' => false,
7070
],
71-
[
72-
'/* testPlainInterface */',
73-
false,
71+
'interface declaration, no implements' => [
72+
'identifier' => '/* testPlainInterface */',
73+
'expected' => false,
7474
],
75-
[
76-
'/* testClassThatExtendsAndImplements */',
77-
[
75+
'class extends and implements' => [
76+
'identifier' => '/* testClassThatExtendsAndImplements */',
77+
'expected' => [
7878
'InterfaceA',
7979
'\NameSpaced\Cat\InterfaceB',
8080
],
8181
],
82-
[
83-
'/* testClassThatImplementsAndExtends */',
84-
[
82+
'class implements and extends' => [
83+
'identifier' => '/* testClassThatImplementsAndExtends */',
84+
'expected' => [
8585
'\InterfaceA',
8686
'InterfaceB',
8787
],
8888
],
89-
[
90-
'/* testBackedEnumWithoutImplements */',
91-
false,
89+
'enum does not implement' => [
90+
'identifier' => '/* testBackedEnumWithoutImplements */',
91+
'expected' => false,
9292
],
93-
[
94-
'/* testEnumImplementsSingle */',
95-
['Colorful'],
93+
'enum implements single interface, unqualified' => [
94+
'identifier' => '/* testEnumImplementsSingle */',
95+
'expected' => ['Colorful'],
9696
],
97-
[
98-
'/* testBackedEnumImplementsMulti */',
99-
[
97+
'enum implements multiple interfaces, unqualified + fully qualified' => [
98+
'identifier' => '/* testBackedEnumImplementsMulti */',
99+
'expected' => [
100100
'Colorful',
101101
'\Deck',
102102
],

0 commit comments

Comments
 (0)