|
| 1 | +/** |
| 2 | + * Package: https://github.com/ajaxorg/lib-phpdebug |
| 3 | + * |
| 4 | + * License: MIT |
| 5 | + * |
| 6 | + * Copyright(c) 2011 Ajax.org B.V. <info AT ajax DOT org> |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + * |
| 26 | + * Author: Christoph Dorn <christoph@christophdorn.com> (http://www.christophdorn.com/) |
| 27 | + * |
| 28 | + */ |
| 29 | + |
| 30 | +var HELPER = require("./_helper"), |
| 31 | + ASYNC = require("../support/asyncjs/index"), |
| 32 | + ASSERT = require("assert"), |
| 33 | + XDEBUG = require("../lib/xdebug"); |
| 34 | + |
| 35 | +var Test = |
| 36 | +{ |
| 37 | + name: "async", |
| 38 | + timeout: HELPER.getTestTimeout(10000), // The browser test can take some time |
| 39 | + |
| 40 | + "test serverBreakpoints": function(next) |
| 41 | + { |
| 42 | + var client = new XDEBUG.Client(HELPER.getXdebugClientOptions()); |
| 43 | + |
| 44 | + client.on("connect", function(data) |
| 45 | + { |
| 46 | + HELPER.debugScript("Simple", "stepping-server"); |
| 47 | + }); |
| 48 | + |
| 49 | + client.on("session", function(session) |
| 50 | + { |
| 51 | + session.on("end", function() |
| 52 | + { |
| 53 | + client.disconnect(); |
| 54 | + }); |
| 55 | + |
| 56 | + // After setting a breakpoint we continue with the session after |
| 57 | + // the `run` command returns and the breakpoint is hit. In production use, |
| 58 | + // one can listen for the break status only and ignore the return of the `run` command. |
| 59 | + var breakpointNotify = 0; |
| 60 | + session.on("event", function(event) |
| 61 | + { |
| 62 | + if (event.type === "status" && event.status === "break") |
| 63 | + { |
| 64 | + if (event.raw['xdebug:message']["@"].lineno == 18) |
| 65 | + { |
| 66 | + breakpointNotify++; |
| 67 | + if (breakpointNotify === 2) |
| 68 | + { |
| 69 | + next3(); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + }); |
| 74 | + |
| 75 | + // Watch stdout |
| 76 | + // @see http://xdebug.org/docs-dbgp.php#stdout-stderr |
| 77 | + // NOTE: Watching `stderr` does not work for some reason (always returns `args.success = 0`) |
| 78 | + session.sendCommand("stdout", {"c": 1}, null, function(args, data, raw) |
| 79 | + { |
| 80 | + ASSERT.equal(args.success, "1"); |
| 81 | + |
| 82 | + // @see http://www.xdebug.org/docs-dbgp.php#status |
| 83 | + session.sendCommand("status", null, null, function(args, data, raw) |
| 84 | + { |
| 85 | + ASSERT.equal(args.status, "starting"); |
| 86 | + ASSERT.equal(args.reason, "ok"); |
| 87 | + |
| 88 | + next1(); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + // Line: 2 |
| 93 | + function next1() |
| 94 | + { |
| 95 | + // NOTE: If the first step command is `step_over` a `run` is issued by xdebug automatically! |
| 96 | + // We issue a `step_into` instead so we can start stepping through code without breakpoints. |
| 97 | + // @see http://www.xdebug.org/docs-dbgp.php#continuation-commands |
| 98 | + session.sendCommand("step_into", null, null, function(args, data, raw) |
| 99 | + { |
| 100 | + ASSERT.equal(data.lineno, "2"); |
| 101 | + |
| 102 | + next2(); |
| 103 | + }); |
| 104 | + |
| 105 | + } |
| 106 | + // Line: 3 |
| 107 | + function next2() |
| 108 | + { |
| 109 | + // @see http://www.xdebug.org/docs-dbgp.php#id1 |
| 110 | + session.sendCommand("breakpoint_set", { |
| 111 | + "t": "line", |
| 112 | + "s": "enabled", |
| 113 | + "n": 18 |
| 114 | + }, null, function(args, data, raw) |
| 115 | + { |
| 116 | + ASSERT.equal(args.state, "enabled"); |
| 117 | + |
| 118 | + // @see http://www.xdebug.org/docs-dbgp.php#id5 |
| 119 | + session.sendCommand("breakpoint_list", null, null, function(args1, data1, raw1) |
| 120 | + { |
| 121 | + ASSERT.equal(data1["@"].lineno, "18"); |
| 122 | + ASSERT.equal(data1["@"].id, args.id); |
| 123 | + |
| 124 | + // @see http://www.xdebug.org/docs-dbgp.php#continuation-commands |
| 125 | + session.sendCommand("run", null, null, function() |
| 126 | + { |
| 127 | + breakpointNotify++; |
| 128 | + if (breakpointNotify === 2) |
| 129 | + { |
| 130 | + next3(); |
| 131 | + } |
| 132 | + }); |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + } |
| 137 | + |
| 138 | + // Line: 18 |
| 139 | + function next3() |
| 140 | + { |
| 141 | + // @see http://www.xdebug.org/docs-dbgp.php#stack-get |
| 142 | + session.sendCommand("stack_get", {"d": 0}, null, function(args, data, raw) |
| 143 | + { |
| 144 | + ASSERT.equal(data["@"].lineno, "18"); |
| 145 | + |
| 146 | + // @see http://www.xdebug.org/docs-dbgp.php#source |
| 147 | + session.sendCommand("source", {"f": data["@"].filename, "b": data["@"].lineno, "e": data["@"].lineno}, null, function(args, data, raw) |
| 148 | + { |
| 149 | + if (!/var_dump\(array_diff\(\$in1\['items'\], \$in2\['items'\]\)\);/.test(data)) ASSERT.fail(null, null, "source"); |
| 150 | + |
| 151 | + next4(); |
| 152 | + }); |
| 153 | + }); |
| 154 | + } |
| 155 | + |
| 156 | + function next4() |
| 157 | + { |
| 158 | + // @see http://www.xdebug.org/docs-dbgp.php#continuation-commands |
| 159 | + session.sendCommand("run"); |
| 160 | + } |
| 161 | + }); |
| 162 | + |
| 163 | + client.on("disconnect", function(data) |
| 164 | + { |
| 165 | + next(); |
| 166 | + }); |
| 167 | + |
| 168 | + client.connect(); |
| 169 | + }, |
| 170 | + |
| 171 | + "test browserBreakpoints": function(next) |
| 172 | + { |
| 173 | + HELPER.runBrowserTest("breakpoints", function() { |
| 174 | + next(); |
| 175 | + }, 10000); |
| 176 | + } |
| 177 | + |
| 178 | +} |
| 179 | + |
| 180 | +module.exports = require("../support/asyncjs/lib/test").testcase(Test); |
| 181 | + |
| 182 | +if (module === require.main) |
| 183 | + HELPER.ready(function() { |
| 184 | + module.exports.exec(); |
| 185 | + }); |
0 commit comments