mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 18:27:23 +01:00
feat: --todo flag
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user