TestSuiteTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. public function testAddTestDirectory(): void
  28. {
  29. $testFolder = CORE_TEST_CASES . DS . 'TestSuite';
  30. $count = count(glob($testFolder . DS . '*Test.php'));
  31. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  32. ->onlyMethods(['addTestFile'])
  33. ->getMock();
  34. $suite
  35. ->expects($this->exactly($count))
  36. ->method('addTestFile');
  37. $suite->addTestDirectory($testFolder);
  38. }
  39. /**
  40. * testAddTestDirectoryRecursive
  41. */
  42. public function testAddTestDirectoryRecursive(): void
  43. {
  44. $testFolder = CORE_TEST_CASES . DS . 'Cache';
  45. $count = count(glob($testFolder . DS . '*Test.php'));
  46. $count += count(glob($testFolder . DS . 'Engine/*Test.php'));
  47. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  48. ->onlyMethods(['addTestFile'])
  49. ->getMock();
  50. $suite
  51. ->expects($this->exactly($count))
  52. ->method('addTestFile');
  53. $suite->addTestDirectoryRecursive($testFolder);
  54. }
  55. /**
  56. * testAddTestDirectoryRecursiveWithHidden
  57. */
  58. public function testAddTestDirectoryRecursiveWithHidden(): void
  59. {
  60. $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.');
  61. $path = TMP . 'MyTestFolder';
  62. $fs = new Filesystem();
  63. $fs->mkdir($path);
  64. mkdir($path . DS . '.svn', 0777, true);
  65. touch($path . DS . '.svn/InHiddenFolderTest.php');
  66. touch($path . DS . 'NotHiddenTest.php');
  67. touch($path . DS . '.HiddenTest.php');
  68. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  69. ->onlyMethods(['addTestFile'])
  70. ->getMock();
  71. $suite
  72. ->expects($this->exactly(1))
  73. ->method('addTestFile');
  74. $suite->addTestDirectoryRecursive($path);
  75. $fs->deleteDir($path);
  76. }
  77. /**
  78. * testAddTestDirectoryRecursiveWithNonPhp
  79. */
  80. public function testAddTestDirectoryRecursiveWithNonPhp(): void
  81. {
  82. $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
  83. $path = TMP . 'MyTestFolder';
  84. $fs = new Filesystem();
  85. $fs->mkdir($path);
  86. touch($path . DS . 'BackupTest.php~');
  87. touch($path . DS . 'SomeNotesTest.txt');
  88. touch($path . DS . 'NotHiddenTest.php');
  89. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  90. ->onlyMethods(['addTestFile'])
  91. ->getMock();
  92. $suite
  93. ->expects($this->exactly(1))
  94. ->method('addTestFile');
  95. $suite->addTestDirectoryRecursive($path);
  96. $fs->deleteDir($path);
  97. }
  98. }