Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Request #16209 Sniffs for PHPUnit tests that to not assert anything
Submitted: 2009-05-09 15:12 UTC
From: sebastian Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version CVS)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 26 - 15 = ?

 
 [2009-05-09 15:12 UTC] sebastian (Sebastian Bergmann)
Description: ------------ A case of "useless tests" that I see from time to time is that developers write tests that execution SUT code without asserting -- thus not actually testing -- anything. The sniff should raise a warning when the following conditions are met: - Class has PHPUnit_Framework_TestCase as an ancestor - Method is public and has name test*() or the @test annotation - The method itself (and other methods called from it) does not call $this->assert*(), self::assert*(), or PHPUnit_Framework_Assert::assert*() and does not set up a mock object with expectations. Test script: --------------- . Expected result: ---------------- . Actual result: -------------- .

Comments

 [2009-05-10 09:29 UTC] doconnor (Daniel O'Connor)
Would this be easier to implement in PHPUnit itself? IE, PHPUnit's already got easy ways to tell when you are running a method named test, count assertations, etc.
 [2009-07-02 12:41 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Assigned -Assigned To: +Assigned To: squiz
 [2010-07-07 12:30 UTC] benmatselby (Ben Selby)
I have no implemented this in PHPUnit 3.5, so not sure if anyone wants this still implementing in PHP_CodeSniffer?
 [2010-07-09 09:35 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Closed
No need to add to PHPCS if PHPUnit does it. Thanks for sending that info through.