PHP_Compat
[ class tree: PHP_Compat ] [ index: PHP_Compat ] [ all elements ]

Source for file package-test.php

Documentation is available at package-test.php

  1. <?php
  2. /**
  3.  * Ensure all components are correctly included.
  4.  *
  5.  * This checks the filesystem, and compares it to the components.php file, and the package2.xml
  6.  */
  7.  
  8. // Helper function
  9. function phpt2php($filename)
  10. {
  11.     return substr($filename, 0, -1);
  12. }
  13.  
  14. // Get array of functions on filesystem
  15. $filesystem = scandir('Compat/Function/');
  16. unset($filesystem[array_search('.', $filesystem)]);
  17. unset($filesystem[array_search('..', $filesystem)]);
  18. unset($filesystem[array_search('CVS', $filesystem)]);
  19. unset($filesystem[array_search('.DS_Store', $filesystem)]);
  20. sort($filesystem);
  21.  
  22. // Get array of tests on filesystem
  23. $tests = scandir('tests/function/');
  24. unset($tests[array_search('.', $tests)]);
  25. unset($tests[array_search('..', $tests)]);
  26. unset($tests[array_search('CVS', $tests)]);
  27. unset($tests[array_search('.DS_Store', $tests)]);
  28. $tests_org = $tests;
  29. $tests = array_map('phpt2php', $tests);
  30. sort($tests);
  31.     
  32. // Find any incomplete tests
  33. $incompleteTests = array();
  34. foreach ($tests_org as $testfile) {
  35.     $testfilename = 'tests/function/' . $testfile;
  36.     if (file_get_contents($testfilename, null, null, 9, 12) === '[INCOMPLETE]') {
  37.         $incompleteTests[] = $testfile;
  38.     }
  39. }
  40.  
  41. // Get a list of files from the package2.xml
  42. $xml = simplexml_load_file('package2.xml');
  43. $xml->registerXPathNamespace('pear', 'http://pear.php.net/dtd/package-2.0');
  44. $xpath = '/pear:package/pear:contents/pear:dir[@name="/"]/pear:dir[@name="Compat"]/pear:dir[@name="Function"]/pear:file';
  45. $filexml = array();
  46. foreach ($xml->xpath($xpath) as $file) {
  47.     $filexml[] = (string) $file['name'];
  48. }
  49. sort($filexml);
  50.     
  51. // Get a list of tests from the package2.xml
  52. $xpath = '/pear:package/pear:contents/pear:dir[@name="/"]/pear:dir[@name="tests"]/pear:dir[@name="function"]/pear:file';
  53. $testxml = array();
  54. foreach ($xml->xpath($xpath) as $file) {
  55.     $testxml[] = (string) $file['name'];
  56. }
  57. sort($testxml);
  58.  
  59. // Get list of files from Components.php
  60. require 'Compat/Components.php';
  61. $filecomps = array_keys($components['function']);
  62. foreach ($filecomps as $k => $comp) { $filecomps[$k] = $comp . '.php'; }
  63. sort($filecomps);
  64.  
  65. // Diff them
  66. $error = false;
  67. $res = array_diff($filesystem, $filexml);
  68. if (!empty($res)) {
  69.     echo "Exists in filesystem but not in XML:\n";
  70.     echo '- ' . implode($res, ', ') . "\n";
  71.     $error = true;
  72. }
  73.  
  74. $res = $incompleteTests;
  75. if (!empty($res)) {
  76.     echo "Incomplete test:\n";
  77.     echo '- ' . implode($res, ', ') . "\n";
  78.     $error = true;
  79. }
  80.     
  81. $res = array_diff($tests_org, $testxml);
  82. if (!empty($res)) {
  83.     echo "Exists in filesystem but not in tests XML:\n";
  84.     echo '- ' . implode($res, ', ') . "\n";
  85.     $error = true;
  86. }
  87.  
  88. $res = array_diff($filesystem, $filecomps);
  89. if (!empty($res)) {
  90.    echo "Exists in filesystem but not in Components:\n";
  91.    echo '- ' . implode($res, ', ') . "\n";
  92.    $error = true;
  93. }
  94.  
  95. $res = array_diff($filexml, $filesystem);
  96. if (!empty($res)) {
  97.     echo "Exists in XML but not in Filesytem:\n";
  98.     echo '- ' . implode($res, ', ') . "\n";
  99.     $error = true;
  100. }
  101.  
  102. $res = array_diff($filesystem, $tests);
  103. if (!empty($res)) {
  104.     echo "Tests not found for the following files:\n";
  105.     echo '- ' . implode($res, ', ') . "\n";
  106.     $error = true;
  107. }
  108.  
  109. if ($error === false) {
  110.     echo "No errors found\n";
  111. }
  112.  
  113. ?>

Documentation generated on Mon, 11 Mar 2019 15:39:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.