Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit d1b02fc

Browse files
committed
breakpoints test
1 parent f01f92b commit d1b02fc

4 files changed

Lines changed: 353 additions & 1 deletion

File tree

lib/xdebug.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ define(function(require, exports, module)
416416
data = packet["context"];
417417
else if (packet["property"])
418418
data = packet["property"];
419+
else if (packet["breakpoint"])
420+
data = packet["breakpoint"];
419421

420422
self.emit("event", {type: "command-response", name: packet["@"].command, id: packet["@"].transaction_id, args: args, data: data, raw: packet});
421423
}

test/all.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ HELPER.ready(function()
4343
ASYNC.concat(
4444
require("./connection"),
4545
require("./session"),
46-
require("./stepping")
46+
require("./stepping"),
47+
require("./breakpoints")
4748
).exec()
4849
});

test/breakpoints.js

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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+
});

test/browser/breakpoints.js

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
define(function(require, exports, module)
31+
{
32+
33+
exports.run = function(ASSERT, XDEBUG, options, callback)
34+
{
35+
var client = new XDEBUG.Client(options);
36+
37+
client.on("connect", function(data)
38+
{
39+
options.helpers.debugScript("Simple", "breakpoints-browser");
40+
});
41+
42+
client.on("session", function(session)
43+
{
44+
session.on("end", function()
45+
{
46+
client.disconnect();
47+
});
48+
49+
// After setting a breakpoint we continue with the session after
50+
// the `run` command returns and the breakpoint is hit. In production use,
51+
// one can listen for the break status only and ignore the return of the `run` command.
52+
var breakpointNotify = 0;
53+
session.on("event", function(event)
54+
{
55+
if (event.type === "status" && event.status === "break")
56+
{
57+
if (event.raw['xdebug:message']["@"].lineno == 18)
58+
{
59+
breakpointNotify++;
60+
if (breakpointNotify === 2)
61+
{
62+
next3();
63+
}
64+
}
65+
}
66+
});
67+
68+
// Watch stdout
69+
// @see http://xdebug.org/docs-dbgp.php#stdout-stderr
70+
// NOTE: Watching `stderr` does not work for some reason (always returns `args.success = 0`)
71+
session.sendCommand("stdout", {"c": 1}, null, function(args, data, raw)
72+
{
73+
ASSERT.equal(args.success, "1");
74+
75+
// @see http://www.xdebug.org/docs-dbgp.php#status
76+
session.sendCommand("status", null, null, function(args, data, raw)
77+
{
78+
ASSERT.equal(args.status, "starting");
79+
ASSERT.equal(args.reason, "ok");
80+
81+
next1();
82+
});
83+
});
84+
85+
// Line: 2
86+
function next1()
87+
{
88+
// NOTE: If the first step command is `step_over` a `run` is issued by xdebug automatically!
89+
// We issue a `step_into` instead so we can start stepping through code without breakpoints.
90+
// @see http://www.xdebug.org/docs-dbgp.php#continuation-commands
91+
session.sendCommand("step_into", null, null, function(args, data, raw)
92+
{
93+
ASSERT.equal(data.lineno, "2");
94+
95+
next2();
96+
});
97+
98+
}
99+
// Line: 3
100+
function next2()
101+
{
102+
// @see http://www.xdebug.org/docs-dbgp.php#id1
103+
session.sendCommand("breakpoint_set", {
104+
"t": "line",
105+
"s": "enabled",
106+
"n": 18
107+
}, null, function(args, data, raw)
108+
{
109+
ASSERT.equal(args.state, "enabled");
110+
111+
// @see http://www.xdebug.org/docs-dbgp.php#id5
112+
session.sendCommand("breakpoint_list", null, null, function(args1, data1, raw1)
113+
{
114+
ASSERT.equal(data1["@"].lineno, "18");
115+
ASSERT.equal(data1["@"].id, args.id);
116+
117+
// @see http://www.xdebug.org/docs-dbgp.php#continuation-commands
118+
session.sendCommand("run", null, null, function()
119+
{
120+
breakpointNotify++;
121+
if (breakpointNotify === 2)
122+
{
123+
next3();
124+
}
125+
});
126+
});
127+
});
128+
129+
}
130+
131+
// Line: 18
132+
function next3()
133+
{
134+
// @see http://www.xdebug.org/docs-dbgp.php#stack-get
135+
session.sendCommand("stack_get", {"d": 0}, null, function(args, data, raw)
136+
{
137+
ASSERT.equal(data["@"].lineno, "18");
138+
139+
// @see http://www.xdebug.org/docs-dbgp.php#source
140+
session.sendCommand("source", {"f": data["@"].filename, "b": data["@"].lineno, "e": data["@"].lineno}, null, function(args, data, raw)
141+
{
142+
if (!/var_dump\(array_diff\(\$in1\['items'\], \$in2\['items'\]\)\);/.test(data)) ASSERT.fail(null, null, "source");
143+
144+
next4();
145+
});
146+
});
147+
}
148+
149+
function next4()
150+
{
151+
// @see http://www.xdebug.org/docs-dbgp.php#continuation-commands
152+
session.sendCommand("run");
153+
}
154+
});
155+
156+
client.on("disconnect", function(data)
157+
{
158+
callback(true);
159+
});
160+
161+
client.connect();
162+
}
163+
164+
});

0 commit comments

Comments
 (0)