PHPUnit/using PHPUnit: Difference between revisions
Created page with "== in a Docker Container == After you clone the code for SemanticMediaWiki and initialize the build submodule, you should be able to use '''make''' for various activities. <code>make bash</code> puts you into a bash shell as root in the wiki container Change to the SMW directory if instead you are at the document root of <tt>/var/www/html</tt><br> <code> cd extensions/SemanticMediaWiki</code><br> <pre> root@2421517631d1:/var/www/html/extensions/SemanticMediaWiki# </pre..." |
No edit summary |
||
| Line 25: | Line 25: | ||
<pre>SMW\Tests\Integration\JSONScript\JSONScriptTestCaseRunnerTest::testCaseFile"a-0001.json"</pre> | <pre>SMW\Tests\Integration\JSONScript\JSONScriptTestCaseRunnerTest::testCaseFile"a-0001.json"</pre> | ||
But | But you can't simply pass these test names to the <code>--filter</code> option of PHPUnit when trying to '''run''' the tests. This<br> | ||
<code>php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --bootstrap tests/bootstrap.php --filter SMW\Tests\Integration\JSONScript\JSONScriptTestCaseRunnerTest::testCaseFile"a-0001.json"</code><br> | <code>php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --bootstrap tests/bootstrap.php --filter SMW\Tests\Integration\JSONScript\JSONScriptTestCaseRunnerTest::testCaseFile"a-0001.json"</code><br> | ||
| Line 32: | Line 32: | ||
No tests executed! | No tests executed! | ||
</pre> | </pre> | ||
because the value is not delimited and wouldn't work "as is". The required format of the <tt>--filter</tt> parameter is defined as basically equivalent to the __METHOD__ magic constant. The expected parameter value is a '''pattern''', so if not enclosed in delimiters, the '/' delimiter will '''automatically''' be added. [https://docs.phpunit.de/en/9.6/textui.html See the v9.6 docs] | |||
From the docs, valid <code>--filter</code> parameter examples are: | |||
<pre> | |||
--filter 'TestNamespace\\TestCaseClass::testMethod' | |||
--filter 'TestNamespace\\TestCaseClass' | |||
--filter TestNamespace | |||
--filter TestCaseClass | |||
--filter testMethod | |||
--filter '/::testMethod .*"my named data"/' | |||
--filter '/::testMethod .*#5$/' | |||
--filter '/::testMethod .*#(5|6|7)$/' | |||
</pre> | |||
So, to properly invoke the above test, you could add single quotes and explicit delimiters with the name of the method plus use a wildcard in the pattern: | |||
<code>php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --bootstrap tests/bootstrap.php --filter '/::testCaseFile .*0001.json/'</code><br> | |||
or broaden the scope with a "pattern" that matches the class name - in which case all such tests would run (about 300). | |||
<code>php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --bootstrap tests/bootstrap.php --filter JSONScriptTestCaseRunnerTest</code> | |||