chore: coding style changes

This commit is contained in:
nuno maduro
2026-08-07 14:52:56 +01:00
parent eb88513baf
commit 42d9b777bf
221 changed files with 139 additions and 3086 deletions
-9
View File
@@ -19,9 +19,6 @@ final class AfterAllRepository
*/
private array $state = [];
/**
* Runs the given closure for each after all.
*/
public function each(callable $each): void
{
foreach ($this->state as $filename => $closure) {
@@ -29,9 +26,6 @@ final class AfterAllRepository
}
}
/**
* Sets a after all closure.
*/
public function set(Closure $closure): void
{
$filename = Reflection::getFileNameFromClosure($closure);
@@ -43,9 +37,6 @@ final class AfterAllRepository
$this->state[$filename] = $closure;
}
/**
* Gets a after all closure by the given filename.
*/
public function get(string $filename): Closure
{
return $this->state[$filename] ?? NullClosure::create();
-6
View File
@@ -20,9 +20,6 @@ final class AfterEachRepository
*/
private array $state = [];
/**
* Sets a after each closure.
*/
public function set(string $filename, AfterEachCall $afterEachCall, Closure $afterEachTestCase): void
{
if (array_key_exists($filename, $this->state)) {
@@ -37,9 +34,6 @@ final class AfterEachRepository
$this->state[$filename] = $afterEachTestCase;
}
/**
* Gets an after each closure by the given filename.
*/
public function get(string $filename): Closure
{
$afterEach = $this->state[$filename] ?? NullClosure::create();
-9
View File
@@ -19,9 +19,6 @@ final class BeforeAllRepository
*/
private array $state = [];
/**
* Runs one before all closure, and unsets it from the repository.
*/
public function pop(string $filename): Closure
{
$closure = $this->get($filename);
@@ -31,9 +28,6 @@ final class BeforeAllRepository
return $closure;
}
/**
* Sets a before all closure.
*/
public function set(Closure $closure): void
{
$filename = Reflection::getFileNameFromClosure($closure);
@@ -45,9 +39,6 @@ final class BeforeAllRepository
$this->state[$filename] = $closure;
}
/**
* Gets a before all closure by the given filename.
*/
public function get(string $filename): Closure
{
return $this->state[$filename] ?? NullClosure::create();
@@ -19,9 +19,6 @@ final class BeforeEachRepository
*/
private array $state = [];
/**
* Sets a before each closure.
*/
public function set(string $filename, BeforeEachCall $beforeEachCall, Closure $beforeEachTestCall, Closure $beforeEachTestCase): void
{
if (array_key_exists($filename, $this->state)) {
@@ -36,8 +33,6 @@ final class BeforeEachRepository
}
/**
* Gets a before each closure by the given filename.
*
* @return array{0: Closure, 1: Closure}
*/
public function get(string $filename): array
-10
View File
@@ -22,22 +22,16 @@ final class DatasetsRepository
private const string SEPARATOR = '>>';
/**
* Holds the datasets.
*
* @var array<string, Closure|iterable<int|string, mixed>>
*/
private static array $datasets = [];
/**
* Holds the withs.
*
* @var array<array<string, Closure|iterable<int|string, mixed>|string>>
*/
private static array $withs = [];
/**
* Sets the given.
*
* @param Closure|iterable<int|string, mixed> $data
*/
public static function set(string $name, Closure|iterable $data, string $scope): void
@@ -52,8 +46,6 @@ final class DatasetsRepository
}
/**
* Sets the given "with".
*
* @param array<Closure|iterable<int|string, mixed>|string> $with
*/
public static function with(string $filename, string $description, array $with): void
@@ -85,8 +77,6 @@ final class DatasetsRepository
}
/**
* Resolves the current dataset to an array value.
*
* @param array<Closure|iterable<int|string, mixed>|string> $dataset
* @return array<string, mixed>|null
*/
-22
View File
@@ -15,26 +15,18 @@ final class SnapshotRepository
/** @var array<string, int> */
private static array $expectationsCounter = [];
/**
* Creates a snapshot repository instance.
*/
public function __construct(
private readonly string $rootPath,
private readonly string $testsPath,
private readonly string $snapshotsPath,
) {}
/**
* Checks if the snapshot exists.
*/
public function has(): bool
{
return file_exists($this->getSnapshotFilename());
}
/**
* Gets the snapshot.
*
* @return array{0: string, 1: string}
*
* @throws ShouldNotHappen
@@ -52,9 +44,6 @@ final class SnapshotRepository
return [$snapshot, $contents];
}
/**
* Saves the given snapshot for the given test case.
*/
public function save(string $snapshot): string
{
$snapshotFilename = $this->getSnapshotFilename();
@@ -70,9 +59,6 @@ final class SnapshotRepository
return str_replace(dirname($this->testsPath).'/', '', $snapshotFilename);
}
/**
* Flushes the snapshots.
*/
public function flush(): void
{
$absoluteSnapshotsPath = $this->testsPath.'/'.$this->snapshotsPath;
@@ -101,26 +87,18 @@ final class SnapshotRepository
}
}
/**
* Gets the snapshot's "filename".
*/
private function getSnapshotFilename(): string
{
$testFile = TestSuite::getInstance()->getFilename();
if (str_starts_with($testFile, $this->testsPath)) {
// if the test file is in the tests directory
$startPath = $this->testsPath;
} else {
// if the test file is in the app, src, etc. directory
$startPath = $this->rootPath;
}
// relative path: we use substr() and not str_replace() to remove the start path
// for instance, if the $startPath is /app/ and the $testFile is /app/app/tests/Unit/ExampleTest.php, we should only remove the first /app/ from the path
$relativePath = substr($testFile, strlen($startPath));
// remove extension from filename
$relativePath = substr($relativePath, 0, (int) strrpos($relativePath, '.'));
$description = TestSuite::getInstance()->getDescription();
-27
View File
@@ -41,17 +41,12 @@ final class TestRepository
*/
private array $testCaseMethodFilters = [];
/**
* Counts the number of test cases.
*/
public function count(): int
{
return count($this->testCases);
}
/**
* Returns the filename of each test that should be executed in the suite.
*
* @return array<int, string>
*/
public function getFilenames(): array
@@ -60,8 +55,6 @@ final class TestRepository
}
/**
* Uses the given `$testCaseClass` on the given `$paths`.
*
* @param array<int, string> $classOrTraits
* @param array<int, string> $groups
* @param array<int, string> $paths
@@ -97,25 +90,17 @@ final class TestRepository
}
}
/**
* Filters the test cases using the given filter.
*/
public function addTestCaseFilter(TestCaseFilter $filter): void
{
$this->testCaseFilters[] = $filter;
}
/**
* Filters the test cases using the given filter.
*/
public function addTestCaseMethodFilter(TestCaseMethodFilter $filter): void
{
$this->testCaseMethodFilters[] = $filter;
}
/**
* Gets the class and traits configured for the given directory path.
*
* @return array<int, string>
*/
public function getUsesForPath(string $path): array
@@ -123,17 +108,11 @@ final class TestRepository
return $this->uses[$path][0] ?? [];
}
/**
* Gets the test case factory from the given filename.
*/
public function get(string $filename): ?TestCaseFactory
{
return $this->testCases[$filename] ?? null;
}
/**
* Sets a new test case method.
*/
public function set(TestCaseMethodFactory $method): void
{
foreach ($this->testCaseFilters as $filter) {
@@ -155,9 +134,6 @@ final class TestRepository
$this->testCases[$method->filename]->addMethod($method);
}
/**
* Makes a Test Case from the given filename, if exists.
*/
public function makeIfNeeded(string $filename): void
{
if (! array_key_exists($filename, $this->testCases)) {
@@ -173,9 +149,6 @@ final class TestRepository
$this->make($this->testCases[$filename]);
}
/**
* Makes a Test Case using the given factory.
*/
private function make(TestCaseFactory $testCase): void
{
$startsWith = static fn (string $target, string $directory): bool => Str::startsWith($target, $directory.DIRECTORY_SEPARATOR);