file_find_recursive_test.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22. * @version //autogentag//
  23. * @filesource
  24. * @package Base
  25. * @subpackage Tests
  26. */
  27. /**
  28. * @package Base
  29. * @subpackage Tests
  30. */
  31. class ezcBaseFileFindRecursiveTest extends ezcTestCase
  32. {
  33. public function testRecursive1()
  34. {
  35. $expected = array(
  36. 0 => 'src/base.php',
  37. 1 => 'src/base_autoload.php',
  38. 2 => 'src/exceptions/autoload.php',
  39. 3 => 'src/exceptions/double_class_repository_prefix.php',
  40. 4 => 'src/exceptions/exception.php',
  41. 5 => 'src/exceptions/extension_not_found.php',
  42. 6 => 'src/exceptions/file_exception.php',
  43. 7 => 'src/exceptions/file_io.php',
  44. 8 => 'src/exceptions/file_not_found.php',
  45. 9 => 'src/exceptions/file_permission.php',
  46. 10 => 'src/exceptions/functionality_not_supported.php',
  47. 11 => 'src/exceptions/init_callback_configured.php',
  48. 12 => 'src/exceptions/invalid_callback_class.php',
  49. 13 => 'src/exceptions/invalid_parent_class.php',
  50. 14 => 'src/exceptions/property_not_found.php',
  51. 15 => 'src/exceptions/property_permission.php',
  52. 16 => 'src/exceptions/setting_not_found.php',
  53. 17 => 'src/exceptions/setting_value.php',
  54. 18 => 'src/exceptions/value.php',
  55. 19 => 'src/exceptions/whatever.php',
  56. 20 => 'src/ezc_bootstrap.php',
  57. 21 => 'src/features.php',
  58. 22 => 'src/file.php',
  59. 23 => 'src/init.php',
  60. 24 => 'src/interfaces/configuration_initializer.php',
  61. 25 => 'src/interfaces/exportable.php',
  62. 26 => 'src/interfaces/persistable.php',
  63. 27 => 'src/metadata.php',
  64. 28 => 'src/metadata/pear.php',
  65. 29 => 'src/metadata/tarball.php',
  66. 30 => 'src/options.php',
  67. 31 => 'src/options/autoload.php',
  68. 32 => 'src/struct.php',
  69. 33 => 'src/structs/file_find_context.php',
  70. 34 => 'src/structs/repository_directory.php',
  71. );
  72. $files = ezcBaseFile::findRecursive( "src", array(), array( '@/docs/@', '@svn@', '@\.swp$@', '@git@' ), $stats );
  73. self::assertEquals( $expected, $files );
  74. self::assertEquals( array( 'size' => 133978, 'count' => 35 ), $stats );
  75. }
  76. public function testRecursive2()
  77. {
  78. $expected = array(
  79. 0 => 'vendor/zetacomponents/unit-test/CREDITS',
  80. 1 => 'vendor/zetacomponents/unit-test/ChangeLog',
  81. 2 => 'vendor/zetacomponents/unit-test/NOTICE',
  82. 3 => 'vendor/zetacomponents/unit-test/composer.json',
  83. 4 => 'vendor/zetacomponents/unit-test/design/class_diagram.png',
  84. 5 => 'vendor/zetacomponents/unit-test/src/constraint/image.php',
  85. 6 => 'vendor/zetacomponents/unit-test/src/regression_suite.php',
  86. 7 => 'vendor/zetacomponents/unit-test/src/regression_test.php',
  87. 8 => 'vendor/zetacomponents/unit-test/src/test/case.php',
  88. 9 => 'vendor/zetacomponents/unit-test/src/test/image_case.php',
  89. 10 => 'vendor/zetacomponents/unit-test/src/test_autoload.php',
  90. );
  91. self::assertEquals( $expected, ezcBaseFile::findRecursive( "vendor/zetacomponents/unit-test", array( '@^vendor/zetacomponents/unit-test/@' ), array( '@/docs/@', '@\.git@', '@\.swp$@' ), $stats ) );
  92. self::assertEquals( array( 'size' => 191012, 'count' => 11 ), $stats );
  93. }
  94. public function testRecursive3()
  95. {
  96. $expected = array (
  97. 0 => 'vendor/zetacomponents/unit-test/design/class_diagram.png',
  98. );
  99. self::assertEquals( $expected, ezcBaseFile::findRecursive( "vendor/zetacomponents/unit-test", array( '@\.png$@' ), array( '@\.svn@' ), $stats ) );
  100. self::assertEquals( array( 'size' => 166066, 'count' => 1 ), $stats );
  101. }
  102. public function testRecursive4()
  103. {
  104. $expected = array (
  105. 0 => 'vendor/zetacomponents/unit-test/design/class_diagram.png',
  106. );
  107. self::assertEquals( $expected, ezcBaseFile::findRecursive( "vendor/zetacomponents/unit-test", array( '@/design/@' ), array( '@\.svn@' ), $stats ) );
  108. self::assertEquals( array( 'size' => 166066, 'count' => 1 ), $stats );
  109. }
  110. public function testRecursive5()
  111. {
  112. $expected = array (
  113. 0 => 'vendor/zetacomponents/unit-test/design/class_diagram.png',
  114. 1 => 'vendor/zetacomponents/unit-test/src/constraint/image.php',
  115. 2 => 'vendor/zetacomponents/unit-test/src/regression_suite.php',
  116. 3 => 'vendor/zetacomponents/unit-test/src/regression_test.php',
  117. 4 => 'vendor/zetacomponents/unit-test/src/test/case.php',
  118. 5 => 'vendor/zetacomponents/unit-test/src/test/image_case.php',
  119. 6 => 'vendor/zetacomponents/unit-test/src/test_autoload.php',
  120. );
  121. self::assertEquals( $expected, ezcBaseFile::findRecursive( "vendor/zetacomponents/unit-test", array( '@\.(php|png)$@' ), array( '@/docs/@', '@\.svn@' ) ) );
  122. }
  123. public function testRecursive6()
  124. {
  125. $expected = array();
  126. self::assertEquals( $expected, ezcBaseFile::findRecursive( "vendor/zetacomponents/unit-test", array( '@xxx@' ) ) );
  127. }
  128. public function testNonExistingDirectory()
  129. {
  130. $expected = array();
  131. try
  132. {
  133. ezcBaseFile::findRecursive( "NotHere", array( '@xxx@' ) );
  134. }
  135. catch ( ezcBaseFileNotFoundException $e )
  136. {
  137. self::assertEquals( "The directory file 'NotHere' could not be found.", $e->getMessage() );
  138. }
  139. }
  140. public function testStatsEmptyArray()
  141. {
  142. $expected = array (
  143. 0 => 'vendor/zetacomponents/unit-test/design/class_diagram.png',
  144. );
  145. $stats = array();
  146. self::assertEquals( $expected, ezcBaseFile::findRecursive( "vendor/zetacomponents/unit-test", array( '@/design/@' ), array( '@\.svn@' ), $stats ) );
  147. self::assertEquals( array( 'size' => 166066, 'count' => 1 ), $stats );
  148. }
  149. public static function suite()
  150. {
  151. return new PHPUnit_Framework_TestSuite( "ezcBaseFileFindRecursiveTest" );
  152. }
  153. }
  154. ?>