TestSuiteTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP Project
  13. * @since 1.2.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\TestSuite;
  17. use Cake\Filesystem\Filesystem;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * TestSuiteTest
  21. */
  22. class TestSuiteTest extends TestCase
  23. {
  24. /**
  25. * testAddTestDirectory
  26. *
  27. * @return void
  28. */
  29. public function testAddTestDirectory()
  30. {
  31. $testFolder = CORE_TEST_CASES . DS . 'TestSuite';
  32. $count = count(glob($testFolder . DS . '*Test.php'));
  33. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  34. ->setMethods(['addTestFile'])
  35. ->getMock();
  36. $suite
  37. ->expects($this->exactly($count))
  38. ->method('addTestFile');
  39. $suite->addTestDirectory($testFolder);
  40. }
  41. /**
  42. * testAddTestDirectoryRecursive
  43. *
  44. * @return void
  45. */
  46. public function testAddTestDirectoryRecursive()
  47. {
  48. $testFolder = CORE_TEST_CASES . DS . 'Cache';
  49. $count = count(glob($testFolder . DS . '*Test.php'));
  50. $count += count(glob($testFolder . DS . 'Engine/*Test.php'));
  51. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  52. ->setMethods(['addTestFile'])
  53. ->getMock();
  54. $suite
  55. ->expects($this->exactly($count))
  56. ->method('addTestFile');
  57. $suite->addTestDirectoryRecursive($testFolder);
  58. }
  59. /**
  60. * testAddTestDirectoryRecursiveWithHidden
  61. *
  62. * @return void
  63. */
  64. public function testAddTestDirectoryRecursiveWithHidden()
  65. {
  66. $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.');
  67. $path = TMP . 'MyTestFolder';
  68. $fs = new Filesystem();
  69. $fs->mkdir($path);
  70. mkdir($path . DS . '.svn', 0777, true);
  71. touch($path . DS . '.svn/InHiddenFolderTest.php');
  72. touch($path . DS . 'NotHiddenTest.php');
  73. touch($path . DS . '.HiddenTest.php');
  74. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  75. ->setMethods(['addTestFile'])
  76. ->getMock();
  77. $suite
  78. ->expects($this->exactly(1))
  79. ->method('addTestFile');
  80. $suite->addTestDirectoryRecursive($path);
  81. $fs->deleteDir($path);
  82. }
  83. /**
  84. * testAddTestDirectoryRecursiveWithNonPhp
  85. *
  86. * @return void
  87. */
  88. public function testAddTestDirectoryRecursiveWithNonPhp()
  89. {
  90. $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
  91. $path = TMP . 'MyTestFolder';
  92. $fs = new Filesystem();
  93. $fs->mkdir($path);
  94. touch($path . DS . 'BackupTest.php~');
  95. touch($path . DS . 'SomeNotesTest.txt');
  96. touch($path . DS . 'NotHiddenTest.php');
  97. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  98. ->setMethods(['addTestFile'])
  99. ->getMock();
  100. $suite
  101. ->expects($this->exactly(1))
  102. ->method('addTestFile');
  103. $suite->addTestDirectoryRecursive($path);
  104. $fs->deleteDir($path);
  105. }
  106. }