Php-cs-fixer: PHPUnit setup and teardown methods should be protected

Created on 13 Feb 2017  路  4Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

What about fixing PHPUnit setup() and teardown() methods to be protected when they are public? That's a common mistake and would be nice to have a fixed for that.

kinfeature request

Most helpful comment

While you're at it, rename setup to setUp and teardown to tearDown.

All 4 comments

Would be nice to fixer.

How would the detection if we are fixing a utest class look like (as both methods might be used in other classes as well);

  • must be method of a utest class
  • class is a likely to be a utest class if declared in a namespace that contains test; or
  • class extends \PHPUnit_Framework_TestCase; or
  • class name ends with Test

Still risky fixer as all tests would not be fool proof, wonder if others have an idea to do the detection better :)

Not worth the effort. Only a perfectionist would care about the difference; it has no bearing on functionality whatsoever.

actually we had same issue and had to fix it.
I would simplify check - *Test(?:Case)? in name or parent class.

While you're at it, rename setup to setUp and teardown to tearDown.

Was this page helpful?
0 / 5 - 0 ratings