mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: deprecates only feature
This commit is contained in:
@ -13,7 +13,6 @@ use Pest\Exceptions\ShouldNotHappen;
|
|||||||
use Pest\Exceptions\TestAlreadyExist;
|
use Pest\Exceptions\TestAlreadyExist;
|
||||||
use Pest\Exceptions\TestDescriptionMissing;
|
use Pest\Exceptions\TestDescriptionMissing;
|
||||||
use Pest\Factories\Concerns\HigherOrderable;
|
use Pest\Factories\Concerns\HigherOrderable;
|
||||||
use Pest\Plugins\Environment;
|
|
||||||
use Pest\Support\Reflection;
|
use Pest\Support\Reflection;
|
||||||
use Pest\Support\Str;
|
use Pest\Support\Str;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
@ -83,36 +82,17 @@ final class TestCaseFactory
|
|||||||
|
|
||||||
public function make(): void
|
public function make(): void
|
||||||
{
|
{
|
||||||
$methodsUsingOnly = $this->methodsUsingOnly();
|
$methods = $this->methods;
|
||||||
|
|
||||||
$methods = array_values(array_filter(
|
|
||||||
$this->methods,
|
|
||||||
fn ($method): bool => $methodsUsingOnly === [] || in_array($method, $methodsUsingOnly, true)
|
|
||||||
));
|
|
||||||
|
|
||||||
if ($methods !== []) {
|
if ($methods !== []) {
|
||||||
$this->evaluate($this->filename, $methods);
|
$this->evaluate($this->filename, $methods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all the "only" methods.
|
|
||||||
*
|
|
||||||
* @return array<int, TestCaseMethodFactory>
|
|
||||||
*/
|
|
||||||
public function methodsUsingOnly(): array
|
|
||||||
{
|
|
||||||
if (Environment::name() === Environment::CI) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_values(array_filter($this->methods, static fn ($method): bool => $method->only));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Test Case class using a runtime evaluate.
|
* Creates a Test Case class using a runtime evaluate.
|
||||||
*
|
*
|
||||||
* @param array<int, TestCaseMethodFactory> $methods
|
* @param array<string, TestCaseMethodFactory> $methods
|
||||||
*/
|
*/
|
||||||
public function evaluate(string $filename, array $methods): void
|
public function evaluate(string $filename, array $methods): void
|
||||||
{
|
{
|
||||||
|
|||||||
@ -21,11 +21,6 @@ final class TestCaseMethodFactory
|
|||||||
{
|
{
|
||||||
use HigherOrderable;
|
use HigherOrderable;
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the Test Case Method will be the "only" being run.
|
|
||||||
*/
|
|
||||||
public bool $only = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the Test Case Method is a "todo".
|
* Determines if the Test Case Method is a "todo".
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -121,16 +121,6 @@ final class TestCall
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes the test suite only this test case.
|
|
||||||
*/
|
|
||||||
public function only(): self
|
|
||||||
{
|
|
||||||
$this->testCaseMethod->only = true;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the test group(s).
|
* Sets the test group(s).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -54,13 +54,7 @@ final class TestRepository
|
|||||||
*/
|
*/
|
||||||
public function getFilenames(): array
|
public function getFilenames(): array
|
||||||
{
|
{
|
||||||
$testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase): bool => $testCase->methodsUsingOnly() !== []);
|
return array_values(array_map(static fn (TestCaseFactory $factory): string => $factory->filename, $this->testCases));
|
||||||
|
|
||||||
if ($testCases === []) {
|
|
||||||
$testCases = $this->testCases;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_values(array_map(static fn (TestCaseFactory $factory): string => $factory->filename, $testCases));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234']
|
##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234']
|
||||||
##teamcity[testStarted name='it can fail with comparison' locationHint='pest_qn://tests/.tests/Failure.php::it can fail with comparison' flowId='1234']
|
##teamcity[testStarted name='it can fail with comparison' locationHint='pest_qn://tests/.tests/Failure.php::it can fail with comparison' flowId='1234']
|
||||||
##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:342|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:105|nat src/Concerns/Testable.php:262|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:262|nat src/Concerns/Testable.php:217|nat src/Kernel.php:89' type='comparisonFailure' actual='true' expected='false' flowId='1234']
|
##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:342|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:262|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:262|nat src/Concerns/Testable.php:217|nat src/Kernel.php:89' type='comparisonFailure' actual='true' expected='false' flowId='1234']
|
||||||
##teamcity[testFinished name='it can fail with comparison' duration='100000' flowId='1234']
|
##teamcity[testFinished name='it can fail with comparison' duration='100000' flowId='1234']
|
||||||
##teamcity[testStarted name='it can be ignored because of no assertions' locationHint='pest_qn://tests/.tests/Failure.php::it can be ignored because of no assertions' flowId='1234']
|
##teamcity[testStarted name='it can be ignored because of no assertions' locationHint='pest_qn://tests/.tests/Failure.php::it can be ignored because of no assertions' flowId='1234']
|
||||||
##teamcity[testIgnored name='it can be ignored because of no assertions' message='This test did not perform any assertions' details='' flowId='1234']
|
##teamcity[testIgnored name='it can be ignored because of no assertions' message='This test did not perform any assertions' details='' flowId='1234']
|
||||||
@ -9,7 +9,7 @@
|
|||||||
##teamcity[testIgnored name='it can be ignored because it is skipped' message='This test was ignored.' details='' flowId='1234']
|
##teamcity[testIgnored name='it can be ignored because it is skipped' message='This test was ignored.' details='' flowId='1234']
|
||||||
##teamcity[testFinished name='it can be ignored because it is skipped' duration='100000' flowId='1234']
|
##teamcity[testFinished name='it can be ignored because it is skipped' duration='100000' flowId='1234']
|
||||||
##teamcity[testStarted name='it can fail' locationHint='pest_qn://tests/.tests/Failure.php::it can fail' flowId='1234']
|
##teamcity[testStarted name='it can fail' locationHint='pest_qn://tests/.tests/Failure.php::it can fail' flowId='1234']
|
||||||
##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:105|nat src/Concerns/Testable.php:262|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:262|nat src/Concerns/Testable.php:217|nat src/Kernel.php:89' flowId='1234']
|
##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:262|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:262|nat src/Concerns/Testable.php:217|nat src/Kernel.php:89' flowId='1234']
|
||||||
##teamcity[testFinished name='it can fail' duration='100000' flowId='1234']
|
##teamcity[testFinished name='it can fail' duration='100000' flowId='1234']
|
||||||
##teamcity[testStarted name='it is not done yet' locationHint='pest_qn://tests/.tests/Failure.php::it is not done yet' flowId='1234']
|
##teamcity[testStarted name='it is not done yet' locationHint='pest_qn://tests/.tests/Failure.php::it is not done yet' flowId='1234']
|
||||||
##teamcity[testIgnored name='it is not done yet' message='This test was ignored.' details='' flowId='1234']
|
##teamcity[testIgnored name='it is not done yet' message='This test was ignored.' details='' flowId='1234']
|
||||||
|
|||||||
@ -892,8 +892,6 @@
|
|||||||
✓ 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
|
|
||||||
✓ it does not filter the test suite filenames to those with the only method when working in CI pipeline
|
|
||||||
|
|
||||||
PASS Tests\Visual\Help
|
PASS Tests\Visual\Help
|
||||||
✓ visual snapshot of help command output
|
✓ visual snapshot of help command output
|
||||||
@ -919,4 +917,4 @@
|
|||||||
PASS Tests\Visual\Version
|
PASS Tests\Visual\Version
|
||||||
✓ visual snapshot of help command output
|
✓ visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 4 incomplete, 4 todos, 18 skipped, 636 passed (1556 assertions)
|
Tests: 4 incomplete, 4 todos, 18 skipped, 634 passed (1554 assertions)
|
||||||
@ -3,7 +3,6 @@
|
|||||||
use Pest\Exceptions\DatasetMissing;
|
use Pest\Exceptions\DatasetMissing;
|
||||||
use Pest\Exceptions\TestAlreadyExist;
|
use Pest\Exceptions\TestAlreadyExist;
|
||||||
use Pest\Factories\TestCaseMethodFactory;
|
use Pest\Factories\TestCaseMethodFactory;
|
||||||
use Pest\Plugins\Environment;
|
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
|
|
||||||
it('does not allow to add the same test description twice', function () {
|
it('does not allow to add the same test description twice', function () {
|
||||||
@ -40,39 +39,3 @@ it('can return an array of all test suite filenames', function () {
|
|||||||
'c',
|
'c',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can filter the test suite filenames to those with the only method', function () {
|
|
||||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
|
||||||
|
|
||||||
$testWithOnly = new TestCaseMethodFactory('a', 'b', null);
|
|
||||||
$testWithOnly->only = true;
|
|
||||||
$testSuite->tests->set($testWithOnly);
|
|
||||||
|
|
||||||
$testSuite->tests->set(new TestCaseMethodFactory('c', 'd', null));
|
|
||||||
|
|
||||||
expect($testSuite->tests->getFilenames())->toEqual([
|
|
||||||
'a',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not filter the test suite filenames to those with the only method when working in CI pipeline', function () {
|
|
||||||
$previousEnvironment = Environment::name();
|
|
||||||
Environment::name(Environment::CI);
|
|
||||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
|
||||||
|
|
||||||
$test = function () {
|
|
||||||
};
|
|
||||||
|
|
||||||
$testWithOnly = new TestCaseMethodFactory('a', 'b', null);
|
|
||||||
$testWithOnly->only = true;
|
|
||||||
$testSuite->tests->set($testWithOnly);
|
|
||||||
|
|
||||||
$testSuite->tests->set(new TestCaseMethodFactory('c', 'd', null));
|
|
||||||
|
|
||||||
expect($testSuite->tests->getFilenames())->toEqual([
|
|
||||||
'a',
|
|
||||||
'c',
|
|
||||||
]);
|
|
||||||
|
|
||||||
Environment::name($previousEnvironment);
|
|
||||||
});
|
|
||||||
|
|||||||
@ -13,6 +13,6 @@ $run = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run())->toContain('Running 652 tests using 3 processes')
|
expect($run())->toContain('Running 650 tests using 3 processes')
|
||||||
->toContain('Tests: 4 incomplete, 4 todos, 15 skipped, 629 passed (1548 assertions)');
|
->toContain('Tests: 4 incomplete, 4 todos, 15 skipped, 627 passed (1546 assertions)');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user