TestSuiteTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP Project
  12. * @since 1.2.0
  13. * @license http://www.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. */
  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. $Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
  68. mkdir($Folder->path . DS . '.svn', 0777, true);
  69. touch($Folder->path . DS . '.svn/InHiddenFolderTest.php');
  70. touch($Folder->path . DS . 'NotHiddenTest.php');
  71. touch($Folder->path . DS . '.HiddenTest.php');
  72. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  73. ->setMethods(['addTestFile'])
  74. ->getMock();
  75. $suite
  76. ->expects($this->exactly(1))
  77. ->method('addTestFile');
  78. $suite->addTestDirectoryRecursive($Folder->pwd());
  79. $Folder->delete();
  80. }
  81. /**
  82. * testAddTestDirectoryRecursiveWithNonPhp
  83. *
  84. * @return void
  85. */
  86. public function testAddTestDirectoryRecursiveWithNonPhp()
  87. {
  88. $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
  89. $Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
  90. touch($Folder->path . DS . 'BackupTest.php~');
  91. touch($Folder->path . DS . 'SomeNotesTest.txt');
  92. touch($Folder->path . DS . 'NotHiddenTest.php');
  93. $suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
  94. ->setMethods(['addTestFile'])
  95. ->getMock();
  96. $suite
  97. ->expects($this->exactly(1))
  98. ->method('addTestFile');
  99. $suite->addTestDirectoryRecursive($Folder->pwd());
  100. $Folder->delete();
  101. }
  102. }