Static tests
Executing static tests is straightforward. They can be executed in several ways.
Run on all files
To run static tests on all files, navigate to the application root directory and execute the following command:
Copied to your clipboardbin/magento dev:test:run static
Run on a subset of files
To run the static tests on a subset of files, create a new testsuite for phpunit:
From the application root directory navigate to
dev/tests/static/testsuite/Magento/Test
Create a copy of the
Php
folder on the same directory and rename it toLocal
Navigate to
dev/tests/static/testsuite/Magento/Test/Local/_files/whitelist
and opencommon.txt
Replace the contents with the folder of the files that you want to test. For example:
Copied to your clipboard# Format: <componentType=module|library|theme|language|*> <componentName> <globPattern> or simply <globPattern>app/code/Magento/CatalogSearch/Model/SearchCreate a copy of the
dev/tests/static/phpunit.xml.dist
file and call itphpunit.xml
:Add a new testsuite to the
dev/tests/static/phpunit.xml
file inside the<testsuites>
node:Copied to your clipboard<testsuites>...<testsuite name="Local Test Suite"><file>testsuite/Magento/Test/Local/LiveCodeTest.php</file></testsuite></testsuites>Navigate to the application root directory and run:
Copied to your clipboard./vendor/bin/phpunit --testsuite="Local Test Suite" -c dev/tests/static/phpunit.xml
As a result of this process, you can run PHP static tests on a subset of files. It is also possible to run other types of static tests by following the same process with other testsuites.