Debug Semantic MediaWiki in Docker using VSCode and XDebug
Launch.json[edit]
The first thing you're going to need to debug with VSCode is a launch.json file. Save or edit .vscode/launch.json
in your workspace directory.
You can do more with launch.json besides launching XDebug. You can for example launch PHPUnit to run that tool.
Since Semantic MediaWiki has currently 7 test suites defined, we can predefine a launch configuration for our favorite suite:
Launch.json for PHPUnit and Semantic MediaWiki[edit]
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug PHPUnit",
"type": "php",
"request": "launch",
"program": "${workspaceFolder}/vendor/bin/phpunit",
"args": [
"--test-suite",
"semantic-mediawiki-integration"
],
"cwd": "${workspaceFolder}",
"port": 9003
}
]
}
JSON Script Test Case Runner[edit]
1. Identify the Test Case: Determine which test case is failing. For example, if the test case a-0001.json
is failing, you need to locate it in the TestCases
directory.
2. Set Breakpoints: Open the relevant test runner and test case processor files and set breakpoints where the test case is processed. For example, you can set breakpoints in
JSONScriptTestCaseRunner.php
and
JSONScriptServicesTestCaseRunner.php
3. Run the Test in Debug Mode: Use your IDE's debugging tools to run the specific test in debug mode. In VSCode, you can create a launch configuration for PHPUnit as described and illustrated above.
(insert video) 4. Inspect Variables and Flow: When the breakpoint is hit, inspect the variables and the flow of the test execution to understand why it is failing.