mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: --todo flag
This commit is contained in:
13
bin/pest
13
bin/pest
@ -5,6 +5,7 @@ use Pest\ConfigLoader;
|
||||
use Pest\Kernel;
|
||||
use Pest\Support\Container;
|
||||
use Pest\TestCaseFilters\GitDirtyTestCaseFilter;
|
||||
use Pest\TestCaseMethodFilters\TodoTestCaseFilter;
|
||||
use Pest\TestSuite;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@ -17,6 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
$args = $_SERVER['argv'];
|
||||
$dirty = false;
|
||||
$todo = false;
|
||||
|
||||
foreach ($args as $key => $value) {
|
||||
if (str_contains($value, '--compact')) {
|
||||
@ -38,6 +40,11 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
unset($args[$key]);
|
||||
}
|
||||
|
||||
if (str_contains($value, '--todo')) {
|
||||
$todo = true;
|
||||
unset($args[$key]);
|
||||
}
|
||||
|
||||
if (str_contains($value, '--teamcity')) {
|
||||
unset($args[$key]);
|
||||
$args[] = '--no-output';
|
||||
@ -69,7 +76,11 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
);
|
||||
|
||||
if ($dirty) {
|
||||
$testSuite->tests->filter(new GitDirtyTestCaseFilter($rootPath));
|
||||
$testSuite->tests->addTestCaseFilter(new GitDirtyTestCaseFilter($rootPath));
|
||||
}
|
||||
|
||||
if ($todo) {
|
||||
$testSuite->tests->addTestCaseMethodFilter(new TodoTestCaseFilter());
|
||||
}
|
||||
|
||||
$isDecorated = $argv->getParameterOption('--colors', 'always') !== 'never';
|
||||
|
||||
15
src/Contracts/TestCaseMethodFilter.php
Normal file
15
src/Contracts/TestCaseMethodFilter.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Contracts;
|
||||
|
||||
use Pest\Factories\TestCaseMethodFactory;
|
||||
|
||||
interface TestCaseMethodFilter
|
||||
{
|
||||
/**
|
||||
* Whether the test case method is accepted.
|
||||
*/
|
||||
public function accept(TestCaseMethodFactory $factory): bool;
|
||||
}
|
||||
@ -23,10 +23,15 @@ final class TestCaseMethodFactory
|
||||
use HigherOrderable;
|
||||
|
||||
/**
|
||||
* Determines if the Test Case will be the "only" being run.
|
||||
* 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".
|
||||
*/
|
||||
public bool $todo = false;
|
||||
|
||||
/**
|
||||
* The Test Case Dataset, if any.
|
||||
*
|
||||
|
||||
@ -134,7 +134,7 @@ if (! function_exists('todo')) {
|
||||
|
||||
assert($test instanceof TestCall);
|
||||
|
||||
return $test->skip('__TODO__');
|
||||
return $test->todo();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -208,7 +208,6 @@ final class TeamCityLogger
|
||||
$telemetry->memoryUsageSinceStart(),
|
||||
$telemetry->durationSincePrevious(),
|
||||
$telemetry->memoryUsageSincePrevious(),
|
||||
$telemetry->emitter(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -177,6 +177,8 @@ final class TestCall
|
||||
{
|
||||
$this->skip('__TODO__');
|
||||
|
||||
$this->testCaseMethod->todo = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ namespace Pest\Repositories;
|
||||
|
||||
use Closure;
|
||||
use Pest\Contracts\TestCaseFilter;
|
||||
use Pest\Contracts\TestCaseMethodFilter;
|
||||
use Pest\Exceptions\TestCaseAlreadyInUse;
|
||||
use Pest\Exceptions\TestCaseClassOrTraitNotFound;
|
||||
use Pest\Factories\TestCaseFactory;
|
||||
@ -31,7 +32,12 @@ final class TestRepository
|
||||
/**
|
||||
* @var array<int, TestCaseFilter>
|
||||
*/
|
||||
private array $filters = [];
|
||||
private array $testCaseFilters = [];
|
||||
|
||||
/**
|
||||
* @var array<int, TestCaseMethodFilter>
|
||||
*/
|
||||
private array $testCaseMethodFilters = [];
|
||||
|
||||
/**
|
||||
* Counts the number of test cases.
|
||||
@ -93,9 +99,17 @@ final class TestRepository
|
||||
/**
|
||||
* Filters the test cases using the given filter.
|
||||
*/
|
||||
public function filter(TestCaseFilter $filter): void
|
||||
public function addTestCaseFilter(TestCaseFilter $filter): void
|
||||
{
|
||||
$this->filters[] = $filter;
|
||||
$this->testCaseFilters[] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the test cases using the given filter.
|
||||
*/
|
||||
public function addTestCaseMethodFilter(TestCaseMethodFilter $filter): void
|
||||
{
|
||||
$this->testCaseMethodFilters[] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,6 +125,12 @@ final class TestRepository
|
||||
*/
|
||||
public function set(TestCaseMethodFactory $method): void
|
||||
{
|
||||
foreach ($this->testCaseMethodFilters as $filter) {
|
||||
if (! $filter->accept($method)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (! array_key_exists($method->filename, $this->testCases)) {
|
||||
$this->testCases[$method->filename] = new TestCaseFactory($method->filename);
|
||||
}
|
||||
@ -128,7 +148,7 @@ final class TestRepository
|
||||
}
|
||||
|
||||
$accepted = array_reduce(
|
||||
$this->filters,
|
||||
$this->testCaseFilters,
|
||||
fn (bool $carry, TestCaseFilter $filter): bool => $carry && $filter->accept($filename),
|
||||
true,
|
||||
);
|
||||
|
||||
16
src/TestCaseMethodFilters/TodoTestCaseFilter.php
Normal file
16
src/TestCaseMethodFilters/TodoTestCaseFilter.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\TestCaseMethodFilters;
|
||||
|
||||
use Pest\Contracts\TestCaseMethodFilter;
|
||||
use Pest\Factories\TestCaseMethodFactory;
|
||||
|
||||
final class TodoTestCaseFilter implements TestCaseMethodFilter
|
||||
{
|
||||
public function accept(TestCaseMethodFactory $factory): bool
|
||||
{
|
||||
return $factory->todo;
|
||||
}
|
||||
}
|
||||
@ -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:312|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:101|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:79' 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:312|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:106|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:79' 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:101|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:79' flowId='1234']
|
||||
##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:106|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:79' 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']
|
||||
|
||||
@ -896,7 +896,10 @@
|
||||
- visual snapshot of team city with ('Failure.php')
|
||||
- visual snapshot of team city with ('SuccessOnly.php')
|
||||
|
||||
PASS Tests\Visual\Todo
|
||||
✓ todo
|
||||
|
||||
PASS Tests\Visual\Version
|
||||
✓ visual snapshot of help command output
|
||||
|
||||
Tests: 4 incomplete, 4 todos, 18 skipped, 624 passed (1511 assertions)
|
||||
Tests: 4 incomplete, 4 todos, 18 skipped, 625 passed (1512 assertions)
|
||||
12
tests/.snapshots/todo.txt
Normal file
12
tests/.snapshots/todo.txt
Normal file
@ -0,0 +1,12 @@
|
||||
PASS Tests\Features\DatasetsTests
|
||||
↓ forbids to define tests in Datasets dirs and Datasets.php files
|
||||
|
||||
PASS Tests\Features\Todo
|
||||
↓ something todo later
|
||||
↓ something todo later chained
|
||||
↓ something todo later chained and with function body
|
||||
|
||||
PASS Tests\CustomTestCase\ExecutedTest
|
||||
✓ that gets executed
|
||||
|
||||
Tests: 4 todos, 1 passed (1 assertions)
|
||||
27
tests/Visual/Todo.php
Normal file
27
tests/Visual/Todo.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
$run = function (string $target, $decorated = false) {
|
||||
$process = new Process(['php', 'bin/pest', $target, '--colors=always'], dirname(__DIR__, 2),
|
||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'],
|
||||
);
|
||||
|
||||
$process->run();
|
||||
|
||||
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||
};
|
||||
|
||||
$snapshot = function ($name) {
|
||||
$testsPath = dirname(__DIR__);
|
||||
|
||||
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
|
||||
$testsPath,
|
||||
'.snapshots',
|
||||
"$name.txt",
|
||||
]));
|
||||
};
|
||||
|
||||
test('todo', function () use ($run, $snapshot) {
|
||||
expect($run('--todo'))->toContain($snapshot('todo'));
|
||||
})->skip(PHP_OS_FAMILY === 'Windows');
|
||||
Reference in New Issue
Block a user