refactor: comments

This commit is contained in:
Nuno Maduro
2021-10-24 22:39:35 +01:00
parent 648c6c5a27
commit cd34f0ba81
14 changed files with 50 additions and 61 deletions

View File

@ -23,10 +23,8 @@ final class Each
/** /**
* Creates a new expectation. * Creates a new expectation.
*
* @param mixed $value
*/ */
public function and($value): Expectation public function and(mixed $value): Expectation
{ {
return $this->original->and($value); return $this->original->and($value);
} }

View File

@ -23,31 +23,31 @@ use RuntimeException;
final class TestCaseFactory final class TestCaseFactory
{ {
/** /**
* Marks this test case as only. * Determines if the Test Case will be the "only" being run.
*/ */
public bool $only = false; public bool $only = false;
/** /**
* Holds the test closure. * The Test Case closure.
*/ */
public Closure $test; public Closure $test;
/** /**
* Holds the dataset, if any. * The Test Case Dataset, if any.
* *
* @var array<Closure|iterable<int|string, mixed>|string> * @var array<Closure|iterable<int|string, mixed>|string>
*/ */
public array $datasets = []; public array $datasets = [];
/** /**
* The FQN of the test case class. * The FQN of the Test Case class.
* *
* @var class-string * @var class-string
*/ */
public string $class = TestCase::class; public string $class = TestCase::class;
/** /**
* An array of FQN of the class traits. * An array of FQN of the Test Case traits.
* *
* @var array <int, class-string> * @var array <int, class-string>
*/ */
@ -57,22 +57,22 @@ final class TestCaseFactory
]; ];
/** /**
* Holds the higher order messages for the factory that are proxyable. * The higher order messages for the factory that are proxyable.
*/ */
public HigherOrderMessageCollection $factoryProxies; public HigherOrderMessageCollection $factoryProxies;
/** /**
* Holds the higher order messages that are proxyable. * The higher order messages that are proxyable.
*/ */
public HigherOrderMessageCollection $proxies; public HigherOrderMessageCollection $proxies;
/** /**
* Holds the higher order messages that are chainable. * The higher order messages that are chainable.
*/ */
public HigherOrderMessageCollection $chains; public HigherOrderMessageCollection $chains;
/** /**
* Creates a new anonymous test case pending object. * Creates a new Factory instance.
*/ */
public function __construct( public function __construct(
public string $filename, public string $filename,
@ -87,11 +87,11 @@ final class TestCaseFactory
} }
/** /**
* Builds the anonymous test case. * Makes the Test Case classes.
* *
* @return array<int, TestCase> * @return array<int, TestCase>
*/ */
public function build(TestSuite $testSuite): array public function make(): array
{ {
if ($this->description === null) { if ($this->description === null) {
throw ShouldNotHappen::fromMessage('Description can not be empty.'); throw ShouldNotHappen::fromMessage('Description can not be empty.');
@ -101,10 +101,7 @@ final class TestCaseFactory
$proxies = $this->proxies; $proxies = $this->proxies;
$factoryTest = $this->test; $factoryTest = $this->test;
/** $testClosure = function () use ($chains, $proxies, $factoryTest): mixed {
* @return mixed
*/
$test = function () use ($chains, $proxies, $factoryTest) {
$proxies->proxy($this); $proxies->proxy($this);
$chains->chain($this); $chains->chain($this);
@ -114,8 +111,8 @@ final class TestCaseFactory
$className = $this->makeClassFromFilename($this->filename); $className = $this->makeClassFromFilename($this->filename);
$createTest = function ($description, $data) use ($className, $test) { $createTest = function ($description, $data) use ($className, $testClosure) {
$testCase = new $className($test, $description, $data); $testCase = new $className($testClosure, $description, $data);
$this->factoryProxies->proxy($testCase); $this->factoryProxies->proxy($testCase);
return $testCase; return $testCase;
@ -127,7 +124,7 @@ final class TestCaseFactory
} }
/** /**
* Makes a fully qualified class name from the given filename. * Makes a Fully Qualified Class Name from the given filename.
*/ */
public function makeClassFromFilename(string $filename): string public function makeClassFromFilename(string $filename): string
{ {

View File

@ -4,10 +4,10 @@ declare(strict_types=1);
use Pest\Datasets; use Pest\Datasets;
use Pest\Expectation; use Pest\Expectation;
use Pest\PendingObjects\AfterEachCall; use Pest\PendingCalls\AfterEachCall;
use Pest\PendingObjects\BeforeEachCall; use Pest\PendingCalls\BeforeEachCall;
use Pest\PendingObjects\TestCall; use Pest\PendingCalls\TestCall;
use Pest\PendingObjects\UsesCall; use Pest\PendingCalls\UsesCall;
use Pest\Support\Backtrace; use Pest\Support\Backtrace;
use Pest\Support\Extendable; use Pest\Support\Extendable;
use Pest\Support\HigherOrderTapProxy; use Pest\Support\HigherOrderTapProxy;

View File

@ -17,7 +17,7 @@ use Pest\TestSuite;
final class PestDatasetCommand extends Command final class PestDatasetCommand extends Command
{ {
/** /**
* The console command name. * The Console Command name.
* *
* @var string * @var string
*/ */
@ -25,7 +25,7 @@ final class PestDatasetCommand extends Command
{--test-directory=tests : The name of the tests directory}'; {--test-directory=tests : The name of the tests directory}';
/** /**
* The console command description. * The Console Command description.
* *
* @var string * @var string
*/ */

View File

@ -14,7 +14,7 @@ use Pest\Laravel\Commands\PestTestCommand;
final class PestServiceProvider extends ServiceProvider final class PestServiceProvider extends ServiceProvider
{ {
/** /**
* Register artisan commands. * Register Artisan Commands.
*/ */
public function register(): void public function register(): void
{ {

View File

@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Pest\PendingObjects; namespace Pest\PendingCalls;
use Closure; use Closure;
use Pest\Support\Backtrace; use Pest\Support\Backtrace;
@ -17,21 +17,22 @@ use Pest\TestSuite;
final class AfterEachCall final class AfterEachCall
{ {
/** /**
* Holds the before each closure. * The "afterEach" closure.
*/ */
private Closure $closure; private Closure $closure;
/** /**
* Holds calls that should be proxied. * The calls that should be proxied.
*/ */
private HigherOrderMessageCollection $proxies; private HigherOrderMessageCollection $proxies;
/** /**
* Creates a new instance of before each call. * Creates a new Pending Call.
*/ */
public function __construct( public function __construct(
private TestSuite $testSuite, private TestSuite $testSuite,
private string $filename, Closure $closure = null private string $filename,
Closure $closure = null
) { ) {
$this->closure = $closure instanceof Closure ? $closure : NullClosure::create(); $this->closure = $closure instanceof Closure ? $closure : NullClosure::create();
@ -39,7 +40,7 @@ final class AfterEachCall
} }
/** /**
* Dispatch the creation of each call. * Creates the Call.
*/ */
public function __destruct() public function __destruct()
{ {

View File

@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Pest\PendingObjects; namespace Pest\PendingCalls;
use Closure; use Closure;
use Pest\Support\Backtrace; use Pest\Support\Backtrace;
@ -22,12 +22,12 @@ final class BeforeEachCall
private \Closure $closure; private \Closure $closure;
/** /**
* Holds calls that should be proxied. * The calls that should be proxied.
*/ */
private HigherOrderMessageCollection $proxies; private HigherOrderMessageCollection $proxies;
/** /**
* Creates a new instance of before each call. * Creates a new Pending Call.
*/ */
public function __construct( public function __construct(
private TestSuite $testSuite, private TestSuite $testSuite,
@ -40,7 +40,7 @@ final class BeforeEachCall
} }
/** /**
* Dispatch the creation of each call. * Creates the Call.
*/ */
public function __destruct() public function __destruct()
{ {

View File

@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Pest\PendingObjects; namespace Pest\PendingCalls;
use Closure; use Closure;
use Pest\Factories\TestCaseFactory; use Pest\Factories\TestCaseFactory;
@ -20,21 +20,17 @@ use SebastianBergmann\Exporter\Exporter;
final class TestCall final class TestCall
{ {
/** /**
* Holds the test case factory. * The Test Case Factory.
*
* @readonly
*/ */
private TestCaseFactory $testCaseFactory; private TestCaseFactory $testCaseFactory;
/** /**
* If test call is descriptionLess. * If test call is descriptionLess.
*
* @readonly
*/ */
private bool $descriptionLess = false; private bool $descriptionLess;
/** /**
* Creates a new instance of a pending test call. * Creates a new Pending Call.
*/ */
public function __construct( public function __construct(
private TestSuite $testSuite, private TestSuite $testSuite,
@ -207,8 +203,7 @@ final class TestCall
} }
/** /**
* Adds the current test case factory * Creates the Call.
* to the tests repository.
*/ */
public function __destruct() public function __destruct()
{ {

View File

@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Pest\PendingObjects; namespace Pest\PendingCalls;
use Closure; use Closure;
use Pest\TestSuite; use Pest\TestSuite;
@ -41,7 +41,7 @@ final class UsesCall
private array $groups = []; private array $groups = [];
/** /**
* Creates a new instance of a pending test uses. * Creates a new Pending Call.
* *
* @param array<int, string> $classAndTraits * @param array<int, string> $classAndTraits
*/ */
@ -135,7 +135,7 @@ final class UsesCall
} }
/** /**
* Dispatch the creation of uses. * Creates the Call.
*/ */
public function __destruct() public function __destruct()
{ {

View File

@ -13,8 +13,7 @@ final class AddsOutput
/** /**
* Executes the Plugin action. * Executes the Plugin action.
* *
* Provides an opportunity for any plugins that want * Provides an opportunity for any plugins that want to provide additional output after test execution.
* to provide additional output after test execution.
*/ */
public function __invoke(int $exitCode): int public function __invoke(int $exitCode): int
{ {

View File

@ -28,7 +28,7 @@ final class Coverage implements AddsOutput, HandlesArguments
private const MIN_OPTION = 'min'; private const MIN_OPTION = 'min';
/** /**
* Whether should show the coverage or not. * Whether it should show the coverage or not.
*/ */
public bool $coverage = false; public bool $coverage = false;

View File

@ -101,7 +101,7 @@ final class TestRepository
foreach ($state as $testFactory) { foreach ($state as $testFactory) {
/** @var TestCaseFactory $testFactory */ /** @var TestCaseFactory $testFactory */
$tests = $testFactory->build($testSuite); $tests = $testFactory->make($testSuite);
foreach ($tests as $test) { foreach ($tests as $test) {
$each($test); $each($test);
} }

View File

@ -60,10 +60,9 @@ final class TestSuite
/** /**
* Creates a new instance of the test suite. * Creates a new instance of the test suite.
*/ */
public function __construct(string $rootPath, /** public function __construct(
* Holds the test path. string $rootPath,
*/ public string $testPath)
public string $testPath)
{ {
$this->beforeAll = new BeforeAllRepository(); $this->beforeAll = new BeforeAllRepository();
$this->beforeEach = new BeforeEachRepository(); $this->beforeEach = new BeforeEachRepository();
@ -71,7 +70,7 @@ final class TestSuite
$this->afterEach = new AfterEachRepository(); $this->afterEach = new AfterEachRepository();
$this->afterAll = new AfterAllRepository(); $this->afterAll = new AfterAllRepository();
$this->rootPath = (string) realpath($rootPath); $this->rootPath = (string) realpath($rootPath);
} }
/** /**

View File

@ -1,6 +1,6 @@
<?php <?php
use Pest\PendingObjects\TestCall; use Pest\PendingCalls\TestCall;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
uses(Gettable::class); uses(Gettable::class);