1: <?php
2: /**
3: * A class to contain test cases and run them with shared fixtures
4: *
5: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
6: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
7: *
8: * Licensed under The MIT License
9: * For full copyright and license information, please see the LICENSE.txt
10: * Redistributions of files must retain the above copyright notice.
11: *
12: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
13: * @link https://cakephp.org CakePHP(tm) Project
14: * @since 2.0.0
15: * @license https://opensource.org/licenses/mit-license.php MIT License
16: */
17: namespace Cake\TestSuite;
18:
19: loadPHPUnitAliases();
20:
21: use Cake\Filesystem\Folder;
22: use PHPUnit\Framework\TestSuite as BaseTestSuite;
23:
24: /**
25: * A class to contain test cases and run them with shared fixtures
26: */
27: class TestSuite extends BaseTestSuite
28: {
29: /**
30: * Adds all the files in a directory to the test suite. Does not recursive through directories.
31: *
32: * @param string $directory The directory to add tests from.
33: * @return void
34: */
35: public function addTestDirectory($directory = '.')
36: {
37: $Folder = new Folder($directory);
38: list(, $files) = $Folder->read(true, true, true);
39:
40: foreach ($files as $file) {
41: if (substr($file, -4) === '.php') {
42: $this->addTestFile($file);
43: }
44: }
45: }
46:
47: /**
48: * Recursively adds all the files in a directory to the test suite.
49: *
50: * @param string $directory The directory subtree to add tests from.
51: * @return void
52: */
53: public function addTestDirectoryRecursive($directory = '.')
54: {
55: $Folder = new Folder($directory);
56: $files = $Folder->tree(null, true, 'files');
57:
58: foreach ($files as $file) {
59: if (substr($file, -4) === '.php') {
60: $this->addTestFile($file);
61: }
62: }
63: }
64: }
65: