diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 3a39b0a7..d43ed458 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -29,7 +29,7 @@ final class TestRepository /** * @var array */ - public $state = []; + private $state = []; /** * @var array>> @@ -44,6 +44,16 @@ final class TestRepository return count($this->state); } + /** + * @return array + */ + public function getFilenames(): array + { + return array_values(array_map(function (TestCaseFactory $factory): string { + return $factory->filename; + }, $this->state)); + } + /** * Calls the given callable foreach test case. */ diff --git a/tests/Unit/TestSuite.php b/tests/Unit/TestSuite.php index 62cc724d..96263a3a 100644 --- a/tests/Unit/TestSuite.php +++ b/tests/Unit/TestSuite.php @@ -22,3 +22,15 @@ it('alerts users about tests with arguments but no input', function () { DatasetMissing::class, sprintf("A test with the description '%s' has %d argument(s) ([%s]) and no dataset(s) provided in %s", 'foo', 1, 'int $arg', __FILE__), ); + +it('can return an array of all test suite filenames', function() { + $testSuite = new TestSuite(getcwd(), 'tests'); + $test = function () {}; + $testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test)); + $testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'bar', $test)); + + expect($testSuite->tests->getFilenames())->toEqual([ + __FILE__, + __FILE__, + ]); +});