mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 09:17:23 +01:00
Merge branch 'master' into datasets-scope
# Conflicts: # tests/.snapshots/success.txt
This commit is contained in:
@ -22,7 +22,12 @@ trait Testable
|
||||
/**
|
||||
* Test method description.
|
||||
*/
|
||||
private static string $__description;
|
||||
private string $__description;
|
||||
|
||||
/**
|
||||
* Test "latest" method description.
|
||||
*/
|
||||
private static string $__latestDescription;
|
||||
|
||||
/**
|
||||
* The Test Case "test" closure.
|
||||
@ -69,7 +74,7 @@ trait Testable
|
||||
|
||||
if ($test->hasMethod($name)) {
|
||||
$method = $test->getMethod($name);
|
||||
self::$__description = $method->description;
|
||||
$this->__description = self::$__latestDescription = $method->description;
|
||||
$this->__test = $method->getClosure($this);
|
||||
}
|
||||
}
|
||||
@ -169,7 +174,7 @@ trait Testable
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::$__description = $this->name();
|
||||
$this->__description = self::$__latestDescription = $this->name();
|
||||
|
||||
TestSuite::getInstance()->test = $this;
|
||||
|
||||
@ -221,7 +226,7 @@ trait Testable
|
||||
{
|
||||
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
||||
|
||||
self::$__description = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description;
|
||||
$this->__description = self::$__latestDescription = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description;
|
||||
|
||||
if (count($arguments) !== 1) {
|
||||
return $arguments;
|
||||
@ -258,7 +263,7 @@ trait Testable
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Test Case name that should be used by printers.
|
||||
* The printable test case name.
|
||||
*/
|
||||
public static function getPrintableTestCaseName(): string
|
||||
{
|
||||
@ -266,10 +271,18 @@ trait Testable
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Test Case name that should be used by printers.
|
||||
* The printable test case method name.
|
||||
*/
|
||||
public static function getPrintableTestCaseMethodName(): string
|
||||
public function getPrintableTestCaseMethodName(): string
|
||||
{
|
||||
return self::$__description;
|
||||
return $this->__description;
|
||||
}
|
||||
|
||||
/**
|
||||
* The latest printable test case method name.
|
||||
*/
|
||||
public static function getLatestPrintableTestCaseMethodName(): string
|
||||
{
|
||||
return self::$__latestDescription;
|
||||
}
|
||||
}
|
||||
|
||||
24
src/Exceptions/TestDescriptionMissing.php
Normal file
24
src/Exceptions/TestDescriptionMissing.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use NunoMaduro\Collision\Contracts\RenderlessEditor;
|
||||
use NunoMaduro\Collision\Contracts\RenderlessTrace;
|
||||
use Symfony\Component\Console\Exception\ExceptionInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TestDescriptionMissing extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
|
||||
{
|
||||
/**
|
||||
* Creates a new Exception instance.
|
||||
*/
|
||||
public function __construct(string $fileName)
|
||||
{
|
||||
parent::__construct(sprintf('Test misses description in the filename `%s`.', $fileName));
|
||||
}
|
||||
}
|
||||
@ -161,7 +161,6 @@ final class HigherOrderExpectation
|
||||
*/
|
||||
private function getValue(): mixed
|
||||
{
|
||||
// @phpstan-ignore-next-line
|
||||
return $this->shouldReset ? $this->original->value : $this->expectation->value;
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ use Pest\Contracts\HasPrintableTestCaseName;
|
||||
use Pest\Exceptions\DatasetMissing;
|
||||
use Pest\Exceptions\ShouldNotHappen;
|
||||
use Pest\Exceptions\TestAlreadyExist;
|
||||
use Pest\Exceptions\TestDescriptionMissing;
|
||||
use Pest\Factories\Concerns\HigherOrderable;
|
||||
use Pest\Plugins\Environment;
|
||||
use Pest\Support\Reflection;
|
||||
@ -122,6 +123,8 @@ final class TestCaseFactory
|
||||
$rootPath = TestSuite::getInstance()->rootPath;
|
||||
$relativePath = str_replace($rootPath.DIRECTORY_SEPARATOR, '', $filename);
|
||||
|
||||
$relativePath = ltrim($relativePath, DIRECTORY_SEPARATOR);
|
||||
|
||||
$basename = basename($relativePath, '.php');
|
||||
|
||||
$dotPos = strpos($basename, '.');
|
||||
@ -208,7 +211,11 @@ final class TestCaseFactory
|
||||
|
||||
eval($classCode);
|
||||
} catch (ParseError $caught) {
|
||||
throw new RuntimeException(sprintf('Unable to create test case for test file at %s', $filename), 1, $caught);
|
||||
throw new RuntimeException(sprintf(
|
||||
"Unable to create test case for test file at %s. \n %s",
|
||||
$filename,
|
||||
$classCode
|
||||
), 1, $caught);
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +225,7 @@ final class TestCaseFactory
|
||||
public function addMethod(TestCaseMethodFactory $method): void
|
||||
{
|
||||
if ($method->description === null) {
|
||||
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
||||
throw new TestDescriptionMissing($method->filename);
|
||||
}
|
||||
|
||||
if (array_key_exists($method->description, $this->methods)) {
|
||||
|
||||
@ -524,7 +524,6 @@ final class Expectation
|
||||
{
|
||||
Assert::assertIsString($this->value, $message);
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
Assert::assertJson($this->value, $message);
|
||||
|
||||
return $this;
|
||||
|
||||
@ -156,7 +156,7 @@ final class DatasetsRepository
|
||||
}
|
||||
|
||||
if ($datasets[$index] instanceof Traversable) {
|
||||
$datasets[$index] = iterator_to_array($datasets[$index]);
|
||||
$datasets[$index] = iterator_to_array($datasets[$index], false);
|
||||
}
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
|
||||
@ -84,6 +84,9 @@ final class TestRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the test case factory from the given filename.
|
||||
*/
|
||||
public function get(string $filename): TestCaseFactory
|
||||
{
|
||||
return $this->testCases[$filename];
|
||||
|
||||
@ -28,7 +28,9 @@ final class Backtrace
|
||||
foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) {
|
||||
assert(array_key_exists(self::FILE, $trace));
|
||||
|
||||
if (Str::endsWith($trace[self::FILE], 'overrides/Runner/TestSuiteLoader.php')) {
|
||||
$traceFile = str_replace(DIRECTORY_SEPARATOR, '/', $trace[self::FILE]);
|
||||
|
||||
if (Str::endsWith($traceFile, 'overrides/Runner/TestSuiteLoader.php')) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ final class Coverage
|
||||
|
||||
$totalWidth = (new Terminal())->getWidth();
|
||||
|
||||
$dottedLineLength = $totalWidth <= 70 ? $totalWidth : 70;
|
||||
$dottedLineLength = $totalWidth - 6;
|
||||
|
||||
$totalCoverage = $codeCoverage->getReport()->percentageOfExecutedLines();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user