mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
The getFilenames method now respects only calls.
This commit is contained in:
@ -45,13 +45,17 @@ final class TestRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns the filename of each test that should be run in the suite.
|
||||||
|
*
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public function getFilenames(): array
|
public function getFilenames(): array
|
||||||
{
|
{
|
||||||
|
$testsWithOnly = $this->testsUsingOnly();
|
||||||
|
|
||||||
return array_values(array_map(function (TestCaseFactory $factory): string {
|
return array_values(array_map(function (TestCaseFactory $factory): string {
|
||||||
return $factory->filename;
|
return $factory->filename;
|
||||||
}, $this->state));
|
}, count($testsWithOnly) > 0 ? $testsWithOnly : $this->state));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,9 +99,7 @@ final class TestRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$onlyState = array_filter($this->state, function ($testFactory): bool {
|
$onlyState = $this->testsUsingOnly();
|
||||||
return $testFactory->only;
|
|
||||||
});
|
|
||||||
|
|
||||||
$state = count($onlyState) > 0 ? $onlyState : $this->state;
|
$state = count($onlyState) > 0 ? $onlyState : $this->state;
|
||||||
|
|
||||||
@ -110,6 +112,18 @@ final class TestRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all tests that have called the only method.
|
||||||
|
*
|
||||||
|
* @return array<TestCaseFactory>
|
||||||
|
*/
|
||||||
|
private function testsUsingOnly(): array
|
||||||
|
{
|
||||||
|
return array_filter($this->state, function ($testFactory): bool {
|
||||||
|
return $testFactory->only;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the given `$testCaseClass` on the given `$paths`.
|
* Uses the given `$testCaseClass` on the given `$paths`.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -615,6 +615,7 @@
|
|||||||
✓ it does not allow to add the same test description twice
|
✓ it does not allow to add the same test description twice
|
||||||
✓ it alerts users about tests with arguments but no input
|
✓ it alerts users about tests with arguments but no input
|
||||||
✓ it can return an array of all test suite filenames
|
✓ it can return an array of all test suite filenames
|
||||||
|
✓ it can filter the test suite filenames to those with the only method
|
||||||
|
|
||||||
PASS Tests\Visual\Help
|
PASS Tests\Visual\Help
|
||||||
✓ visual snapshot of help command output
|
✓ visual snapshot of help command output
|
||||||
@ -648,5 +649,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 4 incompleted, 9 skipped, 420 passed
|
Tests: 4 incompleted, 9 skipped, 421 passed
|
||||||
|
|
||||||
@ -34,3 +34,18 @@ it('can return an array of all test suite filenames', function () {
|
|||||||
__FILE__,
|
__FILE__,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can filter the test suite filenames to those with the only method', function () {
|
||||||
|
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||||
|
$test = function () {};
|
||||||
|
|
||||||
|
$testWithOnly = new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test);
|
||||||
|
$testWithOnly->only = true;
|
||||||
|
$testSuite->tests->set($testWithOnly);
|
||||||
|
|
||||||
|
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory('Baz/Bar/Boo.php', 'bar', $test));
|
||||||
|
|
||||||
|
expect($testSuite->tests->getFilenames())->toEqual([
|
||||||
|
__FILE__,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user