After building my module I tried running bin/magento dev:tests:run static.
This reported a few problems with my code, but I'm not sure exactly what is checked when running this tests.
The official documentation says

Static code analysis checks that PHP code follows the Magento 2 coding standards and best practices. They usually are executed during continuous integration using the bin/magento tool.

But that does not mean much.
What I found so far is.

  • presence of composer.json
  • presence of README.md
  • presence of licence.txt
  • order of constructor arguments matches parent order of arguments.

What else?


1 Answer 1


bin/magento dev:tests:run static will run:

  • Less Static Code Analysis: Generic.Files.EndFileNewline, Generic.Files.LineEndings, Generic.WhiteSpace.DisallowTabIndent, Squiz.CSS.NamedColours
  • Javascript Static Code Analysis: eslint, jshint
  • PHP Coding Standard Verification:
    1. Returns whitelist based on blacklist and git changed files
    2. Run the PSR2 code sniffs on the code
    3. Run the Magento specific coding standards on the code
    4. Run the annotations sniffs on the code
    5. Run mess detector on code
    6. Run copy paste detector on code
  • Code Integrity Tests:
    1. Build modules dependencies
    2. A test that enforces composer.lock is up to date with composer.json
    3. A test that enforces validity of composer.json files and any other conventions in Magento components
    4. Hhvm Compatibility Test
  • Xss Unsafe Output Test:
    1. /* @noEscape */ before output. Output doesn't require escaping. Test is green.
    2. /* @escapeNotVerified */ before output. Output escaping is not checked and * should be verified. Test is green.
    3. Methods which contains "html" in their names (e.g. echo $object->{suffix}Html{postfix}() ). * Data is ready for the HTML output. Test is green.
    4. AbstractBlock methods escapeHtml, escapeUrl, escapeQuote, escapeXssInUrl are allowed. Test is green.
    5. Type casting and php function count() are allowed * (e.g. echo (int)$var, echo (float)$var, echo (bool)$var, echo count($var)). Test is green.
    6. Output in single quotes (e.g. echo 'some text'). Test is green.
    7. Output in double quotes without variables (e.g. echo "some text"). Test is green.
    8. Other of p.1-7. Output is not escaped. Test is red.

Source: dev/tests/static/phpunit.xml.dist

  • can you add a few words about each one please? Maybe an example that doesn't pass a specific test?
    – Marius
    Feb 28, 2017 at 10:52
  • @Marius I've just added some words for each one (I took them all from core), hope this helps. Feb 28, 2017 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.