TestSuiteTest.php 3.6 KB

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