From 1a2c2fc04de6fe657a2ba649d8803b3299d6bd97 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 26 Jan 2020 02:58:47 +0100 Subject: [PATCH 1/9] Runable unit tests --- Config.php | 3 - Config/Container.php | 11 +- Config/Container/IniCommented.php | 2 +- Config/Container/IniFile.php | 4 +- Config/Container/PHPConstants.php | 5 +- Config/Container/XML.php | 3 - composer.json | 10 +- test/bug11807.phpt | 4 +- test/bug11827.phpt | 12 +- test/bug12291.phpt | 21 +- test/bug12387.phpt | 15 +- test/bug12388.phpt | 24 +- test/bug2780.phpt | 3 +- test/bug6441.phpt | 32 +-- test/phpt_test.php.inc | 404 ------------------------------ test/run_tests.php | 91 +++++++ test/setup.php.inc | 3 +- 17 files changed, 155 insertions(+), 492 deletions(-) delete mode 100644 test/phpt_test.php.inc create mode 100644 test/run_tests.php diff --git a/Config.php b/Config.php index 0e0b751..a0a59f3 100644 --- a/Config.php +++ b/Config.php @@ -17,9 +17,6 @@ // // $Id$ -require_once('PEAR.php'); -require_once('Config/Container.php'); - $GLOBALS['CONFIG_TYPES'] = array( 'apache' => array('Config/Container/Apache.php', 'Config_Container_Apache'), diff --git a/Config/Container.php b/Config/Container.php index ba05e3a..393eef7 100644 --- a/Config/Container.php +++ b/Config/Container.php @@ -17,8 +17,6 @@ // // $Id$ -require_once 'Config.php'; - /** * Interface for Config containers * @@ -62,7 +60,7 @@ class Config_Container { * Array of attributes for this item * @var array */ - var $attributes; + var $attributes = []; /** * Unique id to differenciate nodes @@ -82,7 +80,7 @@ class Config_Container { * @param string $content Content of container object * @param array $attributes Array of attributes for container object */ - function __construct($type = 'section', $name = '', $content = '', $attributes = null) + function __construct($type = 'section', $name = '', $content = '', $attributes = []) { $this->type = $type; $this->name = $name; @@ -694,7 +692,7 @@ function toArray($useAttr = true) $array[$this->name] = array(); switch ($this->type) { case 'directive': - if ($useAttr && count($this->attributes) > 0) { + if ($useAttr && $this->attributes && count($this->attributes) > 0) { $array[$this->name]['#'] = $this->content; $array[$this->name]['@'] = $this->attributes; } else { @@ -702,7 +700,7 @@ function toArray($useAttr = true) } break; case 'section': - if ($useAttr && count($this->attributes) > 0) { + if ($useAttr && $this->attributes&& count($this->attributes) > 0) { $array[$this->name]['@'] = $this->attributes; } if ($count = count($this->children)) { @@ -773,4 +771,3 @@ function writeDatasrc($datasrc, $configType, $options = array()) } } // end func writeDatasrc } // end class Config_Container -?> diff --git a/Config/Container/IniCommented.php b/Config/Container/IniCommented.php index 2360806..6963f68 100644 --- a/Config/Container/IniCommented.php +++ b/Config/Container/IniCommented.php @@ -164,7 +164,7 @@ function _quoteAndCommaParser($text) $pos = 0; // position in $text do { - $char = $text{$pos}; + $char = $text[$pos]; $state = $this->_getQACEvent($stack); if ($tokens[$state]) { diff --git a/Config/Container/IniFile.php b/Config/Container/IniFile.php index 776e7b0..90c7d3a 100644 --- a/Config/Container/IniFile.php +++ b/Config/Container/IniFile.php @@ -66,6 +66,7 @@ function parseDatasrc($datasrc, $obj) null, PEAR_ERROR_RETURN ); } + $currentSection = $obj->container; $confArray = parse_ini_file($datasrc, true); if (!$confArray) { @@ -74,6 +75,7 @@ function parseDatasrc($datasrc, $obj) null, PEAR_ERROR_RETURN ); } + foreach ($confArray as $key => $value) { if (is_array($value)) { $currentSection =& $obj->container->createSection($key); @@ -213,4 +215,4 @@ function contentToString($content) return $content; } -} // end class Config_Container_IniFile \ No newline at end of file +} // end class Config_Container_IniFile diff --git a/Config/Container/PHPConstants.php b/Config/Container/PHPConstants.php index fc0b130..b9e0c9d 100644 --- a/Config/Container/PHPConstants.php +++ b/Config/Container/PHPConstants.php @@ -11,7 +11,6 @@ * @version SVN: $Id$ * @link http://pear.php.net/package/Config */ -require_once 'Config/Container.php'; /** * Config parser for PHP constant files @@ -22,7 +21,7 @@ * @license http://www.php.net/license PHP License * @link http://pear.php.net/package/Config */ -class Config_Container_PHPConstants extends Config_Container +class Config_Container_PHPConstants { /** * Valid config options: @@ -125,7 +124,7 @@ function &parseDatasrc($datasrc, &$obj) * * @access public */ - function toString(&$obj) + function toString(&$obj, $options = array()) { $string = ''; diff --git a/Config/Container/XML.php b/Config/Container/XML.php index 1183fcb..77b22cc 100644 --- a/Config/Container/XML.php +++ b/Config/Container/XML.php @@ -17,9 +17,6 @@ // // $Id$ -require_once('XML/Parser.php'); -require_once('XML/Util.php'); - /** * Config parser for XML Files * diff --git a/composer.json b/composer.json index 6796f9f..6a0b2d2 100644 --- a/composer.json +++ b/composer.json @@ -38,12 +38,16 @@ }, "type": "library", "require": { - "pear/pear_exception": "*" + "pear/pear": "^1.10", + "pear/xml_parser": "^1.3", + "sebastian/diff": "^3.0" }, "require-dev": { - "phpunit/phpunit": "*" + "phpunit/phpunit": "*", + "pear/text_diff": "^1.2", + "phpspec/php-diff": "^1.1" }, "suggest": { "pear/xml_parser": "Install optionally via your project's composer.json" } -} \ No newline at end of file +} diff --git a/test/bug11807.phpt b/test/bug11807.phpt index 44db8d8..b6f3b0d 100644 --- a/test/bug11807.phpt +++ b/test/bug11807.phpt @@ -27,7 +27,7 @@ print file_get_contents($path); ?> --CLEAN-- --EXPECT-- \ No newline at end of file +?> diff --git a/test/bug11827.phpt b/test/bug11827.phpt index a14cced..f58151d 100644 --- a/test/bug11827.phpt +++ b/test/bug11827.phpt @@ -5,12 +5,10 @@ regression test for bug #11827 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; $datasrc = dirname(__FILE__) . '/bug11827.ini'; $root = $config->parseConfig($datasrc, 'inifile'); -var_dump($root->children[0]->children[0]->content); +var_export($root->children[0]->children[0]->content); ?> --EXPECT-- -array(2) { - [0]=> - string(6) "value1" - [1]=> - string(6) "value2" -} +array ( + 0 => 'value1', + 1 => 'value2', +) diff --git a/test/bug12291.phpt b/test/bug12291.phpt index 3edf905..1eb036d 100644 --- a/test/bug12291.phpt +++ b/test/bug12291.phpt @@ -10,17 +10,14 @@ regression test for bug #12291: do not require space before newline require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; $datasrc = dirname(__FILE__) . '/bug12291.ini'; $root = $config->parseConfig($datasrc, 'genericconf'); -var_dump($root->toArray()); +var_export($root->toArray()); ?> --EXPECT-- -array(1) { - ["root"]=> - array(3) { - ["keyword"]=> - string(11) "foo,bar,baz" - ["keyword_with_space"]=> - string(13) "foo, bar, baz" - ["keyword_with_two_spaces"]=> - string(14) "foo, bar, baz" - } -} +array ( + 'root' => + array ( + 'keyword' => 'foo,bar,baz', + 'keyword_with_space' => 'foo, bar, baz', + 'keyword_with_two_spaces' => 'foo, bar, baz', + ), +) diff --git a/test/bug12387.phpt b/test/bug12387.phpt index 37f151e..b0fd895 100644 --- a/test/bug12387.phpt +++ b/test/bug12387.phpt @@ -5,13 +5,12 @@ Test for request #12387: Allow hyphens in the key require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; $datasrc = dirname(__FILE__) . '/bug12387.ini'; $root = $config->parseConfig($datasrc, 'genericconf'); -var_dump($root->toArray()); +var_export($root->toArray()); ?> --EXPECT-- -array(1) { - ["root"]=> - array(1) { - ["hy-phen"]=> - string(5) "value" - } -} +array ( + 'root' => + array ( + 'hy-phen' => 'value', + ), +) diff --git a/test/bug12388.phpt b/test/bug12388.phpt index 7b91fb9..880fa89 100644 --- a/test/bug12388.phpt +++ b/test/bug12388.phpt @@ -5,19 +5,15 @@ Test for request #12388: Allow spaces after the key require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; $datasrc = dirname(__FILE__) . '/bug12388.ini'; $root = $config->parseConfig($datasrc, 'genericconf'); -var_dump($root->toArray()); +var_export($root->toArray()); ?> --EXPECT-- -array(1) { - ["root"]=> - array(4) { - ["nospace"]=> - string(5) "value" - ["space_before"]=> - string(5) "value" - ["space_after"]=> - string(5) "value" - ["two_spaces_after"]=> - string(5) "value" - } -} +array ( + 'root' => + array ( + 'nospace' => 'value', + 'space_before' => 'value', + 'space_after' => 'value', + 'two_spaces_after' => 'value', + ), +) diff --git a/test/bug2780.phpt b/test/bug2780.phpt index 3acfbc2..ac23a4d 100644 --- a/test/bug2780.phpt +++ b/test/bug2780.phpt @@ -2,8 +2,7 @@ bug 2780 regression --FILE-- parseConfig($datasrc, 'inicommented'); $temp = $conf_obj->toArray(); $conf = $temp['root']; -var_dump($conf); +var_export($conf); ?> --EXPECT-- -array(8) { - ["val1"]=> - string(1) "1" - ["val2"]=> - string(0) "" - ["val3"]=> - string(1) "1" - ["val4"]=> - string(0) "" - ["val5"]=> - string(1) "1" - ["val6"]=> - string(0) "" - ["val7"]=> - string(4) "true" - ["val8"]=> - string(5) "false" -} +array ( + 'val1' => '1', + 'val2' => '', + 'val3' => '1', + 'val4' => '', + 'val5' => '1', + 'val6' => '', + 'val7' => 'true', + 'val8' => 'false', +) diff --git a/test/phpt_test.php.inc b/test/phpt_test.php.inc deleted file mode 100644 index d7ecafb..0000000 --- a/test/phpt_test.php.inc +++ /dev/null @@ -1,404 +0,0 @@ -_diffonly = $diffonly; - $this->_errors = array(); - PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$this, 'pearerrorCallback')); - PEAR_ErrorStack::setDefaultCallback(array(&$this, 'pearerrorstackCallback')); - } - - function pearerrorCallback($err) - { - PEAR_ErrorStack::staticPush('PEAR_Error', -1, 'error', array('obj' => $err), - $err->getMessage()); - } - - function pearerrorstackCallback($err) - { - $this->_errors[] = $err; - } - - function assertPEARError($err, $message) - { - if (is_a($err, 'PEAR_Error')) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Not a PEAR_Error\n"; - return false; - } - - function assertNoErrors($message, $trace = null) - { - if (count($this->_errors) == 0) { - return true; - } - if ($trace === null) { - $trace = debug_backtrace(); - } - $this->_failTest($trace, $message); - foreach ($this->_errors as $err) { - if ($err['package'] == 'PEAR_Error') { - echo "Unexpected PEAR_Error:\n"; - echo 'message "' . $err['message'] . "\"\n"; - } else { - echo "Unexpected PEAR_ErrorStack error:\n"; - echo 'package "' . $err['package'] . "\"\n"; - echo 'message "' . $err['message'] . "\"\n"; - } - } - $this->_errors = array(); - return false; - } - - function assertErrors($errors, $message, $trace = null) - { - if (!count($this->_errors)) { - if ($trace === null) { - $trace = debug_backtrace(); - } - $this->_failTest($trace, $message); - echo "No errors caught, but errors were expected\n"; - return false; - } - if (!isset($errors[0])) { - $errors = array($errors); - } - $failed = false; - foreach ($errors as $err) { - $found = false; - foreach ($this->_errors as $i => $caughterror) { - if ($caughterror['package'] == $err['package']) { - if ($caughterror['message'] == $err['message']) { - $found = true; - break; - } - } - } - if ($found) { - unset($this->_errors[$i]); - continue; - } - if (!$failed) { - if ($trace === null) { - $trace = debug_backtrace(); - } - $failed = true; - $this->_failTest($trace, $message); - } - echo "Unthrown error:\n"; - if ($err['package'] == 'PEAR_Error') { - echo "PEAR_Error:\n"; - } else { - echo "error package: \"$err[package]\"\n"; - } - echo "message: \"$err[message]\"\n"; - } - if (count($this->_errors)) { - if (!$failed) { - if ($trace === null) { - $trace = debug_backtrace(); - } - $failed = true; - $this->_failTest($trace, $message); - } - foreach ($this->_errors as $err) { - echo "Unexpected error:\n"; - if ($err['package'] == 'PEAR_Error') { - echo "PEAR_Error:\n"; - } else { - echo "error package: \"$err[package]\"\n"; - } - echo "message: \"$err[message]\"\n"; - } - } - $this->_errors = array(); - return !$failed; - } - - function assertTrue($test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if ($test === true) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpected non-true value: \n"; - var_export($test); - echo "\n'$message'\n"; - return false; - } - - function assertIsa($control, $test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if (is_a($test, $control)) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpected non-$control object: \n"; - var_export($test); - echo "\n'$message'\n"; - return false; - } - - function assertNull($test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if ($test === null) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpected non-null value: \n"; - var_export($test); - echo "\n'$message'\n"; - return false; - } - - function assertNotNull($test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if ($test !== null) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpected null: \n"; - var_export($test); - echo "\n'$message'\n"; - return false; - } - - function assertSame($test, $test1, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if ($test === $test1) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpectedly two vars are not the same thing: \n"; - echo "\n'$message'\n"; - return false; - } - - function assertNotSame($test, $test1, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if ($test !== $test1) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpectedly two vars are the same thing: \n"; - echo "\n'$message'\n"; - return false; - } - - function assertFalse($test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if ($test === false) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpected non-false value: \n"; - var_export($test); - echo "\n'$message'\n"; - return false; - } - - function assertNotTrue($test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if (!$test) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpected loose true value: \n"; - var_export($test); - echo "\n'$message'\n"; - return false; - } - - function assertNotFalse($test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if ($test) { - return true; - } - $this->_failTest(debug_backtrace(), $message); - echo "Unexpected loose false value: \n"; - var_export($test); - echo "\n'$message'\n"; - return false; - } - - function assertEquals($control, $test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if (str_replace(array("\r", "\n"), array('', ''), - var_export($control, true)) != str_replace(array("\r", "\n"), array('', ''), - var_export($test, true))) { - $this->_failTest(debug_backtrace(), $message); - if (class_exists('Text_Diff')) { - echo "Diff of expecting/received:\n"; - $diff = &new Text_Diff( - explode("\n", var_export($control, true)), - explode("\n", var_export($test, true))); - - // Output the diff in unified format. - $renderer = &new Text_Diff_Renderer_unified(); - echo $renderer->render($diff); - if ($this->_diffonly) { - return false; - } - } - echo "Expecting:\n"; - var_export($control); - echo "\nReceived:\n"; - var_export($test); - return false; - } - return true; - } - - function assertFileExists($fname, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if (!@file_exists($fname)) { - $this->_failTest(debug_backtrace(), $message); - echo "File '$fname' does not exist, and should\n"; - return false; - } - return true; - } - - function assertFileNotExists($fname, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if (@file_exists($fname)) { - $this->_failTest(debug_backtrace(), $message); - echo "File '$fname' exists, and should not\n"; - return false; - } - return true; - } - - function assertRegEquals($dump, &$reg, $message) - { - $actualdump = var_export(trim($this->dumpReg($reg)), true); - $testdump = var_export(trim($dump), true); - return $this->assertEquals($testdump, $actualdump, $message); - } - - function assertPackageInfoEquals($control, $test, $message) - { - $this->assertNoErrors($message, debug_backtrace()); - if (isset($control[0])) { - if (!isset($test[0]) || (count($control) != count($test))) { - echo "Invalid packageInfo\n"; - $ret = $this->assertEquals($control, $test, $message); - } - $ret = true; - foreach ($control as $i => $packageinfo) { - $ret = $ret && - $this->assertPackageInfoEquals($packageinfo, $test[$i], $message . $i); - } - return $ret; - } - if (isset($control['_lastmodified'])) { - if (!isset($test['_lastmodified'])) { - echo "_lastmodified is not set in packageInfo() output\n"; - $this->_failTest(debug_backtrace(), $message); - return false; - } - } - $savecontrol = $control; - $savetest = $test; - unset($control['_lastmodified']); - unset($test['_lastmodified']); - if (var_export($control, true) != var_export($test, true)) { - $this->_failTest(debug_backtrace(), $message); - if (class_exists('Text_Diff')) { - echo "Diff of expecting/received:\n"; - $diff = &new Text_Diff( - explode("\n", var_export($control, true)), - explode("\n", var_export($test, true))); - - // Output the diff in unified format. - $renderer = &new Text_Diff_Renderer_unified(); - echo $renderer->render($diff); - if ($this->_diffonly) { - return false; - } - } - echo "Expecting:\n"; - var_export($savecontrol); - echo "\nReceived:\n"; - var_export($savetest); - return false; - } - return true; - } - - function dumpReg(&$reg) - { - ob_start(); - print "dumping registry...\n"; - $infos = $reg->packageInfo(null, null, null); - foreach ($infos as $channel => $info) { - echo "channel $channel:\n"; - foreach ($info as $pkg) { - print $pkg["name"] . ":"; - unset($pkg["name"]); - foreach ($pkg as $k => $v) { - if ($k == '_lastmodified') { - print " _lastmodified is set"; - continue; - } - if (is_array($v) && $k == 'filelist') { - print " $k=array("; - $i = 0; - foreach ($v as $k2 => $v2) { - if ($i++ > 0) print ","; - print "{$k2}["; - $j = 0; - foreach ($v2 as $k3 => $v3) { - if ($j++ > 0) print ","; - print "$k3=$v3"; - } - print "]"; - } - print ")"; - } else { - print " $k=\"$v\""; - } - } - print "\n"; - } - } - print "dump done\n"; - $ret = ob_get_contents(); - ob_end_clean(); - return $ret; - } - - function _failTest($trace, $message) - { - echo 'Test Failure: "' . $message . "\"\n in " . $trace[0]['file'] . ' line ' . - $trace[0]['line'] . "\n"; - } - - function showAll() - { - $this->_diffonly = false; - } -} -?> \ No newline at end of file diff --git a/test/run_tests.php b/test/run_tests.php new file mode 100644 index 0000000..7d64659 --- /dev/null +++ b/test/run_tests.php @@ -0,0 +1,91 @@ + $shell_argument) { + if ($shell_argument == '--filter') { + if (! empty($argv[$i+1])) { + $arguments['filter'] = $argv[$i+1]; + } + } +} +// var_dump($arguments); +// exit; + +$differ = new Differ; + +error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); + +$tests_failed = []; + +foreach ($files as $file) { + if (preg_match("/\.phpt$/", $file)) { + + if (! empty($arguments['filter']) && $file != $arguments['filter']) { + continue; + } + + $test_parts = file_get_contents(__DIR__ . '/' . $file); + $test_parts = preg_split("/(^|\n)--/", $test_parts); + $parts = []; + foreach (array_filter($test_parts) as $test_part) { + if (! preg_match("#^(\w+)--(\n([\s\S]+))?$#m", $test_part, $matches)) { + throw new \Exception('Invalid test part: '.$test_part); + } + $parts[$matches[1]] = isset($matches[3]) ? $matches[3] : ''; + } + + echo "$file: {$parts['TEST']}\n"; + $current_test_filename = __DIR__ . '/current_test.php'; + file_exists($current_test_filename) && unlink($current_test_filename); + file_put_contents($current_test_filename, $parts['FILE']); + + $output = shell_exec("php$php_version $current_test_filename"); + + if (trim($output) != trim($parts['EXPECT'])) { + echo "Test failed\n"; + + // Options for generating the diff + $options = array( + //'ignoreWhitespace' => true, + //'ignoreCase' => true, + ); + + // Initialize the diff class + // print $differ->diff('foo', 'bar'); + $diff = new Diff( + explode("\n", $parts['EXPECT']), + explode("\n", $output), + $options + ); + + $renderer = new Diff_Renderer_Text_Unified; + echo $diff->render($renderer); + echo "\n$output\n"; + // echo "Expected:\n{$parts['EXPECT']}\n"; + $tests_failed[] = "$file: {$parts['TEST']}"; + // exit; + } + + if (isset($parts['CLEAN'])) { + $current_clean_filename = __DIR__ . '/current_clean.php'; + file_put_contents($current_clean_filename, $parts['CLEAN']); + require_once $current_clean_filename; + unlink($current_clean_filename); + } + } +} +/**/ diff --git a/test/setup.php.inc b/test/setup.php.inc index 1c82501..120d93f 100644 --- a/test/setup.php.inc +++ b/test/setup.php.inc @@ -1,6 +1,5 @@ Date: Sun, 26 Jan 2020 03:33:35 +0100 Subject: [PATCH 2/9] Integrate PHPUnit --- .gitignore | 3 + .travis.yml | 6 +- phpunit.xml | 31 +++++++ test/run_tests.php | 91 ------------------- tests/AbstractTest.php | 18 ++++ tests/bootstrap_phpunit.php | 13 +++ tests/legacy/LegacyTest.php | 60 ++++++++++++ {test => tests/legacy}/bug10010.phpt | 0 {test => tests/legacy}/bug10185.phpt | 0 {test => tests/legacy}/bug11184.phpt | 0 .../legacy}/bug11435-inicommented.phpt | 0 {test => tests/legacy}/bug11435-inifile.phpt | 0 {test => tests/legacy}/bug11435.ini | 0 {test => tests/legacy}/bug11807.phpt | 0 tests/legacy/bug11807.txt | 7 ++ {test => tests/legacy}/bug11827.ini | 0 {test => tests/legacy}/bug11827.phpt | 0 {test => tests/legacy}/bug12291.ini | 0 {test => tests/legacy}/bug12291.phpt | 0 {test => tests/legacy}/bug12387.ini | 0 {test => tests/legacy}/bug12387.phpt | 0 {test => tests/legacy}/bug12388.ini | 0 {test => tests/legacy}/bug12388.phpt | 0 {test => tests/legacy}/bug13791.phpt | 0 {test => tests/legacy}/bug16590-2.phpt | 0 {test => tests/legacy}/bug16590.phpt | 0 {test => tests/legacy}/bug16656.ini | 0 {test => tests/legacy}/bug16656.phpt | 0 {test => tests/legacy}/bug16724-config.php | 0 {test => tests/legacy}/bug16724.phpt | 0 {test => tests/legacy}/bug18124.phpt | 0 {test => tests/legacy}/bug2742.ini | 0 {test => tests/legacy}/bug2742.phpt | 0 {test => tests/legacy}/bug2780.phpt | 0 {test => tests/legacy}/bug3051.phpt | 0 {test => tests/legacy}/bug3051.xml | 0 {test => tests/legacy}/bug3137.phpt | 0 {test => tests/legacy}/bug3298.phpt | 0 {test => tests/legacy}/bug3298.xml | 0 {test => tests/legacy}/bug3398.ini | 0 {test => tests/legacy}/bug3398.phpt | 0 {test => tests/legacy}/bug3590-input.php | 0 {test => tests/legacy}/bug3590.phpt | 0 {test => tests/legacy}/bug4623.conf | 0 {test => tests/legacy}/bug4623.phpt | 0 {test => tests/legacy}/bug6441.ini | 0 {test => tests/legacy}/bug6441.phpt | 0 .../legacy}/bug7544-inicommented.phpt | 0 {test => tests/legacy}/bug7544-inifile.phpt | 0 {test => tests/legacy}/bug7544.ini | 0 {test => tests/legacy}/bug7652.phpt | 0 {test => tests/legacy}/bug7652.xml | 0 .../legacy}/bug8357-inicommented.phpt | 0 {test => tests/legacy}/bug8357-inifile.phpt | 0 {test => tests/legacy}/bug8357.ini | 0 tests/legacy/current_test.php | 24 +++++ {test => tests/legacy}/inifile.ini | 0 {test => tests/legacy}/inifile.phpt | 0 {test => tests/legacy}/phpconstants.phpt | 0 {test => tests/legacy}/setup.php.inc | 2 +- 60 files changed, 160 insertions(+), 95 deletions(-) create mode 100644 phpunit.xml delete mode 100644 test/run_tests.php create mode 100644 tests/AbstractTest.php create mode 100644 tests/bootstrap_phpunit.php create mode 100644 tests/legacy/LegacyTest.php rename {test => tests/legacy}/bug10010.phpt (100%) rename {test => tests/legacy}/bug10185.phpt (100%) rename {test => tests/legacy}/bug11184.phpt (100%) rename {test => tests/legacy}/bug11435-inicommented.phpt (100%) rename {test => tests/legacy}/bug11435-inifile.phpt (100%) rename {test => tests/legacy}/bug11435.ini (100%) rename {test => tests/legacy}/bug11807.phpt (100%) create mode 100644 tests/legacy/bug11807.txt rename {test => tests/legacy}/bug11827.ini (100%) rename {test => tests/legacy}/bug11827.phpt (100%) rename {test => tests/legacy}/bug12291.ini (100%) rename {test => tests/legacy}/bug12291.phpt (100%) rename {test => tests/legacy}/bug12387.ini (100%) rename {test => tests/legacy}/bug12387.phpt (100%) rename {test => tests/legacy}/bug12388.ini (100%) rename {test => tests/legacy}/bug12388.phpt (100%) rename {test => tests/legacy}/bug13791.phpt (100%) rename {test => tests/legacy}/bug16590-2.phpt (100%) rename {test => tests/legacy}/bug16590.phpt (100%) rename {test => tests/legacy}/bug16656.ini (100%) rename {test => tests/legacy}/bug16656.phpt (100%) rename {test => tests/legacy}/bug16724-config.php (100%) rename {test => tests/legacy}/bug16724.phpt (100%) rename {test => tests/legacy}/bug18124.phpt (100%) rename {test => tests/legacy}/bug2742.ini (100%) rename {test => tests/legacy}/bug2742.phpt (100%) rename {test => tests/legacy}/bug2780.phpt (100%) rename {test => tests/legacy}/bug3051.phpt (100%) rename {test => tests/legacy}/bug3051.xml (100%) rename {test => tests/legacy}/bug3137.phpt (100%) rename {test => tests/legacy}/bug3298.phpt (100%) rename {test => tests/legacy}/bug3298.xml (100%) rename {test => tests/legacy}/bug3398.ini (100%) rename {test => tests/legacy}/bug3398.phpt (100%) rename {test => tests/legacy}/bug3590-input.php (100%) rename {test => tests/legacy}/bug3590.phpt (100%) rename {test => tests/legacy}/bug4623.conf (100%) rename {test => tests/legacy}/bug4623.phpt (100%) rename {test => tests/legacy}/bug6441.ini (100%) rename {test => tests/legacy}/bug6441.phpt (100%) rename {test => tests/legacy}/bug7544-inicommented.phpt (100%) rename {test => tests/legacy}/bug7544-inifile.phpt (100%) rename {test => tests/legacy}/bug7544.ini (100%) rename {test => tests/legacy}/bug7652.phpt (100%) rename {test => tests/legacy}/bug7652.xml (100%) rename {test => tests/legacy}/bug8357-inicommented.phpt (100%) rename {test => tests/legacy}/bug8357-inifile.phpt (100%) rename {test => tests/legacy}/bug8357.ini (100%) create mode 100644 tests/legacy/current_test.php rename {test => tests/legacy}/inifile.ini (100%) rename {test => tests/legacy}/inifile.phpt (100%) rename {test => tests/legacy}/phpconstants.phpt (100%) rename {test => tests/legacy}/setup.php.inc (67%) diff --git a/.gitignore b/.gitignore index 869f498..24524b5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ composer.lock composer.phar vendor +tests/coverage +.phpunit.result.cache +clover.xml diff --git a/.travis.yml b/.travis.yml index 1a7578e..fec7f0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php install: - - pear install -a package.xml + - composer install php: - - 5.5 -script: phpunit test/ \ No newline at end of file + - 7.4 +script: phpunit diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..c01bfd0 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,31 @@ + + + + + + + ./tests/integration + ./tests/legacy + + + + + + + ./Config + + + + + + + + + diff --git a/test/run_tests.php b/test/run_tests.php deleted file mode 100644 index 7d64659..0000000 --- a/test/run_tests.php +++ /dev/null @@ -1,91 +0,0 @@ - $shell_argument) { - if ($shell_argument == '--filter') { - if (! empty($argv[$i+1])) { - $arguments['filter'] = $argv[$i+1]; - } - } -} -// var_dump($arguments); -// exit; - -$differ = new Differ; - -error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); - -$tests_failed = []; - -foreach ($files as $file) { - if (preg_match("/\.phpt$/", $file)) { - - if (! empty($arguments['filter']) && $file != $arguments['filter']) { - continue; - } - - $test_parts = file_get_contents(__DIR__ . '/' . $file); - $test_parts = preg_split("/(^|\n)--/", $test_parts); - $parts = []; - foreach (array_filter($test_parts) as $test_part) { - if (! preg_match("#^(\w+)--(\n([\s\S]+))?$#m", $test_part, $matches)) { - throw new \Exception('Invalid test part: '.$test_part); - } - $parts[$matches[1]] = isset($matches[3]) ? $matches[3] : ''; - } - - echo "$file: {$parts['TEST']}\n"; - $current_test_filename = __DIR__ . '/current_test.php'; - file_exists($current_test_filename) && unlink($current_test_filename); - file_put_contents($current_test_filename, $parts['FILE']); - - $output = shell_exec("php$php_version $current_test_filename"); - - if (trim($output) != trim($parts['EXPECT'])) { - echo "Test failed\n"; - - // Options for generating the diff - $options = array( - //'ignoreWhitespace' => true, - //'ignoreCase' => true, - ); - - // Initialize the diff class - // print $differ->diff('foo', 'bar'); - $diff = new Diff( - explode("\n", $parts['EXPECT']), - explode("\n", $output), - $options - ); - - $renderer = new Diff_Renderer_Text_Unified; - echo $diff->render($renderer); - echo "\n$output\n"; - // echo "Expected:\n{$parts['EXPECT']}\n"; - $tests_failed[] = "$file: {$parts['TEST']}"; - // exit; - } - - if (isset($parts['CLEAN'])) { - $current_clean_filename = __DIR__ . '/current_clean.php'; - file_put_contents($current_clean_filename, $parts['CLEAN']); - require_once $current_clean_filename; - unlink($current_clean_filename); - } - } -} -/**/ diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php new file mode 100644 index 0000000..0324972 --- /dev/null +++ b/tests/AbstractTest.php @@ -0,0 +1,18 @@ +getName() ."\n" ); + } + + /**/ +} diff --git a/tests/bootstrap_phpunit.php b/tests/bootstrap_phpunit.php new file mode 100644 index 0000000..6447b21 --- /dev/null +++ b/tests/bootstrap_phpunit.php @@ -0,0 +1,13 @@ + $legacy_test) { + $out[] = [$filename, $legacy_test]; + } + + return $out; + } + + /** + * @dataProvider dataProvider_legacy_unit_tests + */ + public function test_legacy_unit_tests($filename, $parts) + { + $php_version = explode('.',phpversion()); + $php_version = $php_version[0] . '.' . $php_version[1]; + + $current_test_filename = __DIR__ . '/current_test.php'; + file_exists($current_test_filename) && unlink($current_test_filename); + file_put_contents($current_test_filename, $parts['FILE']); + $output = shell_exec("php$php_version $current_test_filename"); + + $this->assertEquals( + trim($parts['EXPECT']), + trim($output) + ); + + if (isset($parts['CLEAN'])) { + $current_clean_filename = __DIR__ . '/current_clean.php'; + file_put_contents($current_clean_filename, $parts['CLEAN']); + require_once $current_clean_filename; + unlink($current_clean_filename); + } + } + + /**/ +} diff --git a/test/bug10010.phpt b/tests/legacy/bug10010.phpt similarity index 100% rename from test/bug10010.phpt rename to tests/legacy/bug10010.phpt diff --git a/test/bug10185.phpt b/tests/legacy/bug10185.phpt similarity index 100% rename from test/bug10185.phpt rename to tests/legacy/bug10185.phpt diff --git a/test/bug11184.phpt b/tests/legacy/bug11184.phpt similarity index 100% rename from test/bug11184.phpt rename to tests/legacy/bug11184.phpt diff --git a/test/bug11435-inicommented.phpt b/tests/legacy/bug11435-inicommented.phpt similarity index 100% rename from test/bug11435-inicommented.phpt rename to tests/legacy/bug11435-inicommented.phpt diff --git a/test/bug11435-inifile.phpt b/tests/legacy/bug11435-inifile.phpt similarity index 100% rename from test/bug11435-inifile.phpt rename to tests/legacy/bug11435-inifile.phpt diff --git a/test/bug11435.ini b/tests/legacy/bug11435.ini similarity index 100% rename from test/bug11435.ini rename to tests/legacy/bug11435.ini diff --git a/test/bug11807.phpt b/tests/legacy/bug11807.phpt similarity index 100% rename from test/bug11807.phpt rename to tests/legacy/bug11807.phpt diff --git a/tests/legacy/bug11807.txt b/tests/legacy/bug11807.txt new file mode 100644 index 0000000..c0bf2db --- /dev/null +++ b/tests/legacy/bug11807.txt @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/test/bug11827.ini b/tests/legacy/bug11827.ini similarity index 100% rename from test/bug11827.ini rename to tests/legacy/bug11827.ini diff --git a/test/bug11827.phpt b/tests/legacy/bug11827.phpt similarity index 100% rename from test/bug11827.phpt rename to tests/legacy/bug11827.phpt diff --git a/test/bug12291.ini b/tests/legacy/bug12291.ini similarity index 100% rename from test/bug12291.ini rename to tests/legacy/bug12291.ini diff --git a/test/bug12291.phpt b/tests/legacy/bug12291.phpt similarity index 100% rename from test/bug12291.phpt rename to tests/legacy/bug12291.phpt diff --git a/test/bug12387.ini b/tests/legacy/bug12387.ini similarity index 100% rename from test/bug12387.ini rename to tests/legacy/bug12387.ini diff --git a/test/bug12387.phpt b/tests/legacy/bug12387.phpt similarity index 100% rename from test/bug12387.phpt rename to tests/legacy/bug12387.phpt diff --git a/test/bug12388.ini b/tests/legacy/bug12388.ini similarity index 100% rename from test/bug12388.ini rename to tests/legacy/bug12388.ini diff --git a/test/bug12388.phpt b/tests/legacy/bug12388.phpt similarity index 100% rename from test/bug12388.phpt rename to tests/legacy/bug12388.phpt diff --git a/test/bug13791.phpt b/tests/legacy/bug13791.phpt similarity index 100% rename from test/bug13791.phpt rename to tests/legacy/bug13791.phpt diff --git a/test/bug16590-2.phpt b/tests/legacy/bug16590-2.phpt similarity index 100% rename from test/bug16590-2.phpt rename to tests/legacy/bug16590-2.phpt diff --git a/test/bug16590.phpt b/tests/legacy/bug16590.phpt similarity index 100% rename from test/bug16590.phpt rename to tests/legacy/bug16590.phpt diff --git a/test/bug16656.ini b/tests/legacy/bug16656.ini similarity index 100% rename from test/bug16656.ini rename to tests/legacy/bug16656.ini diff --git a/test/bug16656.phpt b/tests/legacy/bug16656.phpt similarity index 100% rename from test/bug16656.phpt rename to tests/legacy/bug16656.phpt diff --git a/test/bug16724-config.php b/tests/legacy/bug16724-config.php similarity index 100% rename from test/bug16724-config.php rename to tests/legacy/bug16724-config.php diff --git a/test/bug16724.phpt b/tests/legacy/bug16724.phpt similarity index 100% rename from test/bug16724.phpt rename to tests/legacy/bug16724.phpt diff --git a/test/bug18124.phpt b/tests/legacy/bug18124.phpt similarity index 100% rename from test/bug18124.phpt rename to tests/legacy/bug18124.phpt diff --git a/test/bug2742.ini b/tests/legacy/bug2742.ini similarity index 100% rename from test/bug2742.ini rename to tests/legacy/bug2742.ini diff --git a/test/bug2742.phpt b/tests/legacy/bug2742.phpt similarity index 100% rename from test/bug2742.phpt rename to tests/legacy/bug2742.phpt diff --git a/test/bug2780.phpt b/tests/legacy/bug2780.phpt similarity index 100% rename from test/bug2780.phpt rename to tests/legacy/bug2780.phpt diff --git a/test/bug3051.phpt b/tests/legacy/bug3051.phpt similarity index 100% rename from test/bug3051.phpt rename to tests/legacy/bug3051.phpt diff --git a/test/bug3051.xml b/tests/legacy/bug3051.xml similarity index 100% rename from test/bug3051.xml rename to tests/legacy/bug3051.xml diff --git a/test/bug3137.phpt b/tests/legacy/bug3137.phpt similarity index 100% rename from test/bug3137.phpt rename to tests/legacy/bug3137.phpt diff --git a/test/bug3298.phpt b/tests/legacy/bug3298.phpt similarity index 100% rename from test/bug3298.phpt rename to tests/legacy/bug3298.phpt diff --git a/test/bug3298.xml b/tests/legacy/bug3298.xml similarity index 100% rename from test/bug3298.xml rename to tests/legacy/bug3298.xml diff --git a/test/bug3398.ini b/tests/legacy/bug3398.ini similarity index 100% rename from test/bug3398.ini rename to tests/legacy/bug3398.ini diff --git a/test/bug3398.phpt b/tests/legacy/bug3398.phpt similarity index 100% rename from test/bug3398.phpt rename to tests/legacy/bug3398.phpt diff --git a/test/bug3590-input.php b/tests/legacy/bug3590-input.php similarity index 100% rename from test/bug3590-input.php rename to tests/legacy/bug3590-input.php diff --git a/test/bug3590.phpt b/tests/legacy/bug3590.phpt similarity index 100% rename from test/bug3590.phpt rename to tests/legacy/bug3590.phpt diff --git a/test/bug4623.conf b/tests/legacy/bug4623.conf similarity index 100% rename from test/bug4623.conf rename to tests/legacy/bug4623.conf diff --git a/test/bug4623.phpt b/tests/legacy/bug4623.phpt similarity index 100% rename from test/bug4623.phpt rename to tests/legacy/bug4623.phpt diff --git a/test/bug6441.ini b/tests/legacy/bug6441.ini similarity index 100% rename from test/bug6441.ini rename to tests/legacy/bug6441.ini diff --git a/test/bug6441.phpt b/tests/legacy/bug6441.phpt similarity index 100% rename from test/bug6441.phpt rename to tests/legacy/bug6441.phpt diff --git a/test/bug7544-inicommented.phpt b/tests/legacy/bug7544-inicommented.phpt similarity index 100% rename from test/bug7544-inicommented.phpt rename to tests/legacy/bug7544-inicommented.phpt diff --git a/test/bug7544-inifile.phpt b/tests/legacy/bug7544-inifile.phpt similarity index 100% rename from test/bug7544-inifile.phpt rename to tests/legacy/bug7544-inifile.phpt diff --git a/test/bug7544.ini b/tests/legacy/bug7544.ini similarity index 100% rename from test/bug7544.ini rename to tests/legacy/bug7544.ini diff --git a/test/bug7652.phpt b/tests/legacy/bug7652.phpt similarity index 100% rename from test/bug7652.phpt rename to tests/legacy/bug7652.phpt diff --git a/test/bug7652.xml b/tests/legacy/bug7652.xml similarity index 100% rename from test/bug7652.xml rename to tests/legacy/bug7652.xml diff --git a/test/bug8357-inicommented.phpt b/tests/legacy/bug8357-inicommented.phpt similarity index 100% rename from test/bug8357-inicommented.phpt rename to tests/legacy/bug8357-inicommented.phpt diff --git a/test/bug8357-inifile.phpt b/tests/legacy/bug8357-inifile.phpt similarity index 100% rename from test/bug8357-inifile.phpt rename to tests/legacy/bug8357-inifile.phpt diff --git a/test/bug8357.ini b/tests/legacy/bug8357.ini similarity index 100% rename from test/bug8357.ini rename to tests/legacy/bug8357.ini diff --git a/tests/legacy/current_test.php b/tests/legacy/current_test.php new file mode 100644 index 0000000..78a037a --- /dev/null +++ b/tests/legacy/current_test.php @@ -0,0 +1,24 @@ +getRoot()->createDirective('STRING', 'this is a string'); +$config->getRoot()->createDirective('STRING_WITH_QUOTES', 'double: " single:\' end'); +$config->getRoot()->createDirective('NUMBER', 12345); +$config->getRoot()->createDirective('NUMERIC_STRING', '67890'); +$config->getRoot()->createDirective('CONSTANT_NAME', 'NUMERIC_STRING'); +$config->getRoot()->createDirective('TRUE', true); +$config->getRoot()->createDirective('FALSE', false); +$config->getRoot()->createDirective('TRUE_STRING', 'true'); +$config->getRoot()->createDirective('FALSE_STRING', 'false'); +$config->getRoot()->createDirective('lowercase_name', 'gets uppercased'); + +$config->getRoot()->createBlank(); +$config->getRoot()->createDirective('AFTER_BLANK', '1'); + +$config->getRoot()->createSection('Comments'); + +$config->getRoot()->createComment('Some comment'); +$config->getRoot()->createDirective('AFTER_COMMENT', '1'); + +echo $config->getRoot()->toString('phpconstants'); +?> \ No newline at end of file diff --git a/test/inifile.ini b/tests/legacy/inifile.ini similarity index 100% rename from test/inifile.ini rename to tests/legacy/inifile.ini diff --git a/test/inifile.phpt b/tests/legacy/inifile.phpt similarity index 100% rename from test/inifile.phpt rename to tests/legacy/inifile.phpt diff --git a/test/phpconstants.phpt b/tests/legacy/phpconstants.phpt similarity index 100% rename from test/phpconstants.phpt rename to tests/legacy/phpconstants.phpt diff --git a/test/setup.php.inc b/tests/legacy/setup.php.inc similarity index 67% rename from test/setup.php.inc rename to tests/legacy/setup.php.inc index 120d93f..6b0afd2 100644 --- a/test/setup.php.inc +++ b/tests/legacy/setup.php.inc @@ -1,5 +1,5 @@ Date: Sun, 26 Jan 2020 03:33:35 +0100 Subject: [PATCH 3/9] Integrate PHPUnit --- .gitignore | 3 + .travis.yml | 6 +- composer.json | 7 +- phpunit.xml | 31 +++++++ test/run_tests.php | 91 ------------------- tests/AbstractTest.php | 18 ++++ tests/bootstrap_phpunit.php | 13 +++ tests/legacy/LegacyTest.php | 60 ++++++++++++ {test => tests/legacy}/bug10010.phpt | 0 {test => tests/legacy}/bug10185.phpt | 0 {test => tests/legacy}/bug11184.phpt | 0 .../legacy}/bug11435-inicommented.phpt | 0 {test => tests/legacy}/bug11435-inifile.phpt | 0 {test => tests/legacy}/bug11435.ini | 0 {test => tests/legacy}/bug11807.phpt | 0 tests/legacy/bug11807.txt | 7 ++ {test => tests/legacy}/bug11827.ini | 0 {test => tests/legacy}/bug11827.phpt | 0 {test => tests/legacy}/bug12291.ini | 0 {test => tests/legacy}/bug12291.phpt | 0 {test => tests/legacy}/bug12387.ini | 0 {test => tests/legacy}/bug12387.phpt | 0 {test => tests/legacy}/bug12388.ini | 0 {test => tests/legacy}/bug12388.phpt | 0 {test => tests/legacy}/bug13791.phpt | 0 {test => tests/legacy}/bug16590-2.phpt | 0 {test => tests/legacy}/bug16590.phpt | 0 {test => tests/legacy}/bug16656.ini | 0 {test => tests/legacy}/bug16656.phpt | 0 {test => tests/legacy}/bug16724-config.php | 0 {test => tests/legacy}/bug16724.phpt | 0 {test => tests/legacy}/bug18124.phpt | 0 {test => tests/legacy}/bug2742.ini | 0 {test => tests/legacy}/bug2742.phpt | 0 {test => tests/legacy}/bug2780.phpt | 0 {test => tests/legacy}/bug3051.phpt | 0 {test => tests/legacy}/bug3051.xml | 0 {test => tests/legacy}/bug3137.phpt | 0 {test => tests/legacy}/bug3298.phpt | 0 {test => tests/legacy}/bug3298.xml | 0 {test => tests/legacy}/bug3398.ini | 0 {test => tests/legacy}/bug3398.phpt | 0 {test => tests/legacy}/bug3590-input.php | 0 {test => tests/legacy}/bug3590.phpt | 0 {test => tests/legacy}/bug4623.conf | 0 {test => tests/legacy}/bug4623.phpt | 0 {test => tests/legacy}/bug6441.ini | 0 {test => tests/legacy}/bug6441.phpt | 0 .../legacy}/bug7544-inicommented.phpt | 0 {test => tests/legacy}/bug7544-inifile.phpt | 0 {test => tests/legacy}/bug7544.ini | 0 {test => tests/legacy}/bug7652.phpt | 0 {test => tests/legacy}/bug7652.xml | 0 .../legacy}/bug8357-inicommented.phpt | 0 {test => tests/legacy}/bug8357-inifile.phpt | 0 {test => tests/legacy}/bug8357.ini | 0 tests/legacy/current_test.php | 24 +++++ {test => tests/legacy}/inifile.ini | 0 {test => tests/legacy}/inifile.phpt | 0 {test => tests/legacy}/phpconstants.phpt | 0 {test => tests/legacy}/setup.php.inc | 2 +- 61 files changed, 162 insertions(+), 100 deletions(-) create mode 100644 phpunit.xml delete mode 100644 test/run_tests.php create mode 100644 tests/AbstractTest.php create mode 100644 tests/bootstrap_phpunit.php create mode 100644 tests/legacy/LegacyTest.php rename {test => tests/legacy}/bug10010.phpt (100%) rename {test => tests/legacy}/bug10185.phpt (100%) rename {test => tests/legacy}/bug11184.phpt (100%) rename {test => tests/legacy}/bug11435-inicommented.phpt (100%) rename {test => tests/legacy}/bug11435-inifile.phpt (100%) rename {test => tests/legacy}/bug11435.ini (100%) rename {test => tests/legacy}/bug11807.phpt (100%) create mode 100644 tests/legacy/bug11807.txt rename {test => tests/legacy}/bug11827.ini (100%) rename {test => tests/legacy}/bug11827.phpt (100%) rename {test => tests/legacy}/bug12291.ini (100%) rename {test => tests/legacy}/bug12291.phpt (100%) rename {test => tests/legacy}/bug12387.ini (100%) rename {test => tests/legacy}/bug12387.phpt (100%) rename {test => tests/legacy}/bug12388.ini (100%) rename {test => tests/legacy}/bug12388.phpt (100%) rename {test => tests/legacy}/bug13791.phpt (100%) rename {test => tests/legacy}/bug16590-2.phpt (100%) rename {test => tests/legacy}/bug16590.phpt (100%) rename {test => tests/legacy}/bug16656.ini (100%) rename {test => tests/legacy}/bug16656.phpt (100%) rename {test => tests/legacy}/bug16724-config.php (100%) rename {test => tests/legacy}/bug16724.phpt (100%) rename {test => tests/legacy}/bug18124.phpt (100%) rename {test => tests/legacy}/bug2742.ini (100%) rename {test => tests/legacy}/bug2742.phpt (100%) rename {test => tests/legacy}/bug2780.phpt (100%) rename {test => tests/legacy}/bug3051.phpt (100%) rename {test => tests/legacy}/bug3051.xml (100%) rename {test => tests/legacy}/bug3137.phpt (100%) rename {test => tests/legacy}/bug3298.phpt (100%) rename {test => tests/legacy}/bug3298.xml (100%) rename {test => tests/legacy}/bug3398.ini (100%) rename {test => tests/legacy}/bug3398.phpt (100%) rename {test => tests/legacy}/bug3590-input.php (100%) rename {test => tests/legacy}/bug3590.phpt (100%) rename {test => tests/legacy}/bug4623.conf (100%) rename {test => tests/legacy}/bug4623.phpt (100%) rename {test => tests/legacy}/bug6441.ini (100%) rename {test => tests/legacy}/bug6441.phpt (100%) rename {test => tests/legacy}/bug7544-inicommented.phpt (100%) rename {test => tests/legacy}/bug7544-inifile.phpt (100%) rename {test => tests/legacy}/bug7544.ini (100%) rename {test => tests/legacy}/bug7652.phpt (100%) rename {test => tests/legacy}/bug7652.xml (100%) rename {test => tests/legacy}/bug8357-inicommented.phpt (100%) rename {test => tests/legacy}/bug8357-inifile.phpt (100%) rename {test => tests/legacy}/bug8357.ini (100%) create mode 100644 tests/legacy/current_test.php rename {test => tests/legacy}/inifile.ini (100%) rename {test => tests/legacy}/inifile.phpt (100%) rename {test => tests/legacy}/phpconstants.phpt (100%) rename {test => tests/legacy}/setup.php.inc (67%) diff --git a/.gitignore b/.gitignore index 869f498..24524b5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ composer.lock composer.phar vendor +tests/coverage +.phpunit.result.cache +clover.xml diff --git a/.travis.yml b/.travis.yml index 1a7578e..fec7f0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php install: - - pear install -a package.xml + - composer install php: - - 5.5 -script: phpunit test/ \ No newline at end of file + - 7.4 +script: phpunit diff --git a/composer.json b/composer.json index 6a0b2d2..5afcd1b 100644 --- a/composer.json +++ b/composer.json @@ -39,13 +39,10 @@ "type": "library", "require": { "pear/pear": "^1.10", - "pear/xml_parser": "^1.3", - "sebastian/diff": "^3.0" + "pear/xml_parser": "^1.3" }, "require-dev": { - "phpunit/phpunit": "*", - "pear/text_diff": "^1.2", - "phpspec/php-diff": "^1.1" + "phpunit/phpunit": "*" }, "suggest": { "pear/xml_parser": "Install optionally via your project's composer.json" diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..c01bfd0 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,31 @@ + + + + + + + ./tests/integration + ./tests/legacy + + + + + + + ./Config + + + + + + + + + diff --git a/test/run_tests.php b/test/run_tests.php deleted file mode 100644 index 7d64659..0000000 --- a/test/run_tests.php +++ /dev/null @@ -1,91 +0,0 @@ - $shell_argument) { - if ($shell_argument == '--filter') { - if (! empty($argv[$i+1])) { - $arguments['filter'] = $argv[$i+1]; - } - } -} -// var_dump($arguments); -// exit; - -$differ = new Differ; - -error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); - -$tests_failed = []; - -foreach ($files as $file) { - if (preg_match("/\.phpt$/", $file)) { - - if (! empty($arguments['filter']) && $file != $arguments['filter']) { - continue; - } - - $test_parts = file_get_contents(__DIR__ . '/' . $file); - $test_parts = preg_split("/(^|\n)--/", $test_parts); - $parts = []; - foreach (array_filter($test_parts) as $test_part) { - if (! preg_match("#^(\w+)--(\n([\s\S]+))?$#m", $test_part, $matches)) { - throw new \Exception('Invalid test part: '.$test_part); - } - $parts[$matches[1]] = isset($matches[3]) ? $matches[3] : ''; - } - - echo "$file: {$parts['TEST']}\n"; - $current_test_filename = __DIR__ . '/current_test.php'; - file_exists($current_test_filename) && unlink($current_test_filename); - file_put_contents($current_test_filename, $parts['FILE']); - - $output = shell_exec("php$php_version $current_test_filename"); - - if (trim($output) != trim($parts['EXPECT'])) { - echo "Test failed\n"; - - // Options for generating the diff - $options = array( - //'ignoreWhitespace' => true, - //'ignoreCase' => true, - ); - - // Initialize the diff class - // print $differ->diff('foo', 'bar'); - $diff = new Diff( - explode("\n", $parts['EXPECT']), - explode("\n", $output), - $options - ); - - $renderer = new Diff_Renderer_Text_Unified; - echo $diff->render($renderer); - echo "\n$output\n"; - // echo "Expected:\n{$parts['EXPECT']}\n"; - $tests_failed[] = "$file: {$parts['TEST']}"; - // exit; - } - - if (isset($parts['CLEAN'])) { - $current_clean_filename = __DIR__ . '/current_clean.php'; - file_put_contents($current_clean_filename, $parts['CLEAN']); - require_once $current_clean_filename; - unlink($current_clean_filename); - } - } -} -/**/ diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php new file mode 100644 index 0000000..0324972 --- /dev/null +++ b/tests/AbstractTest.php @@ -0,0 +1,18 @@ +getName() ."\n" ); + } + + /**/ +} diff --git a/tests/bootstrap_phpunit.php b/tests/bootstrap_phpunit.php new file mode 100644 index 0000000..6447b21 --- /dev/null +++ b/tests/bootstrap_phpunit.php @@ -0,0 +1,13 @@ + $legacy_test) { + $out[] = [$filename, $legacy_test]; + } + + return $out; + } + + /** + * @dataProvider dataProvider_legacy_unit_tests + */ + public function test_legacy_unit_tests($filename, $parts) + { + $php_version = explode('.',phpversion()); + $php_version = $php_version[0] . '.' . $php_version[1]; + + $current_test_filename = __DIR__ . '/current_test.php'; + file_exists($current_test_filename) && unlink($current_test_filename); + file_put_contents($current_test_filename, $parts['FILE']); + $output = shell_exec("php$php_version $current_test_filename"); + + $this->assertEquals( + trim($parts['EXPECT']), + trim($output) + ); + + if (isset($parts['CLEAN'])) { + $current_clean_filename = __DIR__ . '/current_clean.php'; + file_put_contents($current_clean_filename, $parts['CLEAN']); + require_once $current_clean_filename; + unlink($current_clean_filename); + } + } + + /**/ +} diff --git a/test/bug10010.phpt b/tests/legacy/bug10010.phpt similarity index 100% rename from test/bug10010.phpt rename to tests/legacy/bug10010.phpt diff --git a/test/bug10185.phpt b/tests/legacy/bug10185.phpt similarity index 100% rename from test/bug10185.phpt rename to tests/legacy/bug10185.phpt diff --git a/test/bug11184.phpt b/tests/legacy/bug11184.phpt similarity index 100% rename from test/bug11184.phpt rename to tests/legacy/bug11184.phpt diff --git a/test/bug11435-inicommented.phpt b/tests/legacy/bug11435-inicommented.phpt similarity index 100% rename from test/bug11435-inicommented.phpt rename to tests/legacy/bug11435-inicommented.phpt diff --git a/test/bug11435-inifile.phpt b/tests/legacy/bug11435-inifile.phpt similarity index 100% rename from test/bug11435-inifile.phpt rename to tests/legacy/bug11435-inifile.phpt diff --git a/test/bug11435.ini b/tests/legacy/bug11435.ini similarity index 100% rename from test/bug11435.ini rename to tests/legacy/bug11435.ini diff --git a/test/bug11807.phpt b/tests/legacy/bug11807.phpt similarity index 100% rename from test/bug11807.phpt rename to tests/legacy/bug11807.phpt diff --git a/tests/legacy/bug11807.txt b/tests/legacy/bug11807.txt new file mode 100644 index 0000000..c0bf2db --- /dev/null +++ b/tests/legacy/bug11807.txt @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/test/bug11827.ini b/tests/legacy/bug11827.ini similarity index 100% rename from test/bug11827.ini rename to tests/legacy/bug11827.ini diff --git a/test/bug11827.phpt b/tests/legacy/bug11827.phpt similarity index 100% rename from test/bug11827.phpt rename to tests/legacy/bug11827.phpt diff --git a/test/bug12291.ini b/tests/legacy/bug12291.ini similarity index 100% rename from test/bug12291.ini rename to tests/legacy/bug12291.ini diff --git a/test/bug12291.phpt b/tests/legacy/bug12291.phpt similarity index 100% rename from test/bug12291.phpt rename to tests/legacy/bug12291.phpt diff --git a/test/bug12387.ini b/tests/legacy/bug12387.ini similarity index 100% rename from test/bug12387.ini rename to tests/legacy/bug12387.ini diff --git a/test/bug12387.phpt b/tests/legacy/bug12387.phpt similarity index 100% rename from test/bug12387.phpt rename to tests/legacy/bug12387.phpt diff --git a/test/bug12388.ini b/tests/legacy/bug12388.ini similarity index 100% rename from test/bug12388.ini rename to tests/legacy/bug12388.ini diff --git a/test/bug12388.phpt b/tests/legacy/bug12388.phpt similarity index 100% rename from test/bug12388.phpt rename to tests/legacy/bug12388.phpt diff --git a/test/bug13791.phpt b/tests/legacy/bug13791.phpt similarity index 100% rename from test/bug13791.phpt rename to tests/legacy/bug13791.phpt diff --git a/test/bug16590-2.phpt b/tests/legacy/bug16590-2.phpt similarity index 100% rename from test/bug16590-2.phpt rename to tests/legacy/bug16590-2.phpt diff --git a/test/bug16590.phpt b/tests/legacy/bug16590.phpt similarity index 100% rename from test/bug16590.phpt rename to tests/legacy/bug16590.phpt diff --git a/test/bug16656.ini b/tests/legacy/bug16656.ini similarity index 100% rename from test/bug16656.ini rename to tests/legacy/bug16656.ini diff --git a/test/bug16656.phpt b/tests/legacy/bug16656.phpt similarity index 100% rename from test/bug16656.phpt rename to tests/legacy/bug16656.phpt diff --git a/test/bug16724-config.php b/tests/legacy/bug16724-config.php similarity index 100% rename from test/bug16724-config.php rename to tests/legacy/bug16724-config.php diff --git a/test/bug16724.phpt b/tests/legacy/bug16724.phpt similarity index 100% rename from test/bug16724.phpt rename to tests/legacy/bug16724.phpt diff --git a/test/bug18124.phpt b/tests/legacy/bug18124.phpt similarity index 100% rename from test/bug18124.phpt rename to tests/legacy/bug18124.phpt diff --git a/test/bug2742.ini b/tests/legacy/bug2742.ini similarity index 100% rename from test/bug2742.ini rename to tests/legacy/bug2742.ini diff --git a/test/bug2742.phpt b/tests/legacy/bug2742.phpt similarity index 100% rename from test/bug2742.phpt rename to tests/legacy/bug2742.phpt diff --git a/test/bug2780.phpt b/tests/legacy/bug2780.phpt similarity index 100% rename from test/bug2780.phpt rename to tests/legacy/bug2780.phpt diff --git a/test/bug3051.phpt b/tests/legacy/bug3051.phpt similarity index 100% rename from test/bug3051.phpt rename to tests/legacy/bug3051.phpt diff --git a/test/bug3051.xml b/tests/legacy/bug3051.xml similarity index 100% rename from test/bug3051.xml rename to tests/legacy/bug3051.xml diff --git a/test/bug3137.phpt b/tests/legacy/bug3137.phpt similarity index 100% rename from test/bug3137.phpt rename to tests/legacy/bug3137.phpt diff --git a/test/bug3298.phpt b/tests/legacy/bug3298.phpt similarity index 100% rename from test/bug3298.phpt rename to tests/legacy/bug3298.phpt diff --git a/test/bug3298.xml b/tests/legacy/bug3298.xml similarity index 100% rename from test/bug3298.xml rename to tests/legacy/bug3298.xml diff --git a/test/bug3398.ini b/tests/legacy/bug3398.ini similarity index 100% rename from test/bug3398.ini rename to tests/legacy/bug3398.ini diff --git a/test/bug3398.phpt b/tests/legacy/bug3398.phpt similarity index 100% rename from test/bug3398.phpt rename to tests/legacy/bug3398.phpt diff --git a/test/bug3590-input.php b/tests/legacy/bug3590-input.php similarity index 100% rename from test/bug3590-input.php rename to tests/legacy/bug3590-input.php diff --git a/test/bug3590.phpt b/tests/legacy/bug3590.phpt similarity index 100% rename from test/bug3590.phpt rename to tests/legacy/bug3590.phpt diff --git a/test/bug4623.conf b/tests/legacy/bug4623.conf similarity index 100% rename from test/bug4623.conf rename to tests/legacy/bug4623.conf diff --git a/test/bug4623.phpt b/tests/legacy/bug4623.phpt similarity index 100% rename from test/bug4623.phpt rename to tests/legacy/bug4623.phpt diff --git a/test/bug6441.ini b/tests/legacy/bug6441.ini similarity index 100% rename from test/bug6441.ini rename to tests/legacy/bug6441.ini diff --git a/test/bug6441.phpt b/tests/legacy/bug6441.phpt similarity index 100% rename from test/bug6441.phpt rename to tests/legacy/bug6441.phpt diff --git a/test/bug7544-inicommented.phpt b/tests/legacy/bug7544-inicommented.phpt similarity index 100% rename from test/bug7544-inicommented.phpt rename to tests/legacy/bug7544-inicommented.phpt diff --git a/test/bug7544-inifile.phpt b/tests/legacy/bug7544-inifile.phpt similarity index 100% rename from test/bug7544-inifile.phpt rename to tests/legacy/bug7544-inifile.phpt diff --git a/test/bug7544.ini b/tests/legacy/bug7544.ini similarity index 100% rename from test/bug7544.ini rename to tests/legacy/bug7544.ini diff --git a/test/bug7652.phpt b/tests/legacy/bug7652.phpt similarity index 100% rename from test/bug7652.phpt rename to tests/legacy/bug7652.phpt diff --git a/test/bug7652.xml b/tests/legacy/bug7652.xml similarity index 100% rename from test/bug7652.xml rename to tests/legacy/bug7652.xml diff --git a/test/bug8357-inicommented.phpt b/tests/legacy/bug8357-inicommented.phpt similarity index 100% rename from test/bug8357-inicommented.phpt rename to tests/legacy/bug8357-inicommented.phpt diff --git a/test/bug8357-inifile.phpt b/tests/legacy/bug8357-inifile.phpt similarity index 100% rename from test/bug8357-inifile.phpt rename to tests/legacy/bug8357-inifile.phpt diff --git a/test/bug8357.ini b/tests/legacy/bug8357.ini similarity index 100% rename from test/bug8357.ini rename to tests/legacy/bug8357.ini diff --git a/tests/legacy/current_test.php b/tests/legacy/current_test.php new file mode 100644 index 0000000..78a037a --- /dev/null +++ b/tests/legacy/current_test.php @@ -0,0 +1,24 @@ +getRoot()->createDirective('STRING', 'this is a string'); +$config->getRoot()->createDirective('STRING_WITH_QUOTES', 'double: " single:\' end'); +$config->getRoot()->createDirective('NUMBER', 12345); +$config->getRoot()->createDirective('NUMERIC_STRING', '67890'); +$config->getRoot()->createDirective('CONSTANT_NAME', 'NUMERIC_STRING'); +$config->getRoot()->createDirective('TRUE', true); +$config->getRoot()->createDirective('FALSE', false); +$config->getRoot()->createDirective('TRUE_STRING', 'true'); +$config->getRoot()->createDirective('FALSE_STRING', 'false'); +$config->getRoot()->createDirective('lowercase_name', 'gets uppercased'); + +$config->getRoot()->createBlank(); +$config->getRoot()->createDirective('AFTER_BLANK', '1'); + +$config->getRoot()->createSection('Comments'); + +$config->getRoot()->createComment('Some comment'); +$config->getRoot()->createDirective('AFTER_COMMENT', '1'); + +echo $config->getRoot()->toString('phpconstants'); +?> \ No newline at end of file diff --git a/test/inifile.ini b/tests/legacy/inifile.ini similarity index 100% rename from test/inifile.ini rename to tests/legacy/inifile.ini diff --git a/test/inifile.phpt b/tests/legacy/inifile.phpt similarity index 100% rename from test/inifile.phpt rename to tests/legacy/inifile.phpt diff --git a/test/phpconstants.phpt b/tests/legacy/phpconstants.phpt similarity index 100% rename from test/phpconstants.phpt rename to tests/legacy/phpconstants.phpt diff --git a/test/setup.php.inc b/tests/legacy/setup.php.inc similarity index 67% rename from test/setup.php.inc rename to tests/legacy/setup.php.inc index 120d93f..6b0afd2 100644 --- a/test/setup.php.inc +++ b/tests/legacy/setup.php.inc @@ -1,5 +1,5 @@ Date: Sun, 26 Jan 2020 03:46:07 +0100 Subject: [PATCH 4/9] Create README.md --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8594dfa --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Pear / Config +Configuration parsers for Apache, Ini files, PHP constants, Xml and generic .conf files. + +[![Build Status](https://travis-ci.org/pear/config.png?branch=master)](https://travis-ci.org/pear/config) + +## Installation +Add the following to your composer.json: +``` +{ + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/pear/Config" + "no-api": true + } + ], + "require": { + "pear/Config": "dev-master", + } +} +``` From a79bc0d45b91e568134123799e895ab7557bbccc Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 26 Jan 2020 03:53:36 +0100 Subject: [PATCH 5/9] Hide tests titles --- tests/AbstractTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index 0324972..c6fc3bd 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -11,7 +11,7 @@ public static function setUpBeforeClass() : void public function setUp() : void { - echo( get_called_class() . '::' . $this->getName() ."\n" ); + // echo( get_called_class() . '::' . $this->getName() ."\n" ); } /**/ From ebe47a9023721c21b35d4f290f5bf247ca135002 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 6 Feb 2020 16:52:48 +0100 Subject: [PATCH 6/9] Support older PHP versions --- .travis.yml | 12 ++++++++++-- tests/AbstractTest.php | 14 -------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index fec7f0b..3f74dee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,14 @@ language: php install: - - composer install + - composer install --prefer-dist --no-progress + php: + - 5.6 + - 7.0 + - 7.1 + - 7.2 + - 7.3 - 7.4 -script: phpunit + +script: + - vendor/bin/phpunit diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index c6fc3bd..114c55c 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -1,18 +1,4 @@ getName() ."\n" ); - } - - /**/ } From 8bc1d1b6c70bd21f40e0ec11820173d030129488 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 6 Feb 2020 16:56:33 +0100 Subject: [PATCH 7/9] Cleaner empty attributes checking --- Config/Container.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Config/Container.php b/Config/Container.php index 393eef7..14323de 100644 --- a/Config/Container.php +++ b/Config/Container.php @@ -692,7 +692,7 @@ function toArray($useAttr = true) $array[$this->name] = array(); switch ($this->type) { case 'directive': - if ($useAttr && $this->attributes && count($this->attributes) > 0) { + if ($useAttr && !empty($this->attributes)) { $array[$this->name]['#'] = $this->content; $array[$this->name]['@'] = $this->attributes; } else { @@ -700,7 +700,7 @@ function toArray($useAttr = true) } break; case 'section': - if ($useAttr && $this->attributes&& count($this->attributes) > 0) { + if ($useAttr && !empty($this->attributes)) { $array[$this->name]['@'] = $this->attributes; } if ($count = count($this->children)) { From 9521f0c623560e95d7075d226003a416a3513cca Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 6 Feb 2020 17:07:40 +0100 Subject: [PATCH 8/9] Clean phpunit.xml --- phpunit.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index c01bfd0..e98ef7d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,9 +18,6 @@ ./Config - From 8783674f7fba41fb17041798a1179c08951f7504 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 9 Feb 2020 20:30:48 +0100 Subject: [PATCH 9/9] Removing .phpunit.result.cache from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 24524b5..11685a9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ composer.lock composer.phar vendor tests/coverage -.phpunit.result.cache clover.xml