mirror of
https://github.com/pestphp/pest.git
synced 2026-09-06 06:43:35 +02:00
chore: coding style changes
This commit is contained in:
@@ -25,28 +25,16 @@ use PHPUnit\TestRunner\TestResult\TestResult as PhpUnitTestResult;
|
||||
*/
|
||||
final readonly class Converter
|
||||
{
|
||||
/**
|
||||
* The prefix for the test suite name.
|
||||
*/
|
||||
private const string PREFIX = 'P\\';
|
||||
|
||||
/**
|
||||
* The state generator.
|
||||
*/
|
||||
private StateGenerator $stateGenerator;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the Converter.
|
||||
*/
|
||||
public function __construct(
|
||||
private string $rootPath,
|
||||
) {
|
||||
$this->stateGenerator = new StateGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the test case method name.
|
||||
*/
|
||||
public function getTestCaseMethodName(Test $test): string
|
||||
{
|
||||
if (! $test instanceof TestMethod) {
|
||||
@@ -56,9 +44,6 @@ final readonly class Converter
|
||||
return $test->testDox()->prettifiedMethodName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the test case location.
|
||||
*/
|
||||
public function getTestCaseLocation(Test $test): string
|
||||
{
|
||||
if (! $test instanceof TestMethod) {
|
||||
@@ -68,15 +53,11 @@ final readonly class Converter
|
||||
$path = $test->testDox()->prettifiedClassName();
|
||||
$relativePath = $this->toRelativePath($path);
|
||||
|
||||
// TODO: Get the description without the dataset.
|
||||
$description = $test->testDox()->prettifiedMethodName();
|
||||
|
||||
return "$relativePath::$description";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the exception message.
|
||||
*/
|
||||
public function getExceptionMessage(Throwable $throwable): string
|
||||
{
|
||||
if (is_a($throwable->className(), FrameworkException::class, true)) {
|
||||
@@ -93,9 +74,6 @@ final readonly class Converter
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the exception details.
|
||||
*/
|
||||
public function getExceptionDetails(Throwable $throwable): string
|
||||
{
|
||||
$buffer = $this->getStackTrace($throwable);
|
||||
@@ -113,26 +91,19 @@ final readonly class Converter
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stack trace.
|
||||
*/
|
||||
public function getStackTrace(Throwable $throwable): string
|
||||
{
|
||||
$stackTrace = $throwable->stackTrace();
|
||||
|
||||
// Split stacktrace per frame.
|
||||
$frames = explode("\n", $stackTrace);
|
||||
|
||||
// Remove empty lines
|
||||
$frames = array_filter($frames);
|
||||
|
||||
// clean the paths of each frame.
|
||||
$frames = array_map(
|
||||
$this->toRelativePath(...),
|
||||
$frames
|
||||
);
|
||||
|
||||
// Format stacktrace as `at <path>`
|
||||
$frames = array_map(
|
||||
fn (string $frame): string => "at $frame",
|
||||
$frames
|
||||
@@ -141,9 +112,6 @@ final readonly class Converter
|
||||
return implode("\n", $frames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the test suite name.
|
||||
*/
|
||||
public function getTestSuiteName(TestSuite $testSuite): string
|
||||
{
|
||||
if ($testSuite instanceof TestSuiteForTestMethodWithDataProvider) {
|
||||
@@ -162,17 +130,11 @@ final readonly class Converter
|
||||
return Str::after($name, self::PREFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the trimmed test class name.
|
||||
*/
|
||||
public function getTrimmedTestClassName(TestMethod $test): string
|
||||
{
|
||||
return Str::after($test->className(), self::PREFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the test suite location.
|
||||
*/
|
||||
public function getTestSuiteLocation(TestSuite $testSuite): ?string
|
||||
{
|
||||
$firstTest = $this->getFirstTest($testSuite);
|
||||
@@ -191,22 +153,15 @@ final readonly class Converter
|
||||
return $classRelativePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the prettified test method name without dataset-related suffix.
|
||||
*/
|
||||
private function getTestMethodNameWithoutDatasetSuffix(TestMethod $testMethod): string
|
||||
{
|
||||
return Str::beforeLast($testMethod->testDox()->prettifiedMethodName(), ' with data set ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first test from the test suite.
|
||||
*/
|
||||
private function getFirstTest(TestSuite $testSuite): ?TestMethod
|
||||
{
|
||||
$tests = $testSuite->tests()->asArray();
|
||||
|
||||
// TODO: figure out how to get the file path without a test being there.
|
||||
if ($tests === []) {
|
||||
return null;
|
||||
}
|
||||
@@ -219,26 +174,16 @@ final readonly class Converter
|
||||
return $firstTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the test suite size.
|
||||
*/
|
||||
public function getTestSuiteSize(TestSuite $testSuite): int
|
||||
{
|
||||
return $testSuite->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the given path in relative path.
|
||||
*/
|
||||
private function toRelativePath(string $path): string
|
||||
{
|
||||
// Remove cwd from the path.
|
||||
return str_replace("$this->rootPath".DIRECTORY_SEPARATOR, '', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the test result.
|
||||
*/
|
||||
public function getStateFromResult(PhpUnitTestResult $result): State
|
||||
{
|
||||
$events = [
|
||||
@@ -253,11 +198,9 @@ final readonly class Converter
|
||||
|
||||
foreach ($events as $event) {
|
||||
if ($event instanceof AfterLastTestMethodErrored) {
|
||||
// PHPUnit's collector does not count these towards `numberOfTestsRun`...
|
||||
continue;
|
||||
}
|
||||
if ($event instanceof AfterLastTestMethodFailed) {
|
||||
// PHPUnit's collector does not count these towards `numberOfTestsRun`...
|
||||
continue;
|
||||
}
|
||||
if ($event instanceof BeforeFirstTestMethodErrored || $event instanceof BeforeFirstTestMethodFailed) {
|
||||
|
||||
Reference in New Issue
Block a user