@@ -275,13 +275,13 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass) {
275275 */
276276 public function testThatDataProvidersAreCorrectlyNamed ($ testClassName )
277277 {
278- $ dataProviderMethodNames = $ this ->getDataProviderMethodNames ($ testClassName );
278+ $ usedDataProviderMethodNames = $ this ->getUsedDataProviderMethodNames ($ testClassName );
279279
280280 if (empty ($ dataProviderMethodNames )) {
281281 $ this ->addToAssertionCount (1 ); // no data providers to test, all good!
282282 }
283283
284- foreach ($ dataProviderMethodNames as $ dataProviderMethodName ) {
284+ foreach ($ usedDataProviderMethodNames as $ dataProviderMethodName ) {
285285 static ::assertRegExp ('/^provide[A-Z]\S+Cases$/ ' , $ dataProviderMethodName , sprintf (
286286 'Data provider in "%s" with name "%s" is not correctly named. ' ,
287287 $ testClassName ,
@@ -290,6 +290,38 @@ public function testThatDataProvidersAreCorrectlyNamed($testClassName)
290290 }
291291 }
292292
293+ /**
294+ * @dataProvider provideTestClassCases
295+ *
296+ * @param string $testClassName
297+ */
298+ public function testThatDataProvidersAreUsed ($ testClassName )
299+ {
300+ $ reflectionClass = new \ReflectionClass ($ testClassName );
301+
302+ $ definedDataProviders = array_filter (
303+ $ reflectionClass ->getMethods (\ReflectionMethod::IS_PUBLIC ),
304+ static function (\ReflectionMethod $ reflectionMethod ) use ($ reflectionClass ) {
305+ return $ reflectionMethod ->getDeclaringClass ()->getName () === $ reflectionClass ->getName ()
306+ && 'provide ' === substr ($ reflectionMethod ->getName (), 0 , 7 );
307+ }
308+ );
309+
310+ if ($ definedDataProviders === []) {
311+ $ this ->addToAssertionCount (1 ); // no methods to test, all good!
312+ }
313+
314+ $ usedDataProviderMethodNames = $ this ->getUsedDataProviderMethodNames ($ testClassName );
315+
316+ foreach ($ definedDataProviders as $ definedDataProvider ) {
317+ static ::assertContains (
318+ $ definedDataProvider ->getName (),
319+ $ usedDataProviderMethodNames ,
320+ sprintf ('Data provider in "%s" with name "%s" is not used. ' , $ definedDataProvider ->getDeclaringClass ()->getName (), $ definedDataProvider ->getName ())
321+ );
322+ }
323+ }
324+
293325 /**
294326 * @dataProvider provideClassesWherePregFunctionsAreForbiddenCases
295327 *
@@ -406,7 +438,7 @@ static function ($className) {
406438 );
407439 }
408440
409- private function getDataProviderMethodNames ($ testClassName )
441+ private function getUsedDataProviderMethodNames ($ testClassName )
410442 {
411443 $ dataProviderMethodNames = [];
412444 $ tokens = Tokens::fromCode (file_get_contents (
0 commit comments