1515use PHPUnit \Framework \TestCase ;
1616use Symfony \Component \Finder \Finder ;
1717use Symfony \Component \Finder \SplFileInfo ;
18+ use Tests \Fixer \AbstractFixerTestCase ;
1819
1920/**
2021 * @internal
@@ -84,13 +85,9 @@ public function testDataProvidersKeys(string $className): void
8485
8586 foreach ($ dataProviders as $ dataProvider ) {
8687 $ dataSet = $ dataProvider ->invoke (null );
87- \assert (\is_array ( $ dataSet) || $ dataSet instanceof \Generator );
88+ \assert ($ dataSet instanceof \Iterator );
8889
89- if ($ dataSet instanceof \Generator) {
90- $ dataSet = \iterator_to_array ($ dataSet );
91- }
92-
93- foreach (\array_keys ($ dataSet ) as $ key ) {
90+ foreach (\array_keys (\iterator_to_array ($ dataSet )) as $ key ) {
9491 if (!\is_string ($ key )) {
9592 self ::markTestIncomplete (\sprintf (
9693 'Data provider "%s" in class "%s" has non-string keys. ' ,
@@ -106,6 +103,48 @@ public function testDataProvidersKeys(string $className): void
106103 }
107104 }
108105
106+ /**
107+ * @dataProvider provideTestClassCases
108+ */
109+ public function testDataProvidersValues (string $ className ): void
110+ {
111+ if (!\is_subclass_of ($ className , AbstractFixerTestCase::class)) {
112+ $ this ->expectNotToPerformAssertions ();
113+
114+ return ;
115+ }
116+
117+ $ dataProviders = $ this ->getDataProviders ($ className );
118+
119+ foreach ($ dataProviders as $ dataProvider ) {
120+ $ dataSet = $ dataProvider ->invoke (null );
121+ \assert ($ dataSet instanceof \Iterator);
122+ $ dataSet = \iterator_to_array ($ dataSet );
123+
124+ $ doNotChangeCases = [];
125+ foreach ($ dataSet as $ value ) {
126+ if (\array_key_exists (1 , $ value ) && $ value [1 ] !== null ) {
127+ continue ;
128+ }
129+ $ doNotChangeCases [] = $ value [0 ];
130+ }
131+ foreach ($ dataSet as $ value ) {
132+ if (!\array_key_exists (1 , $ value ) || $ value [1 ] === null ) {
133+ continue ;
134+ }
135+ self ::assertFalse (
136+ \in_array ($ value [0 ], $ doNotChangeCases , true ),
137+ \sprintf (
138+ "Expected value: \n%s \nis already tested if it is not changing, it does not need separate test case (%s::%s). " ,
139+ $ value [0 ],
140+ $ className ,
141+ $ dataProvider ->getName ()
142+ )
143+ );
144+ }
145+ }
146+ }
147+
109148 /**
110149 * @return array<\ReflectionMethod>
111150 */
@@ -159,6 +198,8 @@ public static function provideTestClassCases(): iterable
159198 $ className .= '\\' . $ file ->getBasename ('.php ' );
160199 $ tests [$ className ] = [$ className ];
161200 }
201+
202+ $ tests = new \ArrayIterator ($ tests );
162203 }
163204
164205 return $ tests ;
0 commit comments