Skip to content

Commit

Permalink
Merged pull request #263
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Feb 23, 2016
2 parents 74873a5 + 1a1b7b7 commit f2973ac
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/bug01258-php5.phpt
@@ -0,0 +1,70 @@
--TEST--
Test for bug #1258: ensure case statements are covered (< PHP 7.0)
--SKIPIF--
<?php if (!version_compare(phpversion(), "7.0", '<')) echo "skip < PHP 7.0 needed\n"; ?>
--FILE--
<?php
$foo = ['bar', 'baz', 'qux', 'quux'];
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
foreach ($foo as $k => $v) {
switch ($v) {
case 'bar':
echo "bar\n";
break;
case 'baz':
echo "baz\n";
break;
case 'qux':
echo "qux\n";
break;
default:
echo "default\n";
break;
}
}
$cc = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
var_dump($cc);
?>
--EXPECTF--
bar
baz
qux
default
array(1) {
["%sbug01258-php5.php"]=>
array(16) {
[4]=>
int(1)
[6]=>
int(1)
[7]=>
int(1)
[8]=>
int(1)
[9]=>
int(1)
[10]=>
int(1)
[11]=>
int(1)
[12]=>
int(1)
[13]=>
int(1)
[14]=>
int(1)
[15]=>
int(1)
[16]=>
int(1)
[17]=>
int(1)
[18]=>
int(1)
[19]=>
int(1)
[20]=>
int(1)
}
}
64 changes: 64 additions & 0 deletions tests/bug01258-php7.phpt
@@ -0,0 +1,64 @@
--TEST--
Test for bug #1258: ensure case statements are covered (>= PHP 7.0)
--SKIPIF--
<?php if (!version_compare(phpversion(), "7.0", '>=')) echo "skip PHP >= 7.0 needed\n"; ?>
--FILE--
<?php
$foo = ['bar', 'baz', 'qux', 'quux'];
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
foreach ($foo as $k => $v) {
switch ($v) {
case 'bar':
echo "bar\n";
break;
case 'baz':
echo "baz\n";
break;
case 'qux':
echo "qux\n";
break;
default:
echo "default\n";
break;
}
}
$cc = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
var_dump($cc);
?>
--EXPECTF--
bar
baz
qux
default
array(1) {
["%sbug01258-php7.php"]=>
array(13) {
[4]=>
int(1)
[6]=>
int(1)
[7]=>
int(1)
[8]=>
int(1)
[9]=>
int(1)
[10]=>
int(1)
[11]=>
int(1)
[12]=>
int(1)
[13]=>
int(1)
[14]=>
int(1)
[16]=>
int(1)
[17]=>
int(1)
[20]=>
int(1)
}
}
2 changes: 2 additions & 0 deletions xdebug.c
Expand Up @@ -725,6 +725,7 @@ PHP_MINIT_FUNCTION(xdebug)
#if PHP_VERSION_ID < 70000
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_SWITCH_FREE);
#endif
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_CASE);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_QM_ASSIGN);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_DECLARE_LAMBDA_FUNCTION);
XDEBUG_SET_OPCODE_OVERRIDE_COMMON(ZEND_ADD_TRAIT);
Expand Down Expand Up @@ -887,6 +888,7 @@ PHP_MSHUTDOWN_FUNCTION(xdebug)
#if PHP_VERSION_ID < 70000
zend_set_user_opcode_handler(ZEND_SWITCH_FREE, NULL);
#endif
zend_set_user_opcode_handler(ZEND_CASE, NULL);
zend_set_user_opcode_handler(ZEND_QM_ASSIGN, NULL);
zend_set_user_opcode_handler(ZEND_DECLARE_LAMBDA_FUNCTION, NULL);
zend_set_user_opcode_handler(ZEND_ADD_TRAIT, NULL);
Expand Down

0 comments on commit f2973ac

Please sign in to comment.