Skip to content

Commit

Permalink
feat: deprecates only feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Feb 14, 2023
1 parent ea6af71 commit a61db76
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 88 deletions.
24 changes: 2 additions & 22 deletions src/Factories/TestCaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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;
Expand Down Expand Up @@ -83,36 +82,17 @@ public function __construct(

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<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.
*
* @param array<int, TestCaseMethodFactory> $methods
* @param array<string, TestCaseMethodFactory> $methods
*/
public function evaluate(string $filename, array $methods): void
{
Expand Down
5 changes: 0 additions & 5 deletions src/Factories/TestCaseMethodFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".
*/
Expand Down
10 changes: 0 additions & 10 deletions src/PendingCalls/TestCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,6 @@ public function depends(string ...$depends): self
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).
*/
Expand Down
8 changes: 1 addition & 7 deletions src/Repositories/TestRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ public function count(): int
*/
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));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/.snapshots/Failure.php.inc
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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']
Expand Down
4 changes: 1 addition & 3 deletions tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Tests: 4 incomplete, 4 todos, 18 skipped, 634 passed (1554 assertions)
37 changes: 0 additions & 37 deletions tests/Unit/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -40,39 +39,3 @@
'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);
});
4 changes: 2 additions & 2 deletions tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
};

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)');
});

0 comments on commit a61db76

Please sign in to comment.