From a61db76c24ef0b886a13fc9dbc40f0d50dbc0da3 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 14 Feb 2023 08:40:02 +0000 Subject: [PATCH] feat: deprecates `only` feature --- src/Factories/TestCaseFactory.php | 24 ++-------------- src/Factories/TestCaseMethodFactory.php | 5 ---- src/PendingCalls/TestCall.php | 10 ------- src/Repositories/TestRepository.php | 8 +----- tests/.snapshots/Failure.php.inc | 4 +-- tests/.snapshots/success.txt | 4 +-- tests/Unit/TestSuite.php | 37 ------------------------- tests/Visual/Parallel.php | 4 +-- 8 files changed, 8 insertions(+), 88 deletions(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 91210e8d..cedce46f 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -13,7 +13,6 @@ use Pest\Exceptions\ShouldNotHappen; use Pest\Exceptions\TestAlreadyExist; use Pest\Exceptions\TestDescriptionMissing; use Pest\Factories\Concerns\HigherOrderable; -use Pest\Plugins\Environment; use Pest\Support\Reflection; use Pest\Support\Str; use Pest\TestSuite; @@ -83,36 +82,17 @@ final class TestCaseFactory public function make(): void { - $methodsUsingOnly = $this->methodsUsingOnly(); - - $methods = array_values(array_filter( - $this->methods, - fn ($method): bool => $methodsUsingOnly === [] || in_array($method, $methodsUsingOnly, true) - )); + $methods = $this->methods; if ($methods !== []) { $this->evaluate($this->filename, $methods); } } - /** - * Returns all the "only" methods. - * - * @return array - */ - 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. * - * @param array $methods + * @param array $methods */ public function evaluate(string $filename, array $methods): void { diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index 98643d54..ef46b841 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -21,11 +21,6 @@ final class TestCaseMethodFactory { 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". */ diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 5099b13a..430e632d 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -121,16 +121,6 @@ final class TestCall 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). */ diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index d698fbd8..e2221e16 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -54,13 +54,7 @@ final class TestRepository */ public function getFilenames(): array { - $testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase): bool => $testCase->methodsUsingOnly() !== []); - - if ($testCases === []) { - $testCases = $this->testCases; - } - - return array_values(array_map(static fn (TestCaseFactory $factory): string => $factory->filename, $testCases)); + return array_values(array_map(static fn (TestCaseFactory $factory): string => $factory->filename, $this->testCases)); } /** diff --git a/tests/.snapshots/Failure.php.inc b/tests/.snapshots/Failure.php.inc index 2acc8cc8..09ca928d 100644 --- a/tests/.snapshots/Failure.php.inc +++ b/tests/.snapshots/Failure.php.inc @@ -1,6 +1,6 @@ ##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[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[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'] @@ -9,7 +9,7 @@ ##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[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[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'] diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index aeb7deaa..7af47ab2 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -892,8 +892,6 @@ ✓ it does not allow to add the same test description twice ✓ it alerts users about tests with arguments but no input ✓ 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 ✓ visual snapshot of help command output @@ -919,4 +917,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 4 incomplete, 4 todos, 18 skipped, 636 passed (1556 assertions) \ No newline at end of file + Tests: 4 incomplete, 4 todos, 18 skipped, 634 passed (1554 assertions) \ No newline at end of file diff --git a/tests/Unit/TestSuite.php b/tests/Unit/TestSuite.php index c25830f0..3c4ff2a1 100644 --- a/tests/Unit/TestSuite.php +++ b/tests/Unit/TestSuite.php @@ -3,7 +3,6 @@ use Pest\Exceptions\DatasetMissing; use Pest\Exceptions\TestAlreadyExist; use Pest\Factories\TestCaseMethodFactory; -use Pest\Plugins\Environment; use Pest\TestSuite; 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', ]); }); - -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); -}); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 4e269fcb..5b622870 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -13,6 +13,6 @@ $run = function () { }; test('parallel', function () use ($run) { - expect($run())->toContain('Running 652 tests using 3 processes') - ->toContain('Tests: 4 incomplete, 4 todos, 15 skipped, 629 passed (1548 assertions)'); + expect($run())->toContain('Running 650 tests using 3 processes') + ->toContain('Tests: 4 incomplete, 4 todos, 15 skipped, 627 passed (1546 assertions)'); });