Debug Semantic MediaWiki in Docker using VSCode and XDebug

From Freephile Wiki
Revision as of 18:23, 10 February 2025 by Admin (talk | contribs) (itial draft)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Launch.json[edit]

The first thing you're going to need to debug with VSCode is a launch.json file. You can do more with launch.json besides launching the PHPDebugger. You can for example launch PHPUnit to run that tool.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        },
        {
            "name": "Debug PHPUnit",
            "type": "php",
            "request": "launch",
            "program": "${workspaceFolder}/vendor/bin/phpunit",
            "args": [
                "--filter",
                "SMW\\\\Tests\\\\Integration\\\\JSONScript\\\\JSONScriptTestCaseRunnerTest::testCaseFile"
            ],
            "cwd": "${workspaceFolder}",
            "port": 9003
        }
    ]
}