Skip to content

Commit

Permalink
Add unit tests (#45)
Browse files Browse the repository at this point in the history
* Add unit tests
  • Loading branch information
huanghantao authored Dec 24, 2020
1 parent 4ac2e53 commit 47391d0
Show file tree
Hide file tree
Showing 23 changed files with 436 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ We did not find a slow start problem.

We did not find a slow start problem.

##### MixPHP

We did not find a slow start problem.

##### Swoft

We did not find a slow start problem.
Expand Down
3 changes: 3 additions & 0 deletions tests/inc_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

?>
6 changes: 4 additions & 2 deletions tests/new → tests/new.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function yes(string $content = ''): bool
$replacement['test_name'] = end($this_dir_name); // use dir name to be test name

$filename = "{$path['dirname']}/{$path['filename']}.phpt";
$incFilename = "{$path['dirname']}/{$path['filename']}.inc";

//if dir not exist, create it
if (!is_dir(__DIR__ . "/{$path['dirname']}")) {
Expand Down Expand Up @@ -89,12 +90,13 @@ function yes(string $content = ''): bool
}

$template = file_get_contents(__DIR__ . '/template');
$replacement['dir_deep'] = str_repeat('/..', $deep);
$incTemplate = file_get_contents(__DIR__ . '/inc_template');
$replacement['dir_deep'] = $deep;
foreach ($replacement as $key => $value) {
$template = str_replace("{{{$key}}}", $value, $template);
}

if (file_put_contents($filename, $template)) {
if (file_put_contents($filename, $template) && file_put_contents($incFilename, $incTemplate)) {
echo yasd_color("Generate the test file successfully!\n", YASD_COLOR_GREEN) .
"[" . __DIR__ . "/$filename]";
@shell_exec('/usr/bin/env git add ' . __DIR__ . "/$filename");
Expand Down
22 changes: 17 additions & 5 deletions tests/template
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
--TEST--
{{test_name}}: {{test_intro}}
--SKIPIF--
<?php
if (!extension_loaded('yasd')) {
echo 'skip not install yasd extension';
}
?>
--FILE--
<?php

use Yasd\DbgpClient;

require dirname(__DIR__, {{dir_deep}}) . '/Include/bootstrap.php';

$basename = basename(__FILE__, '.php');
$filename = realpath(dirname(__FILE__) . "/{$basename}.inc");

$commands = [
'run',
'stop',
];

$client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->start();

?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri=%s language="PHP" xdebug:language_version=%s protocol_version="1.0" appid=%s idekey=%s><engine version=%s><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>
2 changes: 1 addition & 1 deletion tests/yasd_debugger/issue/41.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Check stop cmd
issue: 41
--SKIPIF--
--FILE--
<?php
Expand Down
3 changes: 3 additions & 0 deletions tests/yasd_debugger/remote_mode/breakpoint_list.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

?>
37 changes: 37 additions & 0 deletions tests/yasd_debugger/remote_mode/breakpoint_list.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
remote_mode: breakpoint_list
--SKIPIF--
--FILE--
<?php

use Yasd\DbgpClient;

require dirname(__DIR__, 2) . '/Include/bootstrap.php';

$basename = basename(__FILE__, '.php');
$filename = realpath(dirname(__FILE__) . "/{$basename}.inc");

$commands = [
'breakpoint_list',
'run',
'stop',
];

$client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->start();

?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri=%s language="PHP" xdebug:language_version=%s protocol_version="1.0" appid=%s idekey=%s><engine version=%s><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> breakpoint_list -i 1
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"/>

-> run -i 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="stopping" reason="ok"/>

-> stop -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="3" status="stopped" reason="ok"/>
9 changes: 9 additions & 0 deletions tests/yasd_debugger/remote_mode/breakpoint_set.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$a = 1;
$b = 3;
$k = [];

$k = [1, 2, 3];
echo $a;
?>
41 changes: 41 additions & 0 deletions tests/yasd_debugger/remote_mode/breakpoint_set.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
remote_mode: breakpoint_set
--SKIPIF--
--FILE--
<?php

use Yasd\DbgpClient;

require dirname(__DIR__, 2) . '/Include/bootstrap.php';

$basename = basename(__FILE__, '.php');
$filename = realpath(dirname(__FILE__) . "/{$basename}.inc");

$commands = [
"breakpoint_set -t line -f file://{$filename} -n 3",
'run',
'run',
'stop',
];

$client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->start();
?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri=%s language="PHP" xdebug:language_version=%s protocol_version="1.0" appid=%s idekey=%s><engine version=%s><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> breakpoint_set -i 1 -t line -f file://%s -n 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="1" id=%s/>

-> run -i 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file://%s" lineno="3"/></response>

-> run -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="3" status="stopping" reason="ok"/>

-> stop -i 4
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="4" status="stopped" reason="ok"/>
9 changes: 9 additions & 0 deletions tests/yasd_debugger/remote_mode/context_get.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$a = 1;
$b = 3;
$k = [];

$k = [1, 2, 3];
echo $a;
?>
47 changes: 47 additions & 0 deletions tests/yasd_debugger/remote_mode/context_get.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
remote_mode: context_get
--SKIPIF--
--FILE--
<?php

use Yasd\DbgpClient;

require dirname(__DIR__, 2) . '/Include/bootstrap.php';

$basename = basename(__FILE__, '.php');
$filename = realpath(dirname(__FILE__) . "/{$basename}.inc");

$commands = [
"breakpoint_set -t line -f file://{$filename} -n 8",
'run',
'context_get -d 0 -c 0',
'run',
'stop',
];

$client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->start();

?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri=%s language="PHP" xdebug:language_version=%s protocol_version="1.0" appid=%s idekey=%s><engine version=%s><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> breakpoint_set -i 1 -t line -f file://%s -n 8
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="1" id="%s"/>

-> run -i 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file://%s" lineno="8"/></response>

-> context_get -i 3 -d 0 -c 0
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="3" context="0"><property type="int" name="$a" fullname="a"><![CDATA[1]]></property><property type="int" name="$b" fullname="b"><![CDATA[3]]></property><property type="array" name="$k" fullname="k" children="1" numchildren="3"><property type="int" name="0" fullname="k[0]"><![CDATA[1]]></property><property type="int" name="1" fullname="k[1]"><![CDATA[2]]></property><property type="int" name="2" fullname="k[2]"><![CDATA[3]]></property></property></response>

-> run -i 4
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="4" status="stopping" reason="ok"/>

-> stop -i 5
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="5" status="stopped" reason="ok"/>
9 changes: 9 additions & 0 deletions tests/yasd_debugger/remote_mode/context_names.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$a = 1;
$b = 3;
$k = [];

$k = [1, 2, 3];
echo $a;
?>
47 changes: 47 additions & 0 deletions tests/yasd_debugger/remote_mode/context_names.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
remote_mode: context_names
--SKIPIF--
--FILE--
<?php

use Yasd\DbgpClient;

require dirname(__DIR__, 2) . '/Include/bootstrap.php';

$basename = basename(__FILE__, '.php');
$filename = realpath(dirname(__FILE__) . "/{$basename}.inc");

$commands = [
"breakpoint_set -t line -f file://{$filename} -n 8",
'run',
'context_names',
'run',
'stop',
];

$client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->start();

?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri=%s language="PHP" xdebug:language_version=%s protocol_version="1.0" appid=%s idekey=%s><engine version=%s><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> breakpoint_set -i 1 -t line -f file://%s -n 8
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="1" id="%s"/>

-> run -i 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file://%s" lineno="8"/></response>

-> context_names -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_names" transaction_id="3" id="%s"><context name="Locals" id="0"/><context name="Superglobals" id="1"/><context name="User defined constants" id="2"/></response>

-> run -i 4
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="4" status="stopping" reason="ok"/>

-> stop -i 5
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="5" status="stopped" reason="ok"/>
3 changes: 3 additions & 0 deletions tests/yasd_debugger/remote_mode/eval.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

?>
39 changes: 39 additions & 0 deletions tests/yasd_debugger/remote_mode/eval.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
remote_mode: eval
--SKIPIF--
--FILE--
<?php

use Yasd\DbgpClient;

require dirname(__DIR__, 2) . '/Include/bootstrap.php';

$basename = basename(__FILE__, '.php');
$filename = realpath(dirname(__FILE__) . "/{$basename}.inc");

$code = base64_encode("ini_get('yasd.debug_mode');");

$commands = [
"eval -- {$code}",
'run',
'stop',
];

$client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->start();

?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://%s" language="PHP" xdebug:language_version="%s" protocol_version="1.0" appid="%s" idekey="hantaohuang"><engine version="%s"><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> eval -i 1 -- aW5pX2dldCgneWFzZC5kZWJ1Z19tb2RlJyk7
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="1"><property type="string" name="" fullname=""><![CDATA[remote]]></property></response>

-> run -i 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="stopping" reason="ok"/>

-> stop -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="3" status="stopped" reason="ok"/>
3 changes: 3 additions & 0 deletions tests/yasd_debugger/remote_mode/feature_set.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

?>
Loading

0 comments on commit 47391d0

Please sign in to comment.