Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Fix: Require test code to also be PSR-2-compliant #594

Merged
merged 4 commits into from
May 26, 2016
Merged

Fix: Require test code to also be PSR-2-compliant #594

merged 4 commits into from
May 26, 2016

Conversation

localheinz
Copy link
Contributor

@localheinz localheinz commented May 21, 2016

This PR

  • extracts a configuration file for phpcs
  • requires code in tests/ to also be PSR-2 compliant
  • runs phpcbf and extracts each class definition into its own file
  • moves extracted test assets (as well as existing test assets) into Fixtures namespace

馃拋 There really isn't any plausible reason for applying different standards for production and test code, is there?

@localheinz localheinz changed the title Enhancement: Extract configuration file for phpcs Fix: Require test code to also be PSR-2-compliant May 21, 2016
@ghost ghost added the CLA Signed label May 21, 2016
@SammyK SammyK added this to the 5.2.1 milestone May 21, 2016
@SammyK
Copy link
Contributor

SammyK commented May 21, 2016

This is great - thanks! Since it's a bigger one, I'll let @yguedidi give it a once over as well before merging. :)

@yguedidi
Copy link
Contributor

  • OK to extract phpcs config, but in a phpcs.xml.dist file as it's the default loaded one, and can be overided by a git ignored phpcs.xml one
  • Not sure about using PSR-2 in tests...
    • First they're removed in dist zip
    • Second it's allow us to have multiple classes in one file for small fixture classes instead of many files
    • Finally, look at PhpSpec, a great API design tool, tests are written like public function it_do_this_thing() which is not PSR-2 compliant, then how to use it?

@localheinz
Copy link
Contributor Author

@yguedidi

OK to extract phpcs config, but in a phpcs.xml.dist file as it's the default loaded one, and can be overided by a git ignored phpcs.xml one

Addressed.

Second it's allow us to have multiple classes in one file for small fixture classes instead of many files.

Can't really see how that is an advantage. Can you explain?

Finally, look at PhpSpec, a great API design tool, tests are written like public function it_do_this_thing() which is not PSR-2 compliant, then how to use it?

These are the options:

  1. don't use phpspec (phpunit works just fine) and require test code to be PSR-2-compliant
  2. use phpspec, and don't require test code to be PSR-2-compliant
  3. don't require test code to be PSR-2-compliant

In regard to 2.: We're not using it here, so it's not a problem.
In regard to 3.: Certainly an option, but not a good one - consistency wins.

@@ -21,5 +21,5 @@ install:
- travis_retry composer install --prefer-dist --no-interaction

script:
- vendor/bin/phpcs src --standard=psr2 -spn
- vendor/bin/phpcs --standard=phpcs.xml.dist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can just be vendor/bin/phpcs

@yguedidi
Copy link
Contributor

@localheinz I'm not really against using PSR-2 in our current test files, I just think it's not worth it.
BTW, If you really want to separate fixture classes in their own file, please put them under a Fixtures\ namespace.

@localheinz
Copy link
Contributor Author

@yguedidi

Updated!

* DEALINGS IN THE SOFTWARE.
*
*/
namespace Facebook\Tests\GraphNodes\Fixtures;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixtures\ must be the top level namespace, so this must be Facebook\Tests\Fixtures\GraphNodes. Same for other files. It's helpful to put all fixtures together :)

@localheinz
Copy link
Contributor Author

@yguedidi

Amended!

* DEALINGS IN THE SOFTWARE.
*
*/
namespace Facebook\Tests\PseudoRandomString;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@localheinz You missed this one :)

@localheinz
Copy link
Contributor Author

@yguedidi

And amended! 馃槃

@yguedidi
Copy link
Contributor

Looks good :)

@SammyK SammyK merged commit c57935a into facebookarchive:master May 26, 2016
@SammyK
Copy link
Contributor

SammyK commented May 26, 2016

Boom! Thanks guys! :)

@localheinz localheinz deleted the fix/phpcs branch May 26, 2016 14:13
@localheinz
Copy link
Contributor Author

Thank you, @SammyK and @yguedidi!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants