Skip to main content
Glama

warden_run_unit_tests

Execute PHPUnit unit tests in Warden-managed Magento 2 environments to validate code functionality and ensure reliability.

Instructions

Run unit tests using PHPUnit in the php-fpm container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathYesPath to the project directory
config_fileNoPHPUnit configuration file (auto-detects phpunit.xml.dist or phpunit.xml)
test_pathNoOptional path to specific test file or directory
extra_argsNoAdditional PHPUnit arguments

Implementation Reference

  • The handler function for 'warden_run_unit_tests' that runs PHPUnit unit tests inside the Warden php-fpm container, auto-detecting config files and handling arguments.
    async runUnitTests(args) { const { project_path, config_file = "", test_path = "", extra_args = [], } = args; // Determine which config file to use let actualConfigFile = config_file; if (!actualConfigFile) { const normalizedProjectPath = project_path.replace(/\/+$/, ""); const absoluteProjectPath = resolve(normalizedProjectPath); // Check for phpunit.xml.dist first, then fallback to phpunit.xml const phpunitDistPath = join(absoluteProjectPath, "phpunit.xml.dist"); const phpunitPath = join(absoluteProjectPath, "phpunit.xml"); if (existsSync(phpunitDistPath)) { actualConfigFile = "phpunit.xml.dist"; } else if (existsSync(phpunitPath)) { actualConfigFile = "phpunit.xml"; } else { throw new Error( "No PHPUnit configuration file found (phpunit.xml.dist or phpunit.xml)", ); } } const wardenCommand = [ "env", "exec", "-T", "php-fpm", "php", "vendor/phpunit/phpunit/phpunit", "-c", actualConfigFile, ]; if (test_path && test_path.trim() !== "") { wardenCommand.push(test_path); } wardenCommand.push(...extra_args); const commandStr = `warden ${wardenCommand.join(" ")}`; const normalizedProjectPath = project_path.replace(/\/+$/, ""); const absoluteProjectPath = resolve(normalizedProjectPath); const debugInfo = ` Debug Information: - Project Path: ${absoluteProjectPath} - Config File Used: ${actualConfigFile} - Test Path: ${test_path || "(all tests)"} - Extra Args: ${extra_args.length > 0 ? extra_args.join(" ") : "(none)"} - Full Command: ${commandStr} `; try { const result = await this.executeCommand( "warden", wardenCommand, absoluteProjectPath, ); const isSuccess = result.code === 0; return { content: [ { type: "text", text: `Running PHPUnit tests with config: ${actualConfigFile} ${isSuccess ? "completed successfully" : "failed"}!\n${debugInfo}\nExit Code: ${result.code}\n\nOutput:\n${result.stdout || "(no output)"}\n\nErrors:\n${result.stderr || "(no errors)"}`, }, ], isError: !isSuccess, }; } catch (error) { return { content: [ { type: "text", text: `Failed to execute PHPUnit tests:\n${debugInfo}\nError: ${error.message}\n\nOutput:\n${error.stdout || "(no output)"}\n\nErrors:\n${error.stderr || "(no errors)"}`, }, ], isError: true, }; } }
  • The input schema definition for the 'warden_run_unit_tests' tool, specifying parameters like project_path, config_file, test_path, and extra_args.
    { name: "warden_run_unit_tests", description: "Run unit tests using PHPUnit in the php-fpm container", inputSchema: { type: "object", properties: { project_path: { type: "string", description: "Path to the project directory", }, config_file: { type: "string", description: "PHPUnit configuration file (auto-detects phpunit.xml.dist or phpunit.xml)", default: "", }, test_path: { type: "string", description: "Optional path to specific test file or directory", default: "", }, extra_args: { type: "array", description: "Additional PHPUnit arguments", items: { type: "string", }, default: [], }, }, required: ["project_path"], }, },
  • server.js:337-338 (registration)
    Registration and dispatch of the 'warden_run_unit_tests' tool in the CallToolRequestSchema handler switch statement.
    case "warden_run_unit_tests": return await this.runUnitTests(request.params.arguments);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/run-as-root/warden-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server