Adds a method for getting all filenames

This commit is contained in:
luke
2021-08-13 10:26:38 +01:00
parent c2070cd99d
commit d9749ca65b
2 changed files with 23 additions and 1 deletions

View File

@ -29,7 +29,7 @@ final class TestRepository
/**
* @var array<string, TestCaseFactory>
*/
public $state = [];
private $state = [];
/**
* @var array<string, array<int, array<int, string|Closure>>>
@ -44,6 +44,16 @@ final class TestRepository
return count($this->state);
}
/**
* @return array<int, string>
*/
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.
*/

View File

@ -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__,
]);
});