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: /**
31: * Adds all the files in a directory to the test suite. Does not recursive through directories.
32: *
33: * @param string $directory The directory to add tests from.
34: * @return void
35: */
36: public function addTestDirectory($directory = '.')
37: {
38: $Folder = new Folder($directory);
39: list(, $files) = $Folder->read(true, true, true);
40:
41: foreach ($files as $file) {
42: if (substr($file, -4) === '.php') {
43: $this->addTestFile($file);
44: }
45: }
46: }
47:
48: /**
49: * Recursively adds all the files in a directory to the test suite.
50: *
51: * @param string $directory The directory subtree to add tests from.
52: * @return void
53: */
54: public function addTestDirectoryRecursive($directory = '.')
55: {
56: $Folder = new Folder($directory);
57: $files = $Folder->tree(null, true, 'files');
58:
59: foreach ($files as $file) {
60: if (substr($file, -4) === '.php') {
61: $this->addTestFile($file);
62: }
63: }
64: }
65: }
66: