mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
Migrates to Pint
This commit is contained in:
@ -15,8 +15,7 @@ final class CoversNothing
|
||||
/**
|
||||
* Adds annotations regarding the "depends" feature.
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||
|
||||
@ -15,8 +15,7 @@ final class Depends
|
||||
/**
|
||||
* Adds annotations regarding the "depends" feature.
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||
|
||||
@ -14,8 +14,7 @@ final class Groups
|
||||
/**
|
||||
* Adds annotations regarding the "groups" feature.
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
*
|
||||
* @param array<int, string> $annotations
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||
|
||||
@ -19,8 +19,7 @@ abstract class Attribute
|
||||
public const ABOVE_CLASS = false;
|
||||
|
||||
/**
|
||||
* @param array<int, string> $attributes
|
||||
*
|
||||
* @param array<int, string> $attributes
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $attributes): array // @phpstan-ignore-line
|
||||
|
||||
@ -23,8 +23,7 @@ final class Covers extends Attribute
|
||||
/**
|
||||
* Adds attributes regarding the "covers" feature.
|
||||
*
|
||||
* @param array<int, string> $attributes
|
||||
*
|
||||
* @param array<int, string> $attributes
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function __invoke(TestCaseMethodFactory $method, array $attributes): array
|
||||
@ -33,7 +32,7 @@ final class Covers extends Attribute
|
||||
if ($covering instanceof CoversClass) {
|
||||
// Prepend a backslash for FQN classes
|
||||
if (str_contains($covering->class, '\\')) {
|
||||
$covering->class = '\\' . $covering->class;
|
||||
$covering->class = '\\'.$covering->class;
|
||||
}
|
||||
|
||||
$attributes[] = "#[\PHPUnit\Framework\Attributes\CoversClass({$covering->class}::class)]";
|
||||
|
||||
@ -28,8 +28,8 @@ trait HigherOrderable
|
||||
*/
|
||||
private function bootHigherOrderable(): void
|
||||
{
|
||||
$this->chains = new HigherOrderMessageCollection();
|
||||
$this->chains = new HigherOrderMessageCollection();
|
||||
$this->factoryProxies = new HigherOrderMessageCollection();
|
||||
$this->proxies = new HigherOrderMessageCollection();
|
||||
$this->proxies = new HigherOrderMessageCollection();
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ final class TestCaseFactory
|
||||
/**
|
||||
* Creates a Test Case class using a runtime evaluate.
|
||||
*
|
||||
* @param array<int, TestCaseMethodFactory> $methods
|
||||
* @param array<int, TestCaseMethodFactory> $methods
|
||||
*/
|
||||
public function evaluate(string $filename, array $methods): void
|
||||
{
|
||||
@ -118,9 +118,9 @@ final class TestCaseFactory
|
||||
$filename = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', static fn ($match): string => strtolower($match['drive']), $filename);
|
||||
}
|
||||
|
||||
$filename = str_replace('\\\\', '\\', addslashes((string) realpath($filename)));
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename);
|
||||
$filename = str_replace('\\\\', '\\', addslashes((string) realpath($filename)));
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$relativePath = str_replace($rootPath.DIRECTORY_SEPARATOR, '', $filename);
|
||||
|
||||
$basename = basename($relativePath, '.php');
|
||||
|
||||
@ -130,7 +130,7 @@ final class TestCaseFactory
|
||||
$basename = substr($basename, 0, $dotPos);
|
||||
}
|
||||
|
||||
$relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . $basename;
|
||||
$relativePath = dirname(ucfirst($relativePath)).DIRECTORY_SEPARATOR.$basename;
|
||||
|
||||
$relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
|
||||
|
||||
@ -141,29 +141,29 @@ final class TestCaseFactory
|
||||
// Limit to A-Z, a-z, 0-9, '_', '-'.
|
||||
$relativePath = (string) preg_replace('/[^A-Za-z0-9\\\\]/', '', $relativePath);
|
||||
|
||||
$classFQN = 'P\\' . $relativePath;
|
||||
$classFQN = 'P\\'.$relativePath;
|
||||
|
||||
if (class_exists($classFQN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hasPrintableTestCaseClassFQN = sprintf('\%s', HasPrintableTestCaseName::class);
|
||||
$traitsCode = sprintf('use %s;', implode(', ', array_map(
|
||||
$traitsCode = sprintf('use %s;', implode(', ', array_map(
|
||||
static fn ($trait): string => sprintf('\%s', $trait), $this->traits))
|
||||
);
|
||||
|
||||
$partsFQN = explode('\\', $classFQN);
|
||||
$partsFQN = explode('\\', $classFQN);
|
||||
$className = array_pop($partsFQN);
|
||||
$namespace = implode('\\', $partsFQN);
|
||||
$baseClass = sprintf('\%s', $this->class);
|
||||
|
||||
if ('' === trim($className)) {
|
||||
$className = 'InvalidTestName' . Str::random();
|
||||
$className = 'InvalidTestName'.Str::random();
|
||||
$classFQN .= $className;
|
||||
}
|
||||
|
||||
$classAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => $attribute::ABOVE_CLASS);
|
||||
$methodAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => !$attribute::ABOVE_CLASS);
|
||||
$classAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => $attribute::ABOVE_CLASS);
|
||||
$methodAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => ! $attribute::ABOVE_CLASS);
|
||||
|
||||
$classAttributes = [];
|
||||
|
||||
@ -225,7 +225,7 @@ final class TestCaseFactory
|
||||
throw new TestAlreadyExist($method->filename, $method->description);
|
||||
}
|
||||
|
||||
if (!$method->receivesArguments()) {
|
||||
if (! $method->receivesArguments()) {
|
||||
if ($method->closure === null) {
|
||||
throw ShouldNotHappen::fromMessage('The test closure may not be empty.');
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ final class TestCaseMethodFactory
|
||||
$method = $this;
|
||||
|
||||
return function () use ($testCase, $method, $closure): mixed { // @phpstan-ignore-line
|
||||
/* @var TestCase $this */
|
||||
/* @var TestCase $this */
|
||||
$testCase->proxies->proxy($this);
|
||||
$method->proxies->proxy($this);
|
||||
|
||||
@ -112,8 +112,8 @@ final class TestCaseMethodFactory
|
||||
/**
|
||||
* Creates a PHPUnit method as a string ready for evaluation.
|
||||
*
|
||||
* @param array<int, class-string> $annotationsToUse
|
||||
* @param array<int, class-string<\Pest\Factories\Attributes\Attribute>> $attributesToUse
|
||||
* @param array<int, class-string> $annotationsToUse
|
||||
* @param array<int, class-string<\Pest\Factories\Attributes\Attribute>> $attributesToUse
|
||||
*/
|
||||
public function buildForEvaluation(string $classFQN, array $annotationsToUse, array $attributesToUse): string
|
||||
{
|
||||
@ -123,13 +123,13 @@ final class TestCaseMethodFactory
|
||||
|
||||
$methodName = Str::evaluable($this->description);
|
||||
|
||||
if (Retry::$retrying && !TestSuite::getInstance()->retryTempRepository->exists(sprintf('%s::%s', $classFQN, $methodName))) {
|
||||
if (Retry::$retrying && ! TestSuite::getInstance()->retryTempRepository->exists(sprintf('%s::%s', $classFQN, $methodName))) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$datasetsCode = '';
|
||||
$annotations = ['@test'];
|
||||
$attributes = [];
|
||||
$annotations = ['@test'];
|
||||
$attributes = [];
|
||||
|
||||
foreach ($annotationsToUse as $annotation) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
@ -141,9 +141,9 @@ final class TestCaseMethodFactory
|
||||
}
|
||||
|
||||
if (count($this->datasets) > 0) {
|
||||
$dataProviderName = $methodName . '_dataset';
|
||||
$annotations[] = "@dataProvider $dataProviderName";
|
||||
$datasetsCode = $this->buildDatasetForEvaluation($methodName, $dataProviderName);
|
||||
$dataProviderName = $methodName.'_dataset';
|
||||
$annotations[] = "@dataProvider $dataProviderName";
|
||||
$datasetsCode = $this->buildDatasetForEvaluation($methodName, $dataProviderName);
|
||||
}
|
||||
|
||||
$annotations = implode('', array_map(
|
||||
|
||||
Reference in New Issue
Block a user