mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
chore: style changes
This commit is contained in:
4
bin/pest
4
bin/pest
@ -44,10 +44,10 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Used when Pest is required using composer.
|
// Used when Pest is required using composer.
|
||||||
$vendorPath = dirname(__DIR__, 4) . '/vendor/autoload.php';
|
$vendorPath = dirname(__DIR__, 4).'/vendor/autoload.php';
|
||||||
|
|
||||||
// Used when Pest maintainers are running Pest tests.
|
// Used when Pest maintainers are running Pest tests.
|
||||||
$localPath = dirname(__DIR__) . '/vendor/autoload.php';
|
$localPath = dirname(__DIR__).'/vendor/autoload.php';
|
||||||
|
|
||||||
if (file_exists($vendorPath)) {
|
if (file_exists($vendorPath)) {
|
||||||
include_once $vendorPath;
|
include_once $vendorPath;
|
||||||
|
|||||||
@ -29,6 +29,9 @@ final class BootSubscribers implements Bootstrapper
|
|||||||
Subscribers\EnsureTeamCityEnabled::class,
|
Subscribers\EnsureTeamCityEnabled::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Subscriber instance.
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Container $container,
|
private readonly Container $container,
|
||||||
) {
|
) {
|
||||||
@ -40,8 +43,10 @@ final class BootSubscribers implements Bootstrapper
|
|||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
foreach (self::SUBSCRIBERS as $subscriber) {
|
foreach (self::SUBSCRIBERS as $subscriber) {
|
||||||
/** @var Subscriber $instance */
|
|
||||||
$instance = $this->container->get($subscriber);
|
$instance = $this->container->get($subscriber);
|
||||||
|
|
||||||
|
assert($instance instanceof Subscriber);
|
||||||
|
|
||||||
Event\Facade::registerSubscriber(
|
Event\Facade::registerSubscriber(
|
||||||
$instance
|
$instance
|
||||||
);
|
);
|
||||||
|
|||||||
@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Pest\Factories\Annotations;
|
namespace Pest\Contracts;
|
||||||
|
|
||||||
use Pest\Factories\TestCaseMethodFactory;
|
use Pest\Factories\TestCaseMethodFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interal
|
* @interal
|
||||||
*/
|
*/
|
||||||
interface AddsAnnotation
|
interface AddsAnnotations
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Adds annotations to method
|
* Adds annotations to the given test case method.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $annotations
|
* @param array<int, string> $annotations
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
@ -4,19 +4,17 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Factories\Annotations;
|
namespace Pest\Factories\Annotations;
|
||||||
|
|
||||||
|
use Pest\Contracts\AddsAnnotations;
|
||||||
use Pest\Factories\Covers\CoversNothing as CoversNothingFactory;
|
use Pest\Factories\Covers\CoversNothing as CoversNothingFactory;
|
||||||
use Pest\Factories\TestCaseMethodFactory;
|
use Pest\Factories\TestCaseMethodFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class CoversNothing implements AddsAnnotation
|
final class CoversNothing implements AddsAnnotations
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Adds annotations regarding the "depends" feature.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param array<int, string> $annotations
|
|
||||||
* @return array<int, string>
|
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,19 +4,17 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Factories\Annotations;
|
namespace Pest\Factories\Annotations;
|
||||||
|
|
||||||
|
use Pest\Contracts\AddsAnnotations;
|
||||||
use Pest\Factories\TestCaseMethodFactory;
|
use Pest\Factories\TestCaseMethodFactory;
|
||||||
use Pest\Support\Str;
|
use Pest\Support\Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class Depends implements AddsAnnotation
|
final class Depends implements AddsAnnotations
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Adds annotations regarding the "depends" feature.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param array<int, string> $annotations
|
|
||||||
* @return array<int, string>
|
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,18 +4,16 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Factories\Annotations;
|
namespace Pest\Factories\Annotations;
|
||||||
|
|
||||||
|
use Pest\Contracts\AddsAnnotations;
|
||||||
use Pest\Factories\TestCaseMethodFactory;
|
use Pest\Factories\TestCaseMethodFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class Groups implements AddsAnnotation
|
final class Groups implements AddsAnnotations
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Adds annotations regarding the "groups" feature.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param array<int, string> $annotations
|
|
||||||
* @return array<int, string>
|
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,19 +4,16 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Factories\Annotations;
|
namespace Pest\Factories\Annotations;
|
||||||
|
|
||||||
|
use Pest\Contracts\AddsAnnotations;
|
||||||
use Pest\Factories\TestCaseMethodFactory;
|
use Pest\Factories\TestCaseMethodFactory;
|
||||||
|
|
||||||
final class TestDox implements AddsAnnotation
|
final class TestDox implements AddsAnnotations
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Add metadata via test dox for TeamCity
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param array<int, string> $annotations
|
|
||||||
* @return array<int, string>
|
|
||||||
*/
|
*/
|
||||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||||
{
|
{
|
||||||
// First test dox on class overrides the method name.
|
|
||||||
$annotations[] = "@testdox $method->description";
|
$annotations[] = "@testdox $method->description";
|
||||||
|
|
||||||
return $annotations;
|
return $annotations;
|
||||||
|
|||||||
@ -6,12 +6,12 @@ namespace Pest\Factories;
|
|||||||
|
|
||||||
use ParseError;
|
use ParseError;
|
||||||
use Pest\Concerns;
|
use Pest\Concerns;
|
||||||
|
use Pest\Contracts\AddsAnnotations;
|
||||||
use Pest\Contracts\HasPrintableTestCaseName;
|
use Pest\Contracts\HasPrintableTestCaseName;
|
||||||
use Pest\Exceptions\DatasetMissing;
|
use Pest\Exceptions\DatasetMissing;
|
||||||
use Pest\Exceptions\ShouldNotHappen;
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use Pest\Exceptions\TestAlreadyExist;
|
use Pest\Exceptions\TestAlreadyExist;
|
||||||
use Pest\Exceptions\TestDescriptionMissing;
|
use Pest\Exceptions\TestDescriptionMissing;
|
||||||
use Pest\Factories\Annotations\AddsAnnotation;
|
|
||||||
use Pest\Factories\Concerns\HigherOrderable;
|
use Pest\Factories\Concerns\HigherOrderable;
|
||||||
use Pest\Plugins\Environment;
|
use Pest\Plugins\Environment;
|
||||||
use Pest\Support\Reflection;
|
use Pest\Support\Reflection;
|
||||||
@ -30,7 +30,7 @@ final class TestCaseFactory
|
|||||||
/**
|
/**
|
||||||
* The list of annotations.
|
* The list of annotations.
|
||||||
*
|
*
|
||||||
* @var array<int, class-string<AddsAnnotation>>
|
* @var array<int, class-string<AddsAnnotations>>
|
||||||
*/
|
*/
|
||||||
private const ANNOTATIONS = [
|
private const ANNOTATIONS = [
|
||||||
Annotations\Depends::class,
|
Annotations\Depends::class,
|
||||||
|
|||||||
@ -5,8 +5,8 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Factories;
|
namespace Pest\Factories;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Pest\Contracts\AddsAnnotations;
|
||||||
use Pest\Exceptions\ShouldNotHappen;
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use Pest\Factories\Annotations\AddsAnnotation;
|
|
||||||
use Pest\Factories\Concerns\HigherOrderable;
|
use Pest\Factories\Concerns\HigherOrderable;
|
||||||
use Pest\Plugins\Retry;
|
use Pest\Plugins\Retry;
|
||||||
use Pest\Repositories\DatasetsRepository;
|
use Pest\Repositories\DatasetsRepository;
|
||||||
@ -113,7 +113,7 @@ final class TestCaseMethodFactory
|
|||||||
/**
|
/**
|
||||||
* Creates a PHPUnit method as a string ready for evaluation.
|
* Creates a PHPUnit method as a string ready for evaluation.
|
||||||
*
|
*
|
||||||
* @param array<int, class-string<AddsAnnotation>> $annotationsToUse
|
* @param array<int, class-string<AddsAnnotations>> $annotationsToUse
|
||||||
* @param array<int, class-string<\Pest\Factories\Attributes\Attribute>> $attributesToUse
|
* @param array<int, class-string<\Pest\Factories\Attributes\Attribute>> $attributesToUse
|
||||||
*/
|
*/
|
||||||
public function buildForEvaluation(string $classFQN, array $annotationsToUse, array $attributesToUse): string
|
public function buildForEvaluation(string $classFQN, array $annotationsToUse, array $attributesToUse): string
|
||||||
|
|||||||
@ -26,16 +26,19 @@ use PHPUnit\TestRunner\TestResult\TestResult as PhpUnitTestResult;
|
|||||||
*/
|
*/
|
||||||
final class Converter
|
final class Converter
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private const PREFIX = 'P\\';
|
private const PREFIX = 'P\\';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of the Converter.
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly string $rootPath,
|
private readonly string $rootPath,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the test case method name.
|
||||||
|
*/
|
||||||
public function getTestCaseMethodName(Test $test): string
|
public function getTestCaseMethodName(Test $test): string
|
||||||
{
|
{
|
||||||
if (! $test instanceof TestMethod) {
|
if (! $test instanceof TestMethod) {
|
||||||
@ -45,21 +48,27 @@ final class Converter
|
|||||||
return $test->testDox()->prettifiedMethodName();
|
return $test->testDox()->prettifiedMethodName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the test case location.
|
||||||
|
*/
|
||||||
public function getTestCaseLocation(Test $test): string
|
public function getTestCaseLocation(Test $test): string
|
||||||
{
|
{
|
||||||
if (! $test instanceof TestMethod) {
|
if (! $test instanceof TestMethod) {
|
||||||
throw ShouldNotHappen::fromMessage('Not an instance of TestMethod');
|
throw ShouldNotHappen::fromMessage('Not an instance of TestMethod');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fileName = $test->testDox()->prettifiedClassName();
|
$path = $test->testDox()->prettifiedClassName();
|
||||||
$fileName = $this->cleanPath($fileName);
|
$relativePath = $this->toRelativePath($path);
|
||||||
|
|
||||||
// TODO: Get the description without the dataset.
|
// TODO: Get the description without the dataset.
|
||||||
$description = $test->testDox()->prettifiedMethodName();
|
$description = $test->testDox()->prettifiedMethodName();
|
||||||
|
|
||||||
return "$fileName::$description";
|
return "$relativePath::$description";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the exception messsage.
|
||||||
|
*/
|
||||||
public function getExceptionMessage(Throwable $throwable): string
|
public function getExceptionMessage(Throwable $throwable): string
|
||||||
{
|
{
|
||||||
if (is_a($throwable->className(), FrameworkException::class, true)) {
|
if (is_a($throwable->className(), FrameworkException::class, true)) {
|
||||||
@ -76,6 +85,9 @@ final class Converter
|
|||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the exception details.
|
||||||
|
*/
|
||||||
public function getExceptionDetails(Throwable $throwable): string
|
public function getExceptionDetails(Throwable $throwable): string
|
||||||
{
|
{
|
||||||
$buffer = $this->getStackTrace($throwable);
|
$buffer = $this->getStackTrace($throwable);
|
||||||
@ -93,6 +105,9 @@ final class Converter
|
|||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the stack trace.
|
||||||
|
*/
|
||||||
public function getStackTrace(Throwable $throwable): string
|
public function getStackTrace(Throwable $throwable): string
|
||||||
{
|
{
|
||||||
$stackTrace = $throwable->stackTrace();
|
$stackTrace = $throwable->stackTrace();
|
||||||
@ -105,7 +120,7 @@ final class Converter
|
|||||||
|
|
||||||
// clean the paths of each frame.
|
// clean the paths of each frame.
|
||||||
$frames = array_map(
|
$frames = array_map(
|
||||||
fn (string $frame): string => $this->cleanPath($frame),
|
fn (string $frame): string => $this->toRelativePath($frame),
|
||||||
$frames
|
$frames
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -118,6 +133,9 @@ final class Converter
|
|||||||
return implode("\n", $frames);
|
return implode("\n", $frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the test suite name.
|
||||||
|
*/
|
||||||
public function getTestSuiteName(TestSuite $testSuite): string
|
public function getTestSuiteName(TestSuite $testSuite): string
|
||||||
{
|
{
|
||||||
$name = $testSuite->name();
|
$name = $testSuite->name();
|
||||||
@ -129,6 +147,9 @@ final class Converter
|
|||||||
return Str::after($name, self::PREFIX);
|
return Str::after($name, self::PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the test suite location.
|
||||||
|
*/
|
||||||
public function getTestSuiteLocation(TestSuite $testSuite): string|null
|
public function getTestSuiteLocation(TestSuite $testSuite): string|null
|
||||||
{
|
{
|
||||||
$tests = $testSuite->tests()->asArray();
|
$tests = $testSuite->tests()->asArray();
|
||||||
@ -145,15 +166,21 @@ final class Converter
|
|||||||
|
|
||||||
$path = $firstTest->testDox()->prettifiedClassName();
|
$path = $firstTest->testDox()->prettifiedClassName();
|
||||||
|
|
||||||
return $this->cleanPath($path);
|
return $this->toRelativePath($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function cleanPath(string $path): string
|
/**
|
||||||
|
* Transforms the given path in relative path.
|
||||||
|
*/
|
||||||
|
private function toRelativePath(string $path): string
|
||||||
{
|
{
|
||||||
// Remove cwd from the path.
|
// Remove cwd from the path.
|
||||||
return str_replace("$this->rootPath/", '', $path);
|
return str_replace("$this->rootPath/", '', $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the test result.
|
||||||
|
*/
|
||||||
public function getStateFromResult(PhpUnitTestResult $result): State
|
public function getStateFromResult(PhpUnitTestResult $result): State
|
||||||
{
|
{
|
||||||
$state = new State();
|
$state = new State();
|
||||||
|
|||||||
@ -4,6 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Logging\TeamCity;
|
namespace Pest\Logging\TeamCity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
final class ServiceMessage
|
final class ServiceMessage
|
||||||
{
|
{
|
||||||
private static int|null $flowId = null;
|
private static int|null $flowId = null;
|
||||||
|
|||||||
@ -11,10 +11,16 @@ use Pest\Logging\TeamCity\TeamCityLogger;
|
|||||||
*/
|
*/
|
||||||
abstract class Subscriber
|
abstract class Subscriber
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new Subscriber instance.
|
||||||
|
*/
|
||||||
public function __construct(private readonly TeamCityLogger $logger)
|
public function __construct(private readonly TeamCityLogger $logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new TeamCityLogger instance.
|
||||||
|
*/
|
||||||
final protected function logger(): TeamCityLogger
|
final protected function logger(): TeamCityLogger
|
||||||
{
|
{
|
||||||
return $this->logger;
|
return $this->logger;
|
||||||
|
|||||||
@ -17,6 +17,9 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
*/
|
*/
|
||||||
final class EnsureTeamCityEnabled implements ConfiguredSubscriber
|
final class EnsureTeamCityEnabled implements ConfiguredSubscriber
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new Configured Subscriber instance.
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly OutputInterface $output,
|
private readonly OutputInterface $output,
|
||||||
private readonly InputInterface $input,
|
private readonly InputInterface $input,
|
||||||
|
|||||||
@ -77,6 +77,9 @@ final class Str
|
|||||||
return substr($subject, 0, $pos);
|
return substr($subject, 0, $pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content after the given "search".
|
||||||
|
*/
|
||||||
public static function after(string $subject, string $search): string
|
public static function after(string $subject, string $search): string
|
||||||
{
|
{
|
||||||
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
|
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user